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.js | |
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.js')
-rw-r--r-- | server/tests/api/check-params.js | 865 |
1 files changed, 0 insertions, 865 deletions
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 | }) | ||