]>
Commit | Line | Data |
---|---|---|
9f10b292 | 1 | 'use strict' |
34ca3b52 | 2 | |
f0f5567b C |
3 | const chai = require('chai') |
4 | const expect = chai.expect | |
5 | const pathUtils = require('path') | |
6 | const request = require('supertest') | |
1a42c9e2 | 7 | const series = require('async/series') |
34ca3b52 | 8 | |
8d309058 | 9 | const loginUtils = require('../utils/login') |
25ed57f3 | 10 | const requestsUtils = require('../utils/requests') |
8d309058 C |
11 | const serversUtils = require('../utils/servers') |
12 | const usersUtils = require('../utils/users') | |
34ca3b52 | 13 | |
9f10b292 | 14 | describe('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 |
af1068ce | 500 | let rootId = null |
9bd26629 | 501 | |
5c39adb7 C |
502 | describe('When listing users', function () { |
503 | it('Should fail with a bad start pagination', function (done) { | |
504 | request(server.url) | |
505 | .get(path) | |
506 | .query({ start: 'hello' }) | |
507 | .set('Accept', 'application/json') | |
508 | .expect(400, done) | |
509 | }) | |
510 | ||
511 | it('Should fail with a bad count pagination', function (done) { | |
512 | request(server.url) | |
513 | .get(path) | |
514 | .query({ count: 'hello' }) | |
515 | .set('Accept', 'application/json') | |
516 | .expect(400, done) | |
517 | }) | |
518 | ||
519 | it('Should fail with an incorrect sort', function (done) { | |
520 | request(server.url) | |
521 | .get(path) | |
522 | .query({ sort: 'hello' }) | |
523 | .set('Accept', 'application/json') | |
524 | .expect(400, done) | |
525 | }) | |
526 | }) | |
527 | ||
9bd26629 C |
528 | describe('When adding a new user', function () { |
529 | it('Should fail with a too small username', function (done) { | |
530 | const data = { | |
531 | username: 'ji', | |
532 | password: 'mysuperpassword' | |
533 | } | |
534 | ||
25ed57f3 | 535 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
9bd26629 C |
536 | }) |
537 | ||
538 | it('Should fail with a too long username', function (done) { | |
539 | const data = { | |
540 | username: 'mysuperusernamewhichisverylong', | |
541 | password: 'mysuperpassword' | |
542 | } | |
543 | ||
25ed57f3 | 544 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
9bd26629 C |
545 | }) |
546 | ||
547 | it('Should fail with an incorrect username', function (done) { | |
548 | const data = { | |
549 | username: 'my username', | |
550 | password: 'mysuperpassword' | |
551 | } | |
552 | ||
25ed57f3 | 553 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
9bd26629 C |
554 | }) |
555 | ||
556 | it('Should fail with a too small password', function (done) { | |
557 | const data = { | |
558 | username: 'myusername', | |
559 | password: 'bla' | |
560 | } | |
561 | ||
25ed57f3 | 562 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
9bd26629 C |
563 | }) |
564 | ||
565 | it('Should fail with a too long password', function (done) { | |
566 | const data = { | |
567 | username: 'myusername', | |
568 | password: 'my super long password which is very very very very very very very very very very very very very very' + | |
569 | 'very very very very very very very very very very very very very very very veryv very very very very' + | |
570 | 'very very very very very very very very very very very very very very very very very very very very long' | |
571 | } | |
572 | ||
25ed57f3 | 573 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
9bd26629 C |
574 | }) |
575 | ||
576 | it('Should fail with an non authenticated user', function (done) { | |
577 | const data = { | |
578 | username: 'myusername', | |
579 | password: 'my super password' | |
580 | } | |
581 | ||
25ed57f3 | 582 | requestsUtils.makePostBodyRequest(server.url, path, 'super token', data, done, 401) |
9bd26629 C |
583 | }) |
584 | ||
327680c9 | 585 | it('Should fail if we add a user with the same username', function (done) { |
9bd26629 C |
586 | const data = { |
587 | username: 'user1', | |
588 | password: 'my super password' | |
589 | } | |
590 | ||
327680c9 | 591 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 409) |
9bd26629 C |
592 | }) |
593 | ||
327680c9 C |
594 | it('Should succeed with the correct params', function (done) { |
595 | const data = { | |
596 | username: 'user2', | |
597 | password: 'my super password' | |
598 | } | |
bf68dd75 | 599 | |
327680c9 | 600 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204) |
bf68dd75 C |
601 | }) |
602 | ||
9bd26629 C |
603 | it('Should fail with a non admin user', function (done) { |
604 | server.user = { | |
605 | username: 'user1', | |
327680c9 | 606 | password: 'password' |
9bd26629 C |
607 | } |
608 | ||
8d309058 | 609 | loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { |
9bd26629 C |
610 | if (err) throw err |
611 | ||
99a64bfe C |
612 | userAccessToken = accessToken |
613 | ||
9bd26629 | 614 | const data = { |
327680c9 | 615 | username: 'user3', |
9bd26629 C |
616 | password: 'my super password' |
617 | } | |
618 | ||
25ed57f3 | 619 | requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403) |
9bd26629 C |
620 | }) |
621 | }) | |
622 | }) | |
623 | ||
624 | describe('When updating a user', function () { | |
9bd26629 | 625 | before(function (done) { |
8d309058 | 626 | usersUtils.getUsersList(server.url, function (err, res) { |
9bd26629 C |
627 | if (err) throw err |
628 | ||
629 | userId = res.body.data[1].id | |
af1068ce | 630 | rootId = res.body.data[2].id |
9bd26629 C |
631 | done() |
632 | }) | |
633 | }) | |
634 | ||
635 | it('Should fail with a too small password', function (done) { | |
636 | const data = { | |
637 | password: 'bla' | |
638 | } | |
639 | ||
25ed57f3 | 640 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) |
9bd26629 C |
641 | }) |
642 | ||
643 | it('Should fail with a too long password', function (done) { | |
644 | const data = { | |
645 | password: 'my super long password which is very very very very very very very very very very very very very very' + | |
646 | 'very very very very very very very very very very very very very very very veryv very very very very' + | |
647 | 'very very very very very very very very very very very very very very very very very very very very long' | |
648 | } | |
649 | ||
25ed57f3 | 650 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) |
9bd26629 C |
651 | }) |
652 | ||
653 | it('Should fail with an non authenticated user', function (done) { | |
654 | const data = { | |
655 | password: 'my super password' | |
656 | } | |
657 | ||
25ed57f3 | 658 | requestsUtils.makePutBodyRequest(server.url, path + userId, 'super token', data, done, 401) |
9bd26629 C |
659 | }) |
660 | ||
661 | it('Should succeed with the correct params', function (done) { | |
662 | const data = { | |
663 | password: 'my super password' | |
664 | } | |
665 | ||
25ed57f3 | 666 | requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done, 204) |
99a64bfe C |
667 | }) |
668 | }) | |
669 | ||
670 | describe('When getting my information', function () { | |
671 | it('Should fail with a non authenticated user', function (done) { | |
672 | request(server.url) | |
673 | .get(path + 'me') | |
674 | .set('Authorization', 'Bearer faketoken') | |
675 | .set('Accept', 'application/json') | |
676 | .expect(401, done) | |
677 | }) | |
678 | ||
679 | it('Should success with the correct parameters', function (done) { | |
680 | request(server.url) | |
681 | .get(path + 'me') | |
682 | .set('Authorization', 'Bearer ' + userAccessToken) | |
683 | .set('Accept', 'application/json') | |
684 | .expect(200, done) | |
9bd26629 C |
685 | }) |
686 | }) | |
687 | ||
688 | describe('When removing an user', function () { | |
68a3b9f2 | 689 | it('Should fail with an incorrect id', function (done) { |
9bd26629 C |
690 | request(server.url) |
691 | .delete(path + 'bla-bla') | |
692 | .set('Authorization', 'Bearer ' + server.accessToken) | |
693 | .expect(400, done) | |
694 | }) | |
695 | ||
af1068ce C |
696 | it('Should fail with the root user', function (done) { |
697 | request(server.url) | |
698 | .delete(path + rootId) | |
699 | .set('Authorization', 'Bearer ' + server.accessToken) | |
700 | .expect(400, done) | |
701 | }) | |
702 | ||
68a3b9f2 | 703 | it('Should return 404 with a non existing id', function (done) { |
9bd26629 | 704 | request(server.url) |
68a3b9f2 | 705 | .delete(path + '579f982228c99c221d8092b8') |
9bd26629 C |
706 | .set('Authorization', 'Bearer ' + server.accessToken) |
707 | .expect(404, done) | |
708 | }) | |
9bd26629 C |
709 | }) |
710 | }) | |
711 | ||
9f10b292 C |
712 | describe('Of the remote videos API', function () { |
713 | describe('When making a secure request', function () { | |
714 | it('Should check a secure request') | |
715 | }) | |
34ca3b52 | 716 | |
9f10b292 C |
717 | describe('When adding a video', function () { |
718 | it('Should check when adding a video') | |
34ca3b52 | 719 | }) |
9f10b292 C |
720 | |
721 | describe('When removing a video', function () { | |
722 | it('Should check when removing a video') | |
723 | }) | |
724 | }) | |
725 | ||
d3cd34be C |
726 | describe('Of the requests API', function () { |
727 | const path = '/api/v1/requests/stats' | |
728 | ||
729 | it('Should fail with an non authenticated user', function (done) { | |
730 | request(server.url) | |
731 | .get(path) | |
732 | .set('Accept', 'application/json') | |
733 | .expect(401, done) | |
734 | }) | |
735 | ||
736 | it('Should fail with a non admin user', function (done) { | |
737 | request(server.url) | |
738 | .get(path) | |
739 | .set('Authorization', 'Bearer ' + userAccessToken) | |
740 | .set('Accept', 'application/json') | |
741 | .expect(403, done) | |
742 | }) | |
743 | }) | |
744 | ||
9f10b292 | 745 | after(function (done) { |
0c1cbbfe | 746 | process.kill(-server.app.pid) |
9f10b292 C |
747 | |
748 | // Keep the logs if the test failed | |
749 | if (this.ok) { | |
8d309058 | 750 | serversUtils.flushTests(done) |
9f10b292 C |
751 | } else { |
752 | done() | |
753 | } | |
34ca3b52 | 754 | }) |
9f10b292 | 755 | }) |