diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-12-30 12:23:53 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-12-30 12:23:53 +0100 |
commit | efe923bcdaf15b47593ad8583df09a92c715ac6c (patch) | |
tree | 1944856cd35ff8e1845a31ef776d4cf965b4be34 /server/tests/api/check-params | |
parent | 818f7987eba27c59793e2103168b26129c9404f2 (diff) | |
download | PeerTube-efe923bcdaf15b47593ad8583df09a92c715ac6c.tar.gz PeerTube-efe923bcdaf15b47593ad8583df09a92c715ac6c.tar.zst PeerTube-efe923bcdaf15b47593ad8583df09a92c715ac6c.zip |
Server: split check params tests
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/index.js | 8 | ||||
-rw-r--r-- | server/tests/api/check-params/pods.js | 204 | ||||
-rw-r--r-- | server/tests/api/check-params/remotes.js | 60 | ||||
-rw-r--r-- | server/tests/api/check-params/requests.js | 87 | ||||
-rw-r--r-- | server/tests/api/check-params/users.js | 284 | ||||
-rw-r--r-- | server/tests/api/check-params/videos.js | 456 |
6 files changed, 1099 insertions, 0 deletions
diff --git a/server/tests/api/check-params/index.js b/server/tests/api/check-params/index.js new file mode 100644 index 000000000..3d6f09267 --- /dev/null +++ b/server/tests/api/check-params/index.js | |||
@@ -0,0 +1,8 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | // Order of the tests we want to execute | ||
4 | require('./pods') | ||
5 | require('./remotes') | ||
6 | require('./users') | ||
7 | require('./requests') | ||
8 | require('./videos') | ||
diff --git a/server/tests/api/check-params/pods.js b/server/tests/api/check-params/pods.js new file mode 100644 index 000000000..2f85af644 --- /dev/null +++ b/server/tests/api/check-params/pods.js | |||
@@ -0,0 +1,204 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const request = require('supertest') | ||
4 | const series = require('async/series') | ||
5 | |||
6 | const loginUtils = require('../../utils/login') | ||
7 | const requestsUtils = require('../../utils/requests') | ||
8 | const serversUtils = require('../../utils/servers') | ||
9 | const usersUtils = require('../../utils/users') | ||
10 | |||
11 | describe('Test pods API validators', function () { | ||
12 | const path = '/api/v1/pods/' | ||
13 | let server = null | ||
14 | |||
15 | // --------------------------------------------------------------- | ||
16 | |||
17 | before(function (done) { | ||
18 | this.timeout(20000) | ||
19 | |||
20 | series([ | ||
21 | function (next) { | ||
22 | serversUtils.flushTests(next) | ||
23 | }, | ||
24 | function (next) { | ||
25 | serversUtils.runServer(1, function (server1) { | ||
26 | server = server1 | ||
27 | |||
28 | next() | ||
29 | }) | ||
30 | }, | ||
31 | function (next) { | ||
32 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
33 | if (err) throw err | ||
34 | server.accessToken = token | ||
35 | |||
36 | next() | ||
37 | }) | ||
38 | } | ||
39 | ], done) | ||
40 | }) | ||
41 | |||
42 | describe('When making friends', function () { | ||
43 | let userAccessToken = null | ||
44 | |||
45 | before(function (done) { | ||
46 | usersUtils.createUser(server.url, server.accessToken, 'user1', 'password', function () { | ||
47 | server.user = { | ||
48 | username: 'user1', | ||
49 | password: 'password' | ||
50 | } | ||
51 | |||
52 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
53 | if (err) throw err | ||
54 | |||
55 | userAccessToken = accessToken | ||
56 | |||
57 | done() | ||
58 | }) | ||
59 | }) | ||
60 | }) | ||
61 | |||
62 | describe('When making friends', function () { | ||
63 | const body = { | ||
64 | hosts: [ 'localhost:9002' ] | ||
65 | } | ||
66 | |||
67 | it('Should fail without hosts', function (done) { | ||
68 | request(server.url) | ||
69 | .post(path + '/makefriends') | ||
70 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
71 | .set('Accept', 'application/json') | ||
72 | .expect(400, done) | ||
73 | }) | ||
74 | |||
75 | it('Should fail if hosts is not an array', function (done) { | ||
76 | request(server.url) | ||
77 | .post(path + '/makefriends') | ||
78 | .send({ hosts: 'localhost:9002' }) | ||
79 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
80 | .set('Accept', 'application/json') | ||
81 | .expect(400, done) | ||
82 | }) | ||
83 | |||
84 | it('Should fail if the array is not composed by hosts', function (done) { | ||
85 | request(server.url) | ||
86 | .post(path + '/makefriends') | ||
87 | .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] }) | ||
88 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
89 | .set('Accept', 'application/json') | ||
90 | .expect(400, done) | ||
91 | }) | ||
92 | |||
93 | it('Should fail if the array is composed with http schemes', function (done) { | ||
94 | request(server.url) | ||
95 | .post(path + '/makefriends') | ||
96 | .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] }) | ||
97 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
98 | .set('Accept', 'application/json') | ||
99 | .expect(400, done) | ||
100 | }) | ||
101 | |||
102 | it('Should fail if hosts are not unique', function (done) { | ||
103 | request(server.url) | ||
104 | .post(path + '/makefriends') | ||
105 | .send({ urls: [ 'localhost:9002', 'localhost:9002' ] }) | ||
106 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
107 | .set('Accept', 'application/json') | ||
108 | .expect(400, done) | ||
109 | }) | ||
110 | |||
111 | it('Should fail with a invalid token', function (done) { | ||
112 | request(server.url) | ||
113 | .post(path + '/makefriends') | ||
114 | .send(body) | ||
115 | .set('Authorization', 'Bearer faketoken') | ||
116 | .set('Accept', 'application/json') | ||
117 | .expect(401, done) | ||
118 | }) | ||
119 | |||
120 | it('Should fail if the user is not an administrator', function (done) { | ||
121 | request(server.url) | ||
122 | .post(path + '/makefriends') | ||
123 | .send(body) | ||
124 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
125 | .set('Accept', 'application/json') | ||
126 | .expect(403, done) | ||
127 | }) | ||
128 | }) | ||
129 | |||
130 | describe('When quitting friends', function () { | ||
131 | it('Should fail with a invalid token', function (done) { | ||
132 | request(server.url) | ||
133 | .get(path + '/quitfriends') | ||
134 | .query({ start: 'hello' }) | ||
135 | .set('Authorization', 'Bearer faketoken') | ||
136 | .set('Accept', 'application/json') | ||
137 | .expect(401, done) | ||
138 | }) | ||
139 | |||
140 | it('Should fail if the user is not an administrator', function (done) { | ||
141 | request(server.url) | ||
142 | .get(path + '/quitfriends') | ||
143 | .query({ start: 'hello' }) | ||
144 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
145 | .set('Accept', 'application/json') | ||
146 | .expect(403, done) | ||
147 | }) | ||
148 | }) | ||
149 | }) | ||
150 | |||
151 | describe('When adding a pod', function () { | ||
152 | it('Should fail with nothing', function (done) { | ||
153 | const data = {} | ||
154 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
155 | }) | ||
156 | |||
157 | it('Should fail without public key', function (done) { | ||
158 | const data = { | ||
159 | host: 'coucou.com' | ||
160 | } | ||
161 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
162 | }) | ||
163 | |||
164 | it('Should fail without an host', function (done) { | ||
165 | const data = { | ||
166 | publicKey: 'mysuperpublickey' | ||
167 | } | ||
168 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
169 | }) | ||
170 | |||
171 | it('Should fail with an incorrect host', function (done) { | ||
172 | const data = { | ||
173 | host: 'http://coucou.com', | ||
174 | publicKey: 'mysuperpublickey' | ||
175 | } | ||
176 | requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { | ||
177 | data.host = 'http://coucou' | ||
178 | requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { | ||
179 | data.host = 'coucou' | ||
180 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
181 | }) | ||
182 | }) | ||
183 | }) | ||
184 | |||
185 | it('Should succeed with the correct parameters', function (done) { | ||
186 | const data = { | ||
187 | host: 'coucou.com', | ||
188 | publicKey: 'mysuperpublickey' | ||
189 | } | ||
190 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200) | ||
191 | }) | ||
192 | }) | ||
193 | |||
194 | after(function (done) { | ||
195 | process.kill(-server.app.pid) | ||
196 | |||
197 | // Keep the logs if the test failed | ||
198 | if (this.ok) { | ||
199 | serversUtils.flushTests(done) | ||
200 | } else { | ||
201 | done() | ||
202 | } | ||
203 | }) | ||
204 | }) | ||
diff --git a/server/tests/api/check-params/remotes.js b/server/tests/api/check-params/remotes.js new file mode 100644 index 000000000..30ba3b697 --- /dev/null +++ b/server/tests/api/check-params/remotes.js | |||
@@ -0,0 +1,60 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const series = require('async/series') | ||
4 | |||
5 | const loginUtils = require('../../utils/login') | ||
6 | const serversUtils = require('../../utils/servers') | ||
7 | |||
8 | describe('Test remote videos API validators', function () { | ||
9 | let server = null | ||
10 | |||
11 | // --------------------------------------------------------------- | ||
12 | |||
13 | before(function (done) { | ||
14 | this.timeout(20000) | ||
15 | |||
16 | series([ | ||
17 | function (next) { | ||
18 | serversUtils.flushTests(next) | ||
19 | }, | ||
20 | function (next) { | ||
21 | serversUtils.runServer(1, function (server1) { | ||
22 | server = server1 | ||
23 | |||
24 | next() | ||
25 | }) | ||
26 | }, | ||
27 | function (next) { | ||
28 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
29 | if (err) throw err | ||
30 | server.accessToken = token | ||
31 | |||
32 | next() | ||
33 | }) | ||
34 | } | ||
35 | ], done) | ||
36 | }) | ||
37 | |||
38 | describe('When making a secure request', function () { | ||
39 | it('Should check a secure request') | ||
40 | }) | ||
41 | |||
42 | describe('When adding a video', function () { | ||
43 | it('Should check when adding a video') | ||
44 | }) | ||
45 | |||
46 | describe('When removing a video', function () { | ||
47 | it('Should check when removing a video') | ||
48 | }) | ||
49 | |||
50 | after(function (done) { | ||
51 | process.kill(-server.app.pid) | ||
52 | |||
53 | // Keep the logs if the test failed | ||
54 | if (this.ok) { | ||
55 | serversUtils.flushTests(done) | ||
56 | } else { | ||
57 | done() | ||
58 | } | ||
59 | }) | ||
60 | }) | ||
diff --git a/server/tests/api/check-params/requests.js b/server/tests/api/check-params/requests.js new file mode 100644 index 000000000..08f58db43 --- /dev/null +++ b/server/tests/api/check-params/requests.js | |||
@@ -0,0 +1,87 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const request = require('supertest') | ||
4 | const series = require('async/series') | ||
5 | |||
6 | const loginUtils = require('../../utils/login') | ||
7 | const usersUtils = require('../../utils/users') | ||
8 | const serversUtils = require('../../utils/servers') | ||
9 | |||
10 | describe('Test requests API validators', function () { | ||
11 | const path = '/api/v1/requests/stats' | ||
12 | let server = null | ||
13 | let userAccessToken = null | ||
14 | |||
15 | // --------------------------------------------------------------- | ||
16 | |||
17 | before(function (done) { | ||
18 | this.timeout(20000) | ||
19 | |||
20 | series([ | ||
21 | function (next) { | ||
22 | serversUtils.flushTests(next) | ||
23 | }, | ||
24 | function (next) { | ||
25 | serversUtils.runServer(1, function (server1) { | ||
26 | server = server1 | ||
27 | |||
28 | next() | ||
29 | }) | ||
30 | }, | ||
31 | function (next) { | ||
32 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
33 | if (err) throw err | ||
34 | server.accessToken = token | ||
35 | |||
36 | next() | ||
37 | }) | ||
38 | }, | ||
39 | function (next) { | ||
40 | const username = 'user' | ||
41 | const password = 'my super password' | ||
42 | |||
43 | usersUtils.createUser(server.url, server.accessToken, username, password, next) | ||
44 | }, | ||
45 | function (next) { | ||
46 | const user = { | ||
47 | username: 'user', | ||
48 | password: 'my super password' | ||
49 | } | ||
50 | |||
51 | loginUtils.getUserAccessToken(server, user, function (err, accessToken) { | ||
52 | if (err) throw err | ||
53 | |||
54 | userAccessToken = accessToken | ||
55 | |||
56 | next() | ||
57 | }) | ||
58 | } | ||
59 | ], done) | ||
60 | }) | ||
61 | |||
62 | it('Should fail with an non authenticated user', function (done) { | ||
63 | request(server.url) | ||
64 | .get(path) | ||
65 | .set('Accept', 'application/json') | ||
66 | .expect(401, done) | ||
67 | }) | ||
68 | |||
69 | it('Should fail with a non admin user', function (done) { | ||
70 | request(server.url) | ||
71 | .get(path) | ||
72 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
73 | .set('Accept', 'application/json') | ||
74 | .expect(403, done) | ||
75 | }) | ||
76 | |||
77 | after(function (done) { | ||
78 | process.kill(-server.app.pid) | ||
79 | |||
80 | // Keep the logs if the test failed | ||
81 | if (this.ok) { | ||
82 | serversUtils.flushTests(done) | ||
83 | } else { | ||
84 | done() | ||
85 | } | ||
86 | }) | ||
87 | }) | ||
diff --git a/server/tests/api/check-params/users.js b/server/tests/api/check-params/users.js new file mode 100644 index 000000000..c1fcf34a4 --- /dev/null +++ b/server/tests/api/check-params/users.js | |||
@@ -0,0 +1,284 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const request = require('supertest') | ||
4 | const series = require('async/series') | ||
5 | |||
6 | const loginUtils = require('../../utils/login') | ||
7 | const requestsUtils = require('../../utils/requests') | ||
8 | const serversUtils = require('../../utils/servers') | ||
9 | const usersUtils = require('../../utils/users') | ||
10 | |||
11 | describe('Test users API validators', function () { | ||
12 | const path = '/api/v1/users/' | ||
13 | let userId = null | ||
14 | let rootId = null | ||
15 | let server = null | ||
16 | let userAccessToken = null | ||
17 | |||
18 | // --------------------------------------------------------------- | ||
19 | |||
20 | before(function (done) { | ||
21 | this.timeout(20000) | ||
22 | |||
23 | series([ | ||
24 | function (next) { | ||
25 | serversUtils.flushTests(next) | ||
26 | }, | ||
27 | function (next) { | ||
28 | serversUtils.runServer(1, function (server1) { | ||
29 | server = server1 | ||
30 | |||
31 | next() | ||
32 | }) | ||
33 | }, | ||
34 | function (next) { | ||
35 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
36 | if (err) throw err | ||
37 | server.accessToken = token | ||
38 | |||
39 | next() | ||
40 | }) | ||
41 | }, | ||
42 | function (next) { | ||
43 | const username = 'user1' | ||
44 | const password = 'my super password' | ||
45 | |||
46 | usersUtils.createUser(server.url, server.accessToken, username, password, next) | ||
47 | }, | ||
48 | function (next) { | ||
49 | const user = { | ||
50 | username: 'user1', | ||
51 | password: 'my super password' | ||
52 | } | ||
53 | |||
54 | loginUtils.getUserAccessToken(server, user, function (err, accessToken) { | ||
55 | if (err) throw err | ||
56 | |||
57 | userAccessToken = accessToken | ||
58 | |||
59 | next() | ||
60 | }) | ||
61 | } | ||
62 | ], done) | ||
63 | }) | ||
64 | |||
65 | describe('When listing users', function () { | ||
66 | it('Should fail with a bad start pagination', function (done) { | ||
67 | request(server.url) | ||
68 | .get(path) | ||
69 | .query({ start: 'hello' }) | ||
70 | .set('Accept', 'application/json') | ||
71 | .expect(400, done) | ||
72 | }) | ||
73 | |||
74 | it('Should fail with a bad count pagination', function (done) { | ||
75 | request(server.url) | ||
76 | .get(path) | ||
77 | .query({ count: 'hello' }) | ||
78 | .set('Accept', 'application/json') | ||
79 | .expect(400, done) | ||
80 | }) | ||
81 | |||
82 | it('Should fail with an incorrect sort', function (done) { | ||
83 | request(server.url) | ||
84 | .get(path) | ||
85 | .query({ sort: 'hello' }) | ||
86 | .set('Accept', 'application/json') | ||
87 | .expect(400, done) | ||
88 | }) | ||
89 | }) | ||
90 | |||
91 | describe('When adding a new user', function () { | ||
92 | it('Should fail with a too small username', function (done) { | ||
93 | const data = { | ||
94 | username: 'ji', | ||
95 | password: 'mysuperpassword' | ||
96 | } | ||
97 | |||
98 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
99 | }) | ||
100 | |||
101 | it('Should fail with a too long username', function (done) { | ||
102 | const data = { | ||
103 | username: 'mysuperusernamewhichisverylong', | ||
104 | password: 'mysuperpassword' | ||
105 | } | ||
106 | |||
107 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
108 | }) | ||
109 | |||
110 | it('Should fail with an incorrect username', function (done) { | ||
111 | const data = { | ||
112 | username: 'my username', | ||
113 | password: 'mysuperpassword' | ||
114 | } | ||
115 | |||
116 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
117 | }) | ||
118 | |||
119 | it('Should fail with a too small password', function (done) { | ||
120 | const data = { | ||
121 | username: 'myusername', | ||
122 | password: 'bla' | ||
123 | } | ||
124 | |||
125 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
126 | }) | ||
127 | |||
128 | it('Should fail with a too long password', function (done) { | ||
129 | const data = { | ||
130 | username: 'myusername', | ||
131 | password: 'my super long password which is very very very very very very very very very very very very very very' + | ||
132 | 'very very very very very very very very very very very very very very very veryv very very very very' + | ||
133 | 'very very very very very very very very very very very very very very very very very very very very long' | ||
134 | } | ||
135 | |||
136 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
137 | }) | ||
138 | |||
139 | it('Should fail with an non authenticated user', function (done) { | ||
140 | const data = { | ||
141 | username: 'myusername', | ||
142 | password: 'my super password' | ||
143 | } | ||
144 | |||
145 | requestsUtils.makePostBodyRequest(server.url, path, 'super token', data, done, 401) | ||
146 | }) | ||
147 | |||
148 | it('Should fail if we add a user with the same username', function (done) { | ||
149 | const data = { | ||
150 | username: 'user1', | ||
151 | password: 'my super password' | ||
152 | } | ||
153 | |||
154 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 409) | ||
155 | }) | ||
156 | |||
157 | it('Should succeed with the correct params', function (done) { | ||
158 | const data = { | ||
159 | username: 'user2', | ||
160 | password: 'my super password' | ||
161 | } | ||
162 | |||
163 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204) | ||
164 | }) | ||
165 | |||
166 | it('Should fail with a non admin user', function (done) { | ||
167 | server.user = { | ||
168 | username: 'user1', | ||
169 | password: 'my super password' | ||
170 | } | ||
171 | |||
172 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
173 | if (err) throw err | ||
174 | |||
175 | userAccessToken = accessToken | ||
176 | |||
177 | const data = { | ||
178 | username: 'user3', | ||
179 | password: 'my super password' | ||
180 | } | ||
181 | |||
182 | requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403) | ||
183 | }) | ||
184 | }) | ||
185 | }) | ||
186 | |||
187 | describe('When updating a user', function () { | ||
188 | before(function (done) { | ||
189 | usersUtils.getUsersList(server.url, function (err, res) { | ||
190 | if (err) throw err | ||
191 | |||
192 | userId = res.body.data[1].id | ||
193 | rootId = res.body.data[2].id | ||
194 | done() | ||
195 | }) | ||
196 | }) | ||
197 | |||
198 | it('Should fail with a too small password', function (done) { | ||
199 | const data = { | ||
200 | password: 'bla' | ||
201 | } | ||
202 | |||
203 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) | ||
204 | }) | ||
205 | |||
206 | it('Should fail with a too long password', function (done) { | ||
207 | const data = { | ||
208 | password: 'my super long password which is very very very very very very very very very very very very very very' + | ||
209 | 'very very very very very very very very very very very very very very very veryv very very very very' + | ||
210 | 'very very very very very very very very very very very very very very very very very very very very long' | ||
211 | } | ||
212 | |||
213 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) | ||
214 | }) | ||
215 | |||
216 | it('Should fail with an non authenticated user', function (done) { | ||
217 | const data = { | ||
218 | password: 'my super password' | ||
219 | } | ||
220 | |||
221 | requestsUtils.makePutBodyRequest(server.url, path + userId, 'super token', data, done, 401) | ||
222 | }) | ||
223 | |||
224 | it('Should succeed with the correct params', function (done) { | ||
225 | const data = { | ||
226 | password: 'my super password' | ||
227 | } | ||
228 | |||
229 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done, 204) | ||
230 | }) | ||
231 | }) | ||
232 | |||
233 | describe('When getting my information', function () { | ||
234 | it('Should fail with a non authenticated user', function (done) { | ||
235 | request(server.url) | ||
236 | .get(path + 'me') | ||
237 | .set('Authorization', 'Bearer faketoken') | ||
238 | .set('Accept', 'application/json') | ||
239 | .expect(401, done) | ||
240 | }) | ||
241 | |||
242 | it('Should success with the correct parameters', function (done) { | ||
243 | request(server.url) | ||
244 | .get(path + 'me') | ||
245 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
246 | .set('Accept', 'application/json') | ||
247 | .expect(200, done) | ||
248 | }) | ||
249 | }) | ||
250 | |||
251 | describe('When removing an user', function () { | ||
252 | it('Should fail with an incorrect id', function (done) { | ||
253 | request(server.url) | ||
254 | .delete(path + 'bla-bla') | ||
255 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
256 | .expect(400, done) | ||
257 | }) | ||
258 | |||
259 | it('Should fail with the root user', function (done) { | ||
260 | request(server.url) | ||
261 | .delete(path + rootId) | ||
262 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
263 | .expect(400, done) | ||
264 | }) | ||
265 | |||
266 | it('Should return 404 with a non existing id', function (done) { | ||
267 | request(server.url) | ||
268 | .delete(path + '45') | ||
269 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
270 | .expect(404, done) | ||
271 | }) | ||
272 | }) | ||
273 | |||
274 | after(function (done) { | ||
275 | process.kill(-server.app.pid) | ||
276 | |||
277 | // Keep the logs if the test failed | ||
278 | if (this.ok) { | ||
279 | serversUtils.flushTests(done) | ||
280 | } else { | ||
281 | done() | ||
282 | } | ||
283 | }) | ||
284 | }) | ||
diff --git a/server/tests/api/check-params/videos.js b/server/tests/api/check-params/videos.js new file mode 100644 index 000000000..d18305291 --- /dev/null +++ b/server/tests/api/check-params/videos.js | |||
@@ -0,0 +1,456 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const chai = require('chai') | ||
4 | const expect = chai.expect | ||
5 | const pathUtils = require('path') | ||
6 | const request = require('supertest') | ||
7 | const series = require('async/series') | ||
8 | |||
9 | const loginUtils = require('../../utils/login') | ||
10 | const requestsUtils = require('../../utils/requests') | ||
11 | const serversUtils = require('../../utils/servers') | ||
12 | const videosUtils = require('../../utils/videos') | ||
13 | |||
14 | describe('Test videos API validator', function () { | ||
15 | const path = '/api/v1/videos/' | ||
16 | let server = null | ||
17 | |||
18 | // --------------------------------------------------------------- | ||
19 | |||
20 | before(function (done) { | ||
21 | this.timeout(20000) | ||
22 | |||
23 | series([ | ||
24 | function (next) { | ||
25 | serversUtils.flushTests(next) | ||
26 | }, | ||
27 | function (next) { | ||
28 | serversUtils.runServer(1, function (server1) { | ||
29 | server = server1 | ||
30 | |||
31 | next() | ||
32 | }) | ||
33 | }, | ||
34 | function (next) { | ||
35 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
36 | if (err) throw err | ||
37 | server.accessToken = token | ||
38 | |||
39 | next() | ||
40 | }) | ||
41 | } | ||
42 | ], done) | ||
43 | }) | ||
44 | |||
45 | describe('When listing a video', function () { | ||
46 | it('Should fail with a bad start pagination', function (done) { | ||
47 | request(server.url) | ||
48 | .get(path) | ||
49 | .query({ start: 'hello' }) | ||
50 | .set('Accept', 'application/json') | ||
51 | .expect(400, done) | ||
52 | }) | ||
53 | |||
54 | it('Should fail with a bad count pagination', function (done) { | ||
55 | request(server.url) | ||
56 | .get(path) | ||
57 | .query({ count: 'hello' }) | ||
58 | .set('Accept', 'application/json') | ||
59 | .expect(400, done) | ||
60 | }) | ||
61 | |||
62 | it('Should fail with an incorrect sort', function (done) { | ||
63 | request(server.url) | ||
64 | .get(path) | ||
65 | .query({ sort: 'hello' }) | ||
66 | .set('Accept', 'application/json') | ||
67 | .expect(400, done) | ||
68 | }) | ||
69 | }) | ||
70 | |||
71 | describe('When searching a video', function () { | ||
72 | it('Should fail with nothing', function (done) { | ||
73 | request(server.url) | ||
74 | .get(pathUtils.join(path, 'search')) | ||
75 | .set('Accept', 'application/json') | ||
76 | .expect(400, done) | ||
77 | }) | ||
78 | |||
79 | it('Should fail with a bad start pagination', function (done) { | ||
80 | request(server.url) | ||
81 | .get(pathUtils.join(path, 'search', 'test')) | ||
82 | .query({ start: 'hello' }) | ||
83 | .set('Accept', 'application/json') | ||
84 | .expect(400, done) | ||
85 | }) | ||
86 | |||
87 | it('Should fail with a bad count pagination', function (done) { | ||
88 | request(server.url) | ||
89 | .get(pathUtils.join(path, 'search', 'test')) | ||
90 | .query({ count: 'hello' }) | ||
91 | .set('Accept', 'application/json') | ||
92 | .expect(400, done) | ||
93 | }) | ||
94 | |||
95 | it('Should fail with an incorrect sort', function (done) { | ||
96 | request(server.url) | ||
97 | .get(pathUtils.join(path, 'search', 'test')) | ||
98 | .query({ sort: 'hello' }) | ||
99 | .set('Accept', 'application/json') | ||
100 | .expect(400, done) | ||
101 | }) | ||
102 | }) | ||
103 | |||
104 | describe('When adding a video', function () { | ||
105 | it('Should fail with nothing', function (done) { | ||
106 | const data = {} | ||
107 | const attach = {} | ||
108 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
109 | }) | ||
110 | |||
111 | it('Should fail without name', function (done) { | ||
112 | const data = { | ||
113 | description: 'my super description', | ||
114 | tags: [ 'tag1', 'tag2' ] | ||
115 | } | ||
116 | const attach = { | ||
117 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
118 | } | ||
119 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
120 | }) | ||
121 | |||
122 | it('Should fail with a long name', function (done) { | ||
123 | const data = { | ||
124 | name: 'My very very very very very very very very very very very very very very very very long name', | ||
125 | description: 'my super description', | ||
126 | tags: [ 'tag1', 'tag2' ] | ||
127 | } | ||
128 | const attach = { | ||
129 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
130 | } | ||
131 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
132 | }) | ||
133 | |||
134 | it('Should fail without description', function (done) { | ||
135 | const data = { | ||
136 | name: 'my super name', | ||
137 | tags: [ 'tag1', 'tag2' ] | ||
138 | } | ||
139 | const attach = { | ||
140 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
141 | } | ||
142 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
143 | }) | ||
144 | |||
145 | it('Should fail with a long description', function (done) { | ||
146 | const data = { | ||
147 | name: 'my super name', | ||
148 | description: 'my super description which is very very very very very very very very very very very very very very' + | ||
149 | 'very very very very very very very very very very very very very very very very very very very very very' + | ||
150 | 'very very very very very very very very very very very very very very very long', | ||
151 | tags: [ 'tag1', 'tag2' ] | ||
152 | } | ||
153 | const attach = { | ||
154 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
155 | } | ||
156 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
157 | }) | ||
158 | |||
159 | it('Should fail without tags', function (done) { | ||
160 | const data = { | ||
161 | name: 'my super name', | ||
162 | description: 'my super description' | ||
163 | } | ||
164 | const attach = { | ||
165 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
166 | } | ||
167 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
168 | }) | ||
169 | |||
170 | it('Should fail with too many tags', function (done) { | ||
171 | const data = { | ||
172 | name: 'my super name', | ||
173 | description: 'my super description', | ||
174 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | ||
175 | } | ||
176 | const attach = { | ||
177 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
178 | } | ||
179 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
180 | }) | ||
181 | |||
182 | it('Should fail with not enough tags', function (done) { | ||
183 | const data = { | ||
184 | name: 'my super name', | ||
185 | description: 'my super description', | ||
186 | tags: [ ] | ||
187 | } | ||
188 | const attach = { | ||
189 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
190 | } | ||
191 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
192 | }) | ||
193 | |||
194 | it('Should fail with a tag length too low', function (done) { | ||
195 | const data = { | ||
196 | name: 'my super name', | ||
197 | description: 'my super description', | ||
198 | tags: [ 'tag1', 't' ] | ||
199 | } | ||
200 | const attach = { | ||
201 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
202 | } | ||
203 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
204 | }) | ||
205 | |||
206 | it('Should fail with a tag length too big', function (done) { | ||
207 | const data = { | ||
208 | name: 'my super name', | ||
209 | description: 'my super description', | ||
210 | tags: [ 'mysupertagtoolong', 'tag1' ] | ||
211 | } | ||
212 | const attach = { | ||
213 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
214 | } | ||
215 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
216 | }) | ||
217 | |||
218 | it('Should fail with malformed tags', function (done) { | ||
219 | const data = { | ||
220 | name: 'my super name', | ||
221 | description: 'my super description', | ||
222 | tags: [ 'my tag' ] | ||
223 | } | ||
224 | const attach = { | ||
225 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
226 | } | ||
227 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
228 | }) | ||
229 | |||
230 | it('Should fail without an input file', function (done) { | ||
231 | const data = { | ||
232 | name: 'my super name', | ||
233 | description: 'my super description', | ||
234 | tags: [ 'tag1', 'tag2' ] | ||
235 | } | ||
236 | const attach = {} | ||
237 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
238 | }) | ||
239 | |||
240 | it('Should fail without an incorrect input file', function (done) { | ||
241 | const data = { | ||
242 | name: 'my super name', | ||
243 | description: 'my super description', | ||
244 | tags: [ 'tag1', 'tag2' ] | ||
245 | } | ||
246 | const attach = { | ||
247 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm') | ||
248 | } | ||
249 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
250 | }) | ||
251 | |||
252 | it('Should fail with a too big duration', function (done) { | ||
253 | const data = { | ||
254 | name: 'my super name', | ||
255 | description: 'my super description', | ||
256 | tags: [ 'tag1', 'tag2' ] | ||
257 | } | ||
258 | const attach = { | ||
259 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_too_long.webm') | ||
260 | } | ||
261 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
262 | }) | ||
263 | |||
264 | it('Should succeed with the correct parameters', function (done) { | ||
265 | const data = { | ||
266 | name: 'my super name', | ||
267 | description: 'my super description', | ||
268 | tags: [ 'tag1', 'tag2' ] | ||
269 | } | ||
270 | const attach = { | ||
271 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | ||
272 | } | ||
273 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { | ||
274 | attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.mp4') | ||
275 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { | ||
276 | attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.ogv') | ||
277 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done, 204) | ||
278 | }, false) | ||
279 | }, false) | ||
280 | }) | ||
281 | }) | ||
282 | |||
283 | describe('When updating a video', function () { | ||
284 | let videoId | ||
285 | |||
286 | before(function (done) { | ||
287 | videosUtils.getVideosList(server.url, function (err, res) { | ||
288 | if (err) throw err | ||
289 | |||
290 | videoId = res.body.data[0].id | ||
291 | |||
292 | return done() | ||
293 | }) | ||
294 | }) | ||
295 | |||
296 | it('Should fail with nothing', function (done) { | ||
297 | const data = {} | ||
298 | requestsUtils.makePutBodyRequest(server.url, path, server.accessToken, data, done) | ||
299 | }) | ||
300 | |||
301 | it('Should fail without a valid uuid', function (done) { | ||
302 | const data = { | ||
303 | description: 'my super description', | ||
304 | tags: [ 'tag1', 'tag2' ] | ||
305 | } | ||
306 | requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done) | ||
307 | }) | ||
308 | |||
309 | it('Should fail with an unknown id', function (done) { | ||
310 | const data = { | ||
311 | description: 'my super description', | ||
312 | tags: [ 'tag1', 'tag2' ] | ||
313 | } | ||
314 | requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done, 404) | ||
315 | }) | ||
316 | |||
317 | it('Should fail with a long name', function (done) { | ||
318 | const data = { | ||
319 | name: 'My very very very very very very very very very very very very very very very very long name', | ||
320 | description: 'my super description', | ||
321 | tags: [ 'tag1', 'tag2' ] | ||
322 | } | ||
323 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
324 | }) | ||
325 | |||
326 | it('Should fail with a long description', function (done) { | ||
327 | const data = { | ||
328 | name: 'my super name', | ||
329 | description: 'my super description which is very very very very very very very very very very very very very very' + | ||
330 | 'very very very very very very very very very very very very very very very very very very very very very' + | ||
331 | 'very very very very very very very very very very very very very very very long', | ||
332 | tags: [ 'tag1', 'tag2' ] | ||
333 | } | ||
334 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
335 | }) | ||
336 | |||
337 | it('Should fail with too many tags', function (done) { | ||
338 | const data = { | ||
339 | name: 'my super name', | ||
340 | description: 'my super description', | ||
341 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | ||
342 | } | ||
343 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
344 | }) | ||
345 | |||
346 | it('Should fail with not enough tags', function (done) { | ||
347 | const data = { | ||
348 | name: 'my super name', | ||
349 | description: 'my super description', | ||
350 | tags: [ ] | ||
351 | } | ||
352 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
353 | }) | ||
354 | |||
355 | it('Should fail with a tag length too low', function (done) { | ||
356 | const data = { | ||
357 | name: 'my super name', | ||
358 | description: 'my super description', | ||
359 | tags: [ 'tag1', 't' ] | ||
360 | } | ||
361 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
362 | }) | ||
363 | |||
364 | it('Should fail with a tag length too big', function (done) { | ||
365 | const data = { | ||
366 | name: 'my super name', | ||
367 | description: 'my super description', | ||
368 | tags: [ 'mysupertagtoolong', 'tag1' ] | ||
369 | } | ||
370 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
371 | }) | ||
372 | |||
373 | it('Should fail with malformed tags', function (done) { | ||
374 | const data = { | ||
375 | name: 'my super name', | ||
376 | description: 'my super description', | ||
377 | tags: [ 'my tag' ] | ||
378 | } | ||
379 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
380 | }) | ||
381 | }) | ||
382 | |||
383 | describe('When getting a video', function () { | ||
384 | it('Should return the list of the videos with nothing', function (done) { | ||
385 | request(server.url) | ||
386 | .get(path) | ||
387 | .set('Accept', 'application/json') | ||
388 | .expect(200) | ||
389 | .expect('Content-Type', /json/) | ||
390 | .end(function (err, res) { | ||
391 | if (err) throw err | ||
392 | |||
393 | expect(res.body.data).to.be.an('array') | ||
394 | expect(res.body.data.length).to.equal(3) | ||
395 | |||
396 | done() | ||
397 | }) | ||
398 | }) | ||
399 | |||
400 | it('Should fail without a correct uuid', function (done) { | ||
401 | request(server.url) | ||
402 | .get(path + 'coucou') | ||
403 | .set('Accept', 'application/json') | ||
404 | .expect(400, done) | ||
405 | }) | ||
406 | |||
407 | it('Should return 404 with an incorrect video', function (done) { | ||
408 | request(server.url) | ||
409 | .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06') | ||
410 | .set('Accept', 'application/json') | ||
411 | .expect(404, done) | ||
412 | }) | ||
413 | |||
414 | it('Should succeed with the correct parameters') | ||
415 | }) | ||
416 | |||
417 | describe('When removing a video', function () { | ||
418 | it('Should have 404 with nothing', function (done) { | ||
419 | request(server.url) | ||
420 | .delete(path) | ||
421 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
422 | .expect(400, done) | ||
423 | }) | ||
424 | |||
425 | it('Should fail without a correct uuid', function (done) { | ||
426 | request(server.url) | ||
427 | .delete(path + 'hello') | ||
428 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
429 | .expect(400, done) | ||
430 | }) | ||
431 | |||
432 | it('Should fail with a video which does not exist', function (done) { | ||
433 | request(server.url) | ||
434 | .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06') | ||
435 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
436 | .expect(404, done) | ||
437 | }) | ||
438 | |||
439 | it('Should fail with a video of another user') | ||
440 | |||
441 | it('Should fail with a video of another pod') | ||
442 | |||
443 | it('Should succeed with the correct parameters') | ||
444 | }) | ||
445 | |||
446 | after(function (done) { | ||
447 | process.kill(-server.app.pid) | ||
448 | |||
449 | // Keep the logs if the test failed | ||
450 | if (this.ok) { | ||
451 | serversUtils.flushTests(done) | ||
452 | } else { | ||
453 | done() | ||
454 | } | ||
455 | }) | ||
456 | }) | ||