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 | |
parent | 818f7987eba27c59793e2103168b26129c9404f2 (diff) | |
download | PeerTube-efe923bcdaf15b47593ad8583df09a92c715ac6c.tar.gz PeerTube-efe923bcdaf15b47593ad8583df09a92c715ac6c.tar.zst PeerTube-efe923bcdaf15b47593ad8583df09a92c715ac6c.zip |
Server: split check params tests
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/remote.js | 1 | ||||
-rw-r--r-- | server/tests/api/check-params.js | 865 | ||||
-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 | ||||
-rw-r--r-- | server/tests/utils/login.js | 11 | ||||
-rw-r--r-- | server/tests/utils/servers.js | 2 |
10 files changed, 1110 insertions, 868 deletions
diff --git a/server/controllers/api/remote.js b/server/controllers/api/remote.js index a36c31c38..be5e6dc98 100644 --- a/server/controllers/api/remote.js +++ b/server/controllers/api/remote.js | |||
@@ -1,6 +1,5 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | const each = require('async/each') | ||
4 | const eachSeries = require('async/eachSeries') | 3 | const eachSeries = require('async/eachSeries') |
5 | const express = require('express') | 4 | const express = require('express') |
6 | const waterfall = require('async/waterfall') | 5 | const waterfall = require('async/waterfall') |
diff --git a/server/tests/api/check-params.js b/server/tests/api/check-params.js deleted file mode 100644 index e8f2aa821..000000000 --- a/server/tests/api/check-params.js +++ /dev/null | |||
@@ -1,865 +0,0 @@ | |||
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 usersUtils = require('../utils/users') | ||
13 | const videosUtils = require('../utils/videos') | ||
14 | |||
15 | describe('Test parameters validator', function () { | ||
16 | let server = null | ||
17 | let userAccessToken = null | ||
18 | |||
19 | // --------------------------------------------------------------- | ||
20 | |||
21 | before(function (done) { | ||
22 | this.timeout(20000) | ||
23 | |||
24 | series([ | ||
25 | function (next) { | ||
26 | serversUtils.flushTests(next) | ||
27 | }, | ||
28 | function (next) { | ||
29 | serversUtils.runServer(1, function (server1) { | ||
30 | server = server1 | ||
31 | |||
32 | next() | ||
33 | }) | ||
34 | }, | ||
35 | function (next) { | ||
36 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
37 | if (err) throw err | ||
38 | server.accessToken = token | ||
39 | |||
40 | next() | ||
41 | }) | ||
42 | } | ||
43 | ], done) | ||
44 | }) | ||
45 | |||
46 | describe('Of the pods API', function () { | ||
47 | const path = '/api/v1/pods/' | ||
48 | |||
49 | describe('When making friends', function () { | ||
50 | let userAccessToken = null | ||
51 | |||
52 | before(function (done) { | ||
53 | usersUtils.createUser(server.url, server.accessToken, 'user1', 'password', function () { | ||
54 | server.user = { | ||
55 | username: 'user1', | ||
56 | password: 'password' | ||
57 | } | ||
58 | |||
59 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
60 | if (err) throw err | ||
61 | |||
62 | userAccessToken = accessToken | ||
63 | |||
64 | done() | ||
65 | }) | ||
66 | }) | ||
67 | }) | ||
68 | |||
69 | describe('When making friends', function () { | ||
70 | const body = { | ||
71 | hosts: [ 'localhost:9002' ] | ||
72 | } | ||
73 | |||
74 | it('Should fail without hosts', function (done) { | ||
75 | request(server.url) | ||
76 | .post(path + '/makefriends') | ||
77 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
78 | .set('Accept', 'application/json') | ||
79 | .expect(400, done) | ||
80 | }) | ||
81 | |||
82 | it('Should fail if hosts is not an array', function (done) { | ||
83 | request(server.url) | ||
84 | .post(path + '/makefriends') | ||
85 | .send({ hosts: 'localhost:9002' }) | ||
86 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
87 | .set('Accept', 'application/json') | ||
88 | .expect(400, done) | ||
89 | }) | ||
90 | |||
91 | it('Should fail if the array is not composed by hosts', function (done) { | ||
92 | request(server.url) | ||
93 | .post(path + '/makefriends') | ||
94 | .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] }) | ||
95 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
96 | .set('Accept', 'application/json') | ||
97 | .expect(400, done) | ||
98 | }) | ||
99 | |||
100 | it('Should fail if the array is composed with http schemes', function (done) { | ||
101 | request(server.url) | ||
102 | .post(path + '/makefriends') | ||
103 | .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] }) | ||
104 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
105 | .set('Accept', 'application/json') | ||
106 | .expect(400, done) | ||
107 | }) | ||
108 | |||
109 | it('Should fail if hosts are not unique', function (done) { | ||
110 | request(server.url) | ||
111 | .post(path + '/makefriends') | ||
112 | .send({ urls: [ 'localhost:9002', 'localhost:9002' ] }) | ||
113 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
114 | .set('Accept', 'application/json') | ||
115 | .expect(400, done) | ||
116 | }) | ||
117 | |||
118 | it('Should fail with a invalid token', function (done) { | ||
119 | request(server.url) | ||
120 | .post(path + '/makefriends') | ||
121 | .send(body) | ||
122 | .set('Authorization', 'Bearer faketoken') | ||
123 | .set('Accept', 'application/json') | ||
124 | .expect(401, done) | ||
125 | }) | ||
126 | |||
127 | it('Should fail if the user is not an administrator', function (done) { | ||
128 | request(server.url) | ||
129 | .post(path + '/makefriends') | ||
130 | .send(body) | ||
131 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
132 | .set('Accept', 'application/json') | ||
133 | .expect(403, done) | ||
134 | }) | ||
135 | }) | ||
136 | |||
137 | describe('When quitting friends', function () { | ||
138 | it('Should fail with a invalid token', function (done) { | ||
139 | request(server.url) | ||
140 | .get(path + '/quitfriends') | ||
141 | .query({ start: 'hello' }) | ||
142 | .set('Authorization', 'Bearer faketoken') | ||
143 | .set('Accept', 'application/json') | ||
144 | .expect(401, done) | ||
145 | }) | ||
146 | |||
147 | it('Should fail if the user is not an administrator', function (done) { | ||
148 | request(server.url) | ||
149 | .get(path + '/quitfriends') | ||
150 | .query({ start: 'hello' }) | ||
151 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
152 | .set('Accept', 'application/json') | ||
153 | .expect(403, done) | ||
154 | }) | ||
155 | }) | ||
156 | }) | ||
157 | |||
158 | describe('When adding a pod', function () { | ||
159 | it('Should fail with nothing', function (done) { | ||
160 | const data = {} | ||
161 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
162 | }) | ||
163 | |||
164 | it('Should fail without public key', function (done) { | ||
165 | const data = { | ||
166 | host: 'coucou.com' | ||
167 | } | ||
168 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
169 | }) | ||
170 | |||
171 | it('Should fail without an host', function (done) { | ||
172 | const data = { | ||
173 | publicKey: 'mysuperpublickey' | ||
174 | } | ||
175 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
176 | }) | ||
177 | |||
178 | it('Should fail with an incorrect host', function (done) { | ||
179 | const data = { | ||
180 | host: 'http://coucou.com', | ||
181 | publicKey: 'mysuperpublickey' | ||
182 | } | ||
183 | requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { | ||
184 | data.host = 'http://coucou' | ||
185 | requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { | ||
186 | data.host = 'coucou' | ||
187 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done) | ||
188 | }) | ||
189 | }) | ||
190 | }) | ||
191 | |||
192 | it('Should succeed with the correct parameters', function (done) { | ||
193 | const data = { | ||
194 | host: 'coucou.com', | ||
195 | publicKey: 'mysuperpublickey' | ||
196 | } | ||
197 | requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200) | ||
198 | }) | ||
199 | }) | ||
200 | }) | ||
201 | |||
202 | describe('Of the videos API', function () { | ||
203 | const path = '/api/v1/videos/' | ||
204 | |||
205 | describe('When listing a video', function () { | ||
206 | it('Should fail with a bad start pagination', function (done) { | ||
207 | request(server.url) | ||
208 | .get(path) | ||
209 | .query({ start: 'hello' }) | ||
210 | .set('Accept', 'application/json') | ||
211 | .expect(400, done) | ||
212 | }) | ||
213 | |||
214 | it('Should fail with a bad count pagination', function (done) { | ||
215 | request(server.url) | ||
216 | .get(path) | ||
217 | .query({ count: 'hello' }) | ||
218 | .set('Accept', 'application/json') | ||
219 | .expect(400, done) | ||
220 | }) | ||
221 | |||
222 | it('Should fail with an incorrect sort', function (done) { | ||
223 | request(server.url) | ||
224 | .get(path) | ||
225 | .query({ sort: 'hello' }) | ||
226 | .set('Accept', 'application/json') | ||
227 | .expect(400, done) | ||
228 | }) | ||
229 | }) | ||
230 | |||
231 | describe('When searching a video', function () { | ||
232 | it('Should fail with nothing', function (done) { | ||
233 | request(server.url) | ||
234 | .get(pathUtils.join(path, 'search')) | ||
235 | .set('Accept', 'application/json') | ||
236 | .expect(400, done) | ||
237 | }) | ||
238 | |||
239 | it('Should fail with a bad start pagination', function (done) { | ||
240 | request(server.url) | ||
241 | .get(pathUtils.join(path, 'search', 'test')) | ||
242 | .query({ start: 'hello' }) | ||
243 | .set('Accept', 'application/json') | ||
244 | .expect(400, done) | ||
245 | }) | ||
246 | |||
247 | it('Should fail with a bad count pagination', function (done) { | ||
248 | request(server.url) | ||
249 | .get(pathUtils.join(path, 'search', 'test')) | ||
250 | .query({ count: 'hello' }) | ||
251 | .set('Accept', 'application/json') | ||
252 | .expect(400, done) | ||
253 | }) | ||
254 | |||
255 | it('Should fail with an incorrect sort', function (done) { | ||
256 | request(server.url) | ||
257 | .get(pathUtils.join(path, 'search', 'test')) | ||
258 | .query({ sort: 'hello' }) | ||
259 | .set('Accept', 'application/json') | ||
260 | .expect(400, done) | ||
261 | }) | ||
262 | }) | ||
263 | |||
264 | describe('When adding a video', function () { | ||
265 | it('Should fail with nothing', function (done) { | ||
266 | const data = {} | ||
267 | const attach = {} | ||
268 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
269 | }) | ||
270 | |||
271 | it('Should fail without name', function (done) { | ||
272 | const data = { | ||
273 | description: 'my super description', | ||
274 | tags: [ 'tag1', 'tag2' ] | ||
275 | } | ||
276 | const attach = { | ||
277 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
278 | } | ||
279 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
280 | }) | ||
281 | |||
282 | it('Should fail with a long name', function (done) { | ||
283 | const data = { | ||
284 | name: 'My very very very very very very very very very very very very very very very very long name', | ||
285 | description: 'my super description', | ||
286 | tags: [ 'tag1', 'tag2' ] | ||
287 | } | ||
288 | const attach = { | ||
289 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
290 | } | ||
291 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
292 | }) | ||
293 | |||
294 | it('Should fail without description', function (done) { | ||
295 | const data = { | ||
296 | name: 'my super name', | ||
297 | tags: [ 'tag1', 'tag2' ] | ||
298 | } | ||
299 | const attach = { | ||
300 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
301 | } | ||
302 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
303 | }) | ||
304 | |||
305 | it('Should fail with a long description', function (done) { | ||
306 | const data = { | ||
307 | name: 'my super name', | ||
308 | description: 'my super description which is very very very very very very very very very very very very very very' + | ||
309 | 'very very very very very very very very very very very very very very very very very very very very very' + | ||
310 | 'very very very very very very very very very very very very very very very long', | ||
311 | tags: [ 'tag1', 'tag2' ] | ||
312 | } | ||
313 | const attach = { | ||
314 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
315 | } | ||
316 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
317 | }) | ||
318 | |||
319 | it('Should fail without tags', function (done) { | ||
320 | const data = { | ||
321 | name: 'my super name', | ||
322 | description: 'my super description' | ||
323 | } | ||
324 | const attach = { | ||
325 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
326 | } | ||
327 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
328 | }) | ||
329 | |||
330 | it('Should fail with too many tags', function (done) { | ||
331 | const data = { | ||
332 | name: 'my super name', | ||
333 | description: 'my super description', | ||
334 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | ||
335 | } | ||
336 | const attach = { | ||
337 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
338 | } | ||
339 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
340 | }) | ||
341 | |||
342 | it('Should fail with not enough tags', function (done) { | ||
343 | const data = { | ||
344 | name: 'my super name', | ||
345 | description: 'my super description', | ||
346 | tags: [ ] | ||
347 | } | ||
348 | const attach = { | ||
349 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
350 | } | ||
351 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
352 | }) | ||
353 | |||
354 | it('Should fail with a tag length too low', function (done) { | ||
355 | const data = { | ||
356 | name: 'my super name', | ||
357 | description: 'my super description', | ||
358 | tags: [ 'tag1', 't' ] | ||
359 | } | ||
360 | const attach = { | ||
361 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
362 | } | ||
363 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
364 | }) | ||
365 | |||
366 | it('Should fail with a tag length too big', function (done) { | ||
367 | const data = { | ||
368 | name: 'my super name', | ||
369 | description: 'my super description', | ||
370 | tags: [ 'mysupertagtoolong', 'tag1' ] | ||
371 | } | ||
372 | const attach = { | ||
373 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
374 | } | ||
375 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
376 | }) | ||
377 | |||
378 | it('Should fail with malformed tags', function (done) { | ||
379 | const data = { | ||
380 | name: 'my super name', | ||
381 | description: 'my super description', | ||
382 | tags: [ 'my tag' ] | ||
383 | } | ||
384 | const attach = { | ||
385 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
386 | } | ||
387 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
388 | }) | ||
389 | |||
390 | it('Should fail without an input file', function (done) { | ||
391 | const data = { | ||
392 | name: 'my super name', | ||
393 | description: 'my super description', | ||
394 | tags: [ 'tag1', 'tag2' ] | ||
395 | } | ||
396 | const attach = {} | ||
397 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
398 | }) | ||
399 | |||
400 | it('Should fail without an incorrect input file', function (done) { | ||
401 | const data = { | ||
402 | name: 'my super name', | ||
403 | description: 'my super description', | ||
404 | tags: [ 'tag1', 'tag2' ] | ||
405 | } | ||
406 | const attach = { | ||
407 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short_fake.webm') | ||
408 | } | ||
409 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
410 | }) | ||
411 | |||
412 | it('Should fail with a too big duration', function (done) { | ||
413 | const data = { | ||
414 | name: 'my super name', | ||
415 | description: 'my super description', | ||
416 | tags: [ 'tag1', 'tag2' ] | ||
417 | } | ||
418 | const attach = { | ||
419 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_too_long.webm') | ||
420 | } | ||
421 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | ||
422 | }) | ||
423 | |||
424 | it('Should succeed with the correct parameters', function (done) { | ||
425 | const data = { | ||
426 | name: 'my super name', | ||
427 | description: 'my super description', | ||
428 | tags: [ 'tag1', 'tag2' ] | ||
429 | } | ||
430 | const attach = { | ||
431 | 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') | ||
432 | } | ||
433 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { | ||
434 | attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4') | ||
435 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { | ||
436 | attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv') | ||
437 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done, 204) | ||
438 | }, false) | ||
439 | }, false) | ||
440 | }) | ||
441 | }) | ||
442 | |||
443 | describe('When updating a video', function () { | ||
444 | let videoId | ||
445 | |||
446 | before(function (done) { | ||
447 | videosUtils.getVideosList(server.url, function (err, res) { | ||
448 | if (err) throw err | ||
449 | |||
450 | videoId = res.body.data[0].id | ||
451 | |||
452 | return done() | ||
453 | }) | ||
454 | }) | ||
455 | |||
456 | it('Should fail with nothing', function (done) { | ||
457 | const data = {} | ||
458 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
459 | }) | ||
460 | |||
461 | it('Should fail without a valid uuid', function (done) { | ||
462 | const data = { | ||
463 | description: 'my super description', | ||
464 | tags: [ 'tag1', 'tag2' ] | ||
465 | } | ||
466 | requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done) | ||
467 | }) | ||
468 | |||
469 | it('Should fail with an unknown id', function (done) { | ||
470 | const data = { | ||
471 | description: 'my super description', | ||
472 | tags: [ 'tag1', 'tag2' ] | ||
473 | } | ||
474 | requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done) | ||
475 | }) | ||
476 | |||
477 | it('Should fail with a long name', function (done) { | ||
478 | const data = { | ||
479 | name: 'My very very very very very very very very very very very very very very very very long name', | ||
480 | description: 'my super description', | ||
481 | tags: [ 'tag1', 'tag2' ] | ||
482 | } | ||
483 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
484 | }) | ||
485 | |||
486 | it('Should fail with a long description', function (done) { | ||
487 | const data = { | ||
488 | name: 'my super name', | ||
489 | description: 'my super description which is very very very very very very very very very very very very very very' + | ||
490 | 'very very very very very very very very very very very very very very very very very very very very very' + | ||
491 | 'very very very very very very very very very very very very very very very long', | ||
492 | tags: [ 'tag1', 'tag2' ] | ||
493 | } | ||
494 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
495 | }) | ||
496 | |||
497 | it('Should fail with too many tags', function (done) { | ||
498 | const data = { | ||
499 | name: 'my super name', | ||
500 | description: 'my super description', | ||
501 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | ||
502 | } | ||
503 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
504 | }) | ||
505 | |||
506 | it('Should fail with not enough tags', function (done) { | ||
507 | const data = { | ||
508 | name: 'my super name', | ||
509 | description: 'my super description', | ||
510 | tags: [ ] | ||
511 | } | ||
512 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
513 | }) | ||
514 | |||
515 | it('Should fail with a tag length too low', function (done) { | ||
516 | const data = { | ||
517 | name: 'my super name', | ||
518 | description: 'my super description', | ||
519 | tags: [ 'tag1', 't' ] | ||
520 | } | ||
521 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
522 | }) | ||
523 | |||
524 | it('Should fail with a tag length too big', function (done) { | ||
525 | const data = { | ||
526 | name: 'my super name', | ||
527 | description: 'my super description', | ||
528 | tags: [ 'mysupertagtoolong', 'tag1' ] | ||
529 | } | ||
530 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
531 | }) | ||
532 | |||
533 | it('Should fail with malformed tags', function (done) { | ||
534 | const data = { | ||
535 | name: 'my super name', | ||
536 | description: 'my super description', | ||
537 | tags: [ 'my tag' ] | ||
538 | } | ||
539 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | ||
540 | }) | ||
541 | }) | ||
542 | |||
543 | describe('When getting a video', function () { | ||
544 | it('Should return the list of the videos with nothing', function (done) { | ||
545 | request(server.url) | ||
546 | .get(path) | ||
547 | .set('Accept', 'application/json') | ||
548 | .expect(200) | ||
549 | .expect('Content-Type', /json/) | ||
550 | .end(function (err, res) { | ||
551 | if (err) throw err | ||
552 | |||
553 | expect(res.body.data).to.be.an('array') | ||
554 | expect(res.body.data.length).to.equal(3) | ||
555 | |||
556 | done() | ||
557 | }) | ||
558 | }) | ||
559 | |||
560 | it('Should fail without a correct uuid', function (done) { | ||
561 | request(server.url) | ||
562 | .get(path + 'coucou') | ||
563 | .set('Accept', 'application/json') | ||
564 | .expect(400, done) | ||
565 | }) | ||
566 | |||
567 | it('Should return 404 with an incorrect video', function (done) { | ||
568 | request(server.url) | ||
569 | .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06') | ||
570 | .set('Accept', 'application/json') | ||
571 | .expect(404, done) | ||
572 | }) | ||
573 | |||
574 | it('Should succeed with the correct parameters') | ||
575 | }) | ||
576 | |||
577 | describe('When removing a video', function () { | ||
578 | it('Should have 404 with nothing', function (done) { | ||
579 | request(server.url) | ||
580 | .delete(path) | ||
581 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
582 | .expect(400, done) | ||
583 | }) | ||
584 | |||
585 | it('Should fail without a correct uuid', function (done) { | ||
586 | request(server.url) | ||
587 | .delete(path + 'hello') | ||
588 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
589 | .expect(400, done) | ||
590 | }) | ||
591 | |||
592 | it('Should fail with a video which does not exist', function (done) { | ||
593 | request(server.url) | ||
594 | .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06') | ||
595 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
596 | .expect(404, done) | ||
597 | }) | ||
598 | |||
599 | it('Should fail with a video of another user') | ||
600 | |||
601 | it('Should fail with a video of another pod') | ||
602 | |||
603 | it('Should succeed with the correct parameters') | ||
604 | }) | ||
605 | }) | ||
606 | |||
607 | describe('Of the users API', function () { | ||
608 | const path = '/api/v1/users/' | ||
609 | let userId = null | ||
610 | let rootId = null | ||
611 | |||
612 | describe('When listing users', function () { | ||
613 | it('Should fail with a bad start pagination', function (done) { | ||
614 | request(server.url) | ||
615 | .get(path) | ||
616 | .query({ start: 'hello' }) | ||
617 | .set('Accept', 'application/json') | ||
618 | .expect(400, done) | ||
619 | }) | ||
620 | |||
621 | it('Should fail with a bad count pagination', function (done) { | ||
622 | request(server.url) | ||
623 | .get(path) | ||
624 | .query({ count: 'hello' }) | ||
625 | .set('Accept', 'application/json') | ||
626 | .expect(400, done) | ||
627 | }) | ||
628 | |||
629 | it('Should fail with an incorrect sort', function (done) { | ||
630 | request(server.url) | ||
631 | .get(path) | ||
632 | .query({ sort: 'hello' }) | ||
633 | .set('Accept', 'application/json') | ||
634 | .expect(400, done) | ||
635 | }) | ||
636 | }) | ||
637 | |||
638 | describe('When adding a new user', function () { | ||
639 | it('Should fail with a too small username', function (done) { | ||
640 | const data = { | ||
641 | username: 'ji', | ||
642 | password: 'mysuperpassword' | ||
643 | } | ||
644 | |||
645 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
646 | }) | ||
647 | |||
648 | it('Should fail with a too long username', function (done) { | ||
649 | const data = { | ||
650 | username: 'mysuperusernamewhichisverylong', | ||
651 | password: 'mysuperpassword' | ||
652 | } | ||
653 | |||
654 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
655 | }) | ||
656 | |||
657 | it('Should fail with an incorrect username', function (done) { | ||
658 | const data = { | ||
659 | username: 'my username', | ||
660 | password: 'mysuperpassword' | ||
661 | } | ||
662 | |||
663 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
664 | }) | ||
665 | |||
666 | it('Should fail with a too small password', function (done) { | ||
667 | const data = { | ||
668 | username: 'myusername', | ||
669 | password: 'bla' | ||
670 | } | ||
671 | |||
672 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
673 | }) | ||
674 | |||
675 | it('Should fail with a too long password', function (done) { | ||
676 | const data = { | ||
677 | username: 'myusername', | ||
678 | password: 'my super long password which is very very very very very very very very very very very very very very' + | ||
679 | 'very very very very very very very very very very very very very very very veryv very very very very' + | ||
680 | 'very very very very very very very very very very very very very very very very very very very very long' | ||
681 | } | ||
682 | |||
683 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
684 | }) | ||
685 | |||
686 | it('Should fail with an non authenticated user', function (done) { | ||
687 | const data = { | ||
688 | username: 'myusername', | ||
689 | password: 'my super password' | ||
690 | } | ||
691 | |||
692 | requestsUtils.makePostBodyRequest(server.url, path, 'super token', data, done, 401) | ||
693 | }) | ||
694 | |||
695 | it('Should fail if we add a user with the same username', function (done) { | ||
696 | const data = { | ||
697 | username: 'user1', | ||
698 | password: 'my super password' | ||
699 | } | ||
700 | |||
701 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 409) | ||
702 | }) | ||
703 | |||
704 | it('Should succeed with the correct params', function (done) { | ||
705 | const data = { | ||
706 | username: 'user2', | ||
707 | password: 'my super password' | ||
708 | } | ||
709 | |||
710 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204) | ||
711 | }) | ||
712 | |||
713 | it('Should fail with a non admin user', function (done) { | ||
714 | server.user = { | ||
715 | username: 'user1', | ||
716 | password: 'password' | ||
717 | } | ||
718 | |||
719 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { | ||
720 | if (err) throw err | ||
721 | |||
722 | userAccessToken = accessToken | ||
723 | |||
724 | const data = { | ||
725 | username: 'user3', | ||
726 | password: 'my super password' | ||
727 | } | ||
728 | |||
729 | requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403) | ||
730 | }) | ||
731 | }) | ||
732 | }) | ||
733 | |||
734 | describe('When updating a user', function () { | ||
735 | before(function (done) { | ||
736 | usersUtils.getUsersList(server.url, function (err, res) { | ||
737 | if (err) throw err | ||
738 | |||
739 | userId = res.body.data[1].id | ||
740 | rootId = res.body.data[2].id | ||
741 | done() | ||
742 | }) | ||
743 | }) | ||
744 | |||
745 | it('Should fail with a too small password', function (done) { | ||
746 | const data = { | ||
747 | password: 'bla' | ||
748 | } | ||
749 | |||
750 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) | ||
751 | }) | ||
752 | |||
753 | it('Should fail with a too long password', function (done) { | ||
754 | const data = { | ||
755 | password: 'my super long password which is very very very very very very very very very very very very very very' + | ||
756 | 'very very very very very very very very very very very very very very very veryv very very very very' + | ||
757 | 'very very very very very very very very very very very very very very very very very very very very long' | ||
758 | } | ||
759 | |||
760 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) | ||
761 | }) | ||
762 | |||
763 | it('Should fail with an non authenticated user', function (done) { | ||
764 | const data = { | ||
765 | password: 'my super password' | ||
766 | } | ||
767 | |||
768 | requestsUtils.makePutBodyRequest(server.url, path + userId, 'super token', data, done, 401) | ||
769 | }) | ||
770 | |||
771 | it('Should succeed with the correct params', function (done) { | ||
772 | const data = { | ||
773 | password: 'my super password' | ||
774 | } | ||
775 | |||
776 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done, 204) | ||
777 | }) | ||
778 | }) | ||
779 | |||
780 | describe('When getting my information', function () { | ||
781 | it('Should fail with a non authenticated user', function (done) { | ||
782 | request(server.url) | ||
783 | .get(path + 'me') | ||
784 | .set('Authorization', 'Bearer faketoken') | ||
785 | .set('Accept', 'application/json') | ||
786 | .expect(401, done) | ||
787 | }) | ||
788 | |||
789 | it('Should success with the correct parameters', function (done) { | ||
790 | request(server.url) | ||
791 | .get(path + 'me') | ||
792 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
793 | .set('Accept', 'application/json') | ||
794 | .expect(200, done) | ||
795 | }) | ||
796 | }) | ||
797 | |||
798 | describe('When removing an user', function () { | ||
799 | it('Should fail with an incorrect id', function (done) { | ||
800 | request(server.url) | ||
801 | .delete(path + 'bla-bla') | ||
802 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
803 | .expect(400, done) | ||
804 | }) | ||
805 | |||
806 | it('Should fail with the root user', function (done) { | ||
807 | request(server.url) | ||
808 | .delete(path + rootId) | ||
809 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
810 | .expect(400, done) | ||
811 | }) | ||
812 | |||
813 | it('Should return 404 with a non existing id', function (done) { | ||
814 | request(server.url) | ||
815 | .delete(path + '45') | ||
816 | .set('Authorization', 'Bearer ' + server.accessToken) | ||
817 | .expect(404, done) | ||
818 | }) | ||
819 | }) | ||
820 | }) | ||
821 | |||
822 | describe('Of the remote videos API', function () { | ||
823 | describe('When making a secure request', function () { | ||
824 | it('Should check a secure request') | ||
825 | }) | ||
826 | |||
827 | describe('When adding a video', function () { | ||
828 | it('Should check when adding a video') | ||
829 | }) | ||
830 | |||
831 | describe('When removing a video', function () { | ||
832 | it('Should check when removing a video') | ||
833 | }) | ||
834 | }) | ||
835 | |||
836 | describe('Of the requests API', function () { | ||
837 | const path = '/api/v1/requests/stats' | ||
838 | |||
839 | it('Should fail with an non authenticated user', function (done) { | ||
840 | request(server.url) | ||
841 | .get(path) | ||
842 | .set('Accept', 'application/json') | ||
843 | .expect(401, done) | ||
844 | }) | ||
845 | |||
846 | it('Should fail with a non admin user', function (done) { | ||
847 | request(server.url) | ||
848 | .get(path) | ||
849 | .set('Authorization', 'Bearer ' + userAccessToken) | ||
850 | .set('Accept', 'application/json') | ||
851 | .expect(403, done) | ||
852 | }) | ||
853 | }) | ||
854 | |||
855 | after(function (done) { | ||
856 | process.kill(-server.app.pid) | ||
857 | |||
858 | // Keep the logs if the test failed | ||
859 | if (this.ok) { | ||
860 | serversUtils.flushTests(done) | ||
861 | } else { | ||
862 | done() | ||
863 | } | ||
864 | }) | ||
865 | }) | ||
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 | }) | ||
diff --git a/server/tests/utils/login.js b/server/tests/utils/login.js index 465564e14..c984c0baf 100644 --- a/server/tests/utils/login.js +++ b/server/tests/utils/login.js | |||
@@ -4,7 +4,8 @@ const request = require('supertest') | |||
4 | 4 | ||
5 | const loginUtils = { | 5 | const loginUtils = { |
6 | login, | 6 | login, |
7 | loginAndGetAccessToken | 7 | loginAndGetAccessToken, |
8 | getUserAccessToken | ||
8 | } | 9 | } |
9 | 10 | ||
10 | // ---------------------- Export functions -------------------- | 11 | // ---------------------- Export functions -------------------- |
@@ -43,6 +44,14 @@ function loginAndGetAccessToken (server, callback) { | |||
43 | }) | 44 | }) |
44 | } | 45 | } |
45 | 46 | ||
47 | function getUserAccessToken (server, user, callback) { | ||
48 | login(server.url, server.client, user, 200, function (err, res) { | ||
49 | if (err) return callback(err) | ||
50 | |||
51 | return callback(null, res.body.access_token) | ||
52 | }) | ||
53 | } | ||
54 | |||
46 | // --------------------------------------------------------------------------- | 55 | // --------------------------------------------------------------------------- |
47 | 56 | ||
48 | module.exports = loginUtils | 57 | module.exports = loginUtils |
diff --git a/server/tests/utils/servers.js b/server/tests/utils/servers.js index e7c756499..1946ef49a 100644 --- a/server/tests/utils/servers.js +++ b/server/tests/utils/servers.js | |||
@@ -34,7 +34,7 @@ function flushAndRunMultipleServers (totalServers, serversRun) { | |||
34 | runServer(j, function (app, url) { | 34 | runServer(j, function (app, url) { |
35 | anotherServerDone(j, app, url) | 35 | anotherServerDone(j, app, url) |
36 | }) | 36 | }) |
37 | }, 1000 * j) | 37 | }, 1000 * (j - 1)) |
38 | } | 38 | } |
39 | }) | 39 | }) |
40 | } | 40 | } |