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