]>
Commit | Line | Data |
---|---|---|
0e1dc3e7 | 1 | /* tslint:disable:no-unused-expression */ |
86d13ec2 | 2 | |
0e1dc3e7 | 3 | import * as chai from 'chai' |
afffe988 | 4 | import 'mocha' |
c5d31dba | 5 | import { UserRole } from '../../../../shared/index' |
0e1dc3e7 | 6 | import { |
11ba2ab3 C |
7 | createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoRating, getUserInformation, getUsersList, |
8 | getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo, registerUser, removeUser, removeVideo, | |
9 | runServer, ServerInfo, serverLogin, updateMyUser, updateUser, uploadVideo | |
c5d31dba C |
10 | } from '../../utils/index' |
11 | import { follow } from '../../utils/server/follows' | |
c5d31dba | 12 | import { setAccessTokensToServers } from '../../utils/users/login' |
11ba2ab3 | 13 | import { getMyVideos } from '../../utils/videos/videos' |
0e1dc3e7 | 14 | |
afffe988 C |
15 | const expect = chai.expect |
16 | ||
0e1dc3e7 C |
17 | describe('Test users', function () { |
18 | let server: ServerInfo | |
19 | let accessToken: string | |
20 | let accessTokenUser: string | |
21 | let videoId: number | |
22 | let userId: number | |
23 | ||
24 | before(async function () { | |
572f8d3d | 25 | this.timeout(10000) |
0e1dc3e7 C |
26 | |
27 | await flushTests() | |
28 | server = await runServer(1) | |
86d13ec2 C |
29 | |
30 | await setAccessTokensToServers([ server ]) | |
0e1dc3e7 C |
31 | }) |
32 | ||
33 | it('Should create a new client') | |
34 | ||
35 | it('Should return the first client') | |
36 | ||
37 | it('Should remove the last client') | |
38 | ||
39 | it('Should not login with an invalid client id', async function () { | |
40 | const client = { id: 'client', secret: server.client.secret } | |
41 | const res = await login(server.url, client, server.user, 400) | |
42 | ||
afffe988 C |
43 | expect(res.body.error) |
44 | .to | |
5960f923 | 45 | .equal('Authentication failed.') |
0e1dc3e7 C |
46 | }) |
47 | ||
48 | it('Should not login with an invalid client secret', async function () { | |
49 | const client = { id: server.client.id, secret: 'coucou' } | |
50 | const res = await login(server.url, client, server.user, 400) | |
51 | ||
afffe988 C |
52 | expect(res.body.error) |
53 | .to | |
5960f923 | 54 | .equal('Authentication failed.') |
0e1dc3e7 C |
55 | }) |
56 | ||
57 | it('Should not login with an invalid username', async function () { | |
58 | const user = { username: 'captain crochet', password: server.user.password } | |
59 | const res = await login(server.url, server.client, user, 400) | |
60 | ||
afffe988 C |
61 | expect(res.body.error) |
62 | .to | |
5960f923 | 63 | .equal('Authentication failed.') |
0e1dc3e7 C |
64 | }) |
65 | ||
66 | it('Should not login with an invalid password', async function () { | |
5f04dd2f | 67 | const user = { username: server.user.username, password: 'mew_three' } |
0e1dc3e7 C |
68 | const res = await login(server.url, server.client, user, 400) |
69 | ||
afffe988 C |
70 | expect(res.body.error) |
71 | .to | |
5960f923 | 72 | .equal('Authentication failed.') |
0e1dc3e7 C |
73 | }) |
74 | ||
75 | it('Should not be able to upload a video', async function () { | |
76 | accessToken = 'my_super_token' | |
77 | ||
78 | const videoAttributes = {} | |
79 | await uploadVideo(server.url, accessToken, videoAttributes, 401) | |
80 | }) | |
81 | ||
afffe988 | 82 | it('Should not be able to follow', async function () { |
0e1dc3e7 | 83 | accessToken = 'my_super_token' |
afffe988 | 84 | await follow(server.url, [ 'http://example.com' ], accessToken, 401) |
0e1dc3e7 C |
85 | }) |
86 | ||
afffe988 | 87 | it('Should not be able to unfollow') |
0e1dc3e7 C |
88 | |
89 | it('Should be able to login', async function () { | |
90 | const res = await login(server.url, server.client, server.user, 200) | |
91 | ||
92 | accessToken = res.body.access_token | |
93 | }) | |
94 | ||
95 | it('Should upload the video with the correct token', async function () { | |
96 | const videoAttributes = {} | |
04e0fc48 | 97 | await uploadVideo(server.url, accessToken, videoAttributes) |
0e1dc3e7 | 98 | const res = await getVideosList(server.url) |
afffe988 | 99 | const video = res.body.data[ 0 ] |
0e1dc3e7 | 100 | |
b1fa3eba | 101 | expect(video.accountName) |
afffe988 C |
102 | .to |
103 | .equal('root') | |
0e1dc3e7 C |
104 | videoId = video.id |
105 | }) | |
106 | ||
107 | it('Should upload the video again with the correct token', async function () { | |
108 | const videoAttributes = {} | |
04e0fc48 | 109 | await uploadVideo(server.url, accessToken, videoAttributes) |
0e1dc3e7 C |
110 | }) |
111 | ||
112 | it('Should retrieve a video rating', async function () { | |
113 | await rateVideo(server.url, accessToken, videoId, 'like') | |
26d21b78 | 114 | const res = await getMyUserVideoRating(server.url, accessToken, videoId) |
0e1dc3e7 C |
115 | const rating = res.body |
116 | ||
afffe988 C |
117 | expect(rating.videoId) |
118 | .to | |
119 | .equal(videoId) | |
120 | expect(rating.rating) | |
121 | .to | |
122 | .equal('like') | |
0e1dc3e7 C |
123 | }) |
124 | ||
125 | it('Should not be able to remove the video with an incorrect token', async function () { | |
126 | await removeVideo(server.url, 'bad_token', videoId, 401) | |
127 | }) | |
128 | ||
129 | it('Should not be able to remove the video with the token of another account') | |
130 | ||
131 | it('Should be able to remove the video with the correct token', async function () { | |
132 | await removeVideo(server.url, accessToken, videoId) | |
133 | }) | |
134 | ||
135 | it('Should logout (revoke token)') | |
136 | ||
137 | it('Should not be able to get the user information') | |
138 | ||
139 | it('Should not be able to upload a video') | |
140 | ||
141 | it('Should not be able to remove a video') | |
142 | ||
143 | it('Should not be able to rate a video', async function () { | |
144 | const path = '/api/v1/videos/' | |
145 | const data = { | |
146 | rating: 'likes' | |
147 | } | |
148 | ||
149 | const options = { | |
150 | url: server.url, | |
151 | path: path + videoId, | |
152 | token: 'wrong token', | |
153 | fields: data, | |
154 | statusCodeExpected: 401 | |
155 | } | |
156 | await makePutBodyRequest(options) | |
157 | }) | |
158 | ||
159 | it('Should be able to login again') | |
160 | ||
161 | it('Should have an expired access token') | |
162 | ||
163 | it('Should refresh the token') | |
164 | ||
165 | it('Should be able to upload a video again') | |
166 | ||
167 | it('Should be able to create a new user', async function () { | |
5c98d3bf | 168 | await createUser(server.url, accessToken, 'user_1', 'super password', 2 * 1024 * 1024) |
0e1dc3e7 C |
169 | }) |
170 | ||
171 | it('Should be able to login with this user', async function () { | |
172 | server.user = { | |
173 | username: 'user_1', | |
174 | password: 'super password' | |
175 | } | |
176 | ||
eec63bbc | 177 | accessTokenUser = await serverLogin(server) |
0e1dc3e7 C |
178 | }) |
179 | ||
180 | it('Should be able to get the user information', async function () { | |
5c98d3bf | 181 | const res = await getMyUserInformation(server.url, accessTokenUser) |
0e1dc3e7 C |
182 | const user = res.body |
183 | ||
afffe988 C |
184 | expect(user.username) |
185 | .to | |
186 | .equal('user_1') | |
187 | expect(user.email) | |
188 | .to | |
189 | .equal('user_1@example.com') | |
0e1dc3e7 | 190 | expect(user.displayNSFW).to.be.false |
afffe988 C |
191 | expect(user.videoQuota) |
192 | .to | |
193 | .equal(2 * 1024 * 1024) | |
194 | expect(user.roleLabel) | |
195 | .to | |
196 | .equal('User') | |
197 | expect(user.id) | |
198 | .to | |
199 | .be | |
200 | .a('number') | |
0e1dc3e7 C |
201 | }) |
202 | ||
203 | it('Should be able to upload a video with this user', async function () { | |
204 | this.timeout(5000) | |
205 | ||
11474c3c C |
206 | const videoAttributes = { |
207 | name: 'super user video' | |
208 | } | |
0e1dc3e7 C |
209 | await uploadVideo(server.url, accessTokenUser, videoAttributes) |
210 | }) | |
211 | ||
11474c3c C |
212 | it('Should be able to list my videos', async function () { |
213 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5) | |
afffe988 C |
214 | expect(res.body.total) |
215 | .to | |
216 | .equal(1) | |
11474c3c C |
217 | |
218 | const videos = res.body.data | |
afffe988 C |
219 | expect(videos) |
220 | .to | |
221 | .have | |
222 | .lengthOf(1) | |
11474c3c | 223 | |
afffe988 C |
224 | expect(videos[ 0 ].name) |
225 | .to | |
226 | .equal('super user video') | |
11474c3c C |
227 | }) |
228 | ||
0e1dc3e7 | 229 | it('Should list all the users', async function () { |
86d13ec2 | 230 | const res = await getUsersList(server.url, server.accessToken) |
0e1dc3e7 C |
231 | const result = res.body |
232 | const total = result.total | |
233 | const users = result.data | |
234 | ||
afffe988 C |
235 | expect(total) |
236 | .to | |
237 | .equal(2) | |
238 | expect(users) | |
239 | .to | |
240 | .be | |
241 | .an('array') | |
242 | expect(users.length) | |
243 | .to | |
244 | .equal(2) | |
245 | ||
246 | const user = users[ 0 ] | |
247 | expect(user.username) | |
248 | .to | |
249 | .equal('user_1') | |
250 | expect(user.email) | |
251 | .to | |
252 | .equal('user_1@example.com') | |
0e1dc3e7 C |
253 | expect(user.displayNSFW).to.be.false |
254 | ||
afffe988 C |
255 | const rootUser = users[ 1 ] |
256 | expect(rootUser.username) | |
257 | .to | |
258 | .equal('root') | |
259 | expect(rootUser.email) | |
260 | .to | |
261 | .equal('admin1@example.com') | |
0e1dc3e7 C |
262 | expect(rootUser.displayNSFW).to.be.false |
263 | ||
264 | userId = user.id | |
265 | }) | |
266 | ||
267 | it('Should list only the first user by username asc', async function () { | |
86d13ec2 | 268 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username') |
0e1dc3e7 C |
269 | |
270 | const result = res.body | |
271 | const total = result.total | |
272 | const users = result.data | |
273 | ||
afffe988 C |
274 | expect(total) |
275 | .to | |
276 | .equal(2) | |
277 | expect(users.length) | |
278 | .to | |
279 | .equal(1) | |
280 | ||
281 | const user = users[ 0 ] | |
282 | expect(user.username) | |
283 | .to | |
284 | .equal('root') | |
285 | expect(user.email) | |
286 | .to | |
287 | .equal('admin1@example.com') | |
288 | expect(user.roleLabel) | |
289 | .to | |
290 | .equal('Administrator') | |
0e1dc3e7 C |
291 | expect(user.displayNSFW).to.be.false |
292 | }) | |
293 | ||
294 | it('Should list only the first user by username desc', async function () { | |
86d13ec2 | 295 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username') |
0e1dc3e7 C |
296 | const result = res.body |
297 | const total = result.total | |
298 | const users = result.data | |
299 | ||
afffe988 C |
300 | expect(total) |
301 | .to | |
302 | .equal(2) | |
303 | expect(users.length) | |
304 | .to | |
305 | .equal(1) | |
306 | ||
307 | const user = users[ 0 ] | |
308 | expect(user.username) | |
309 | .to | |
310 | .equal('user_1') | |
311 | expect(user.email) | |
312 | .to | |
313 | .equal('user_1@example.com') | |
0e1dc3e7 C |
314 | expect(user.displayNSFW).to.be.false |
315 | }) | |
316 | ||
317 | it('Should list only the second user by createdAt desc', async function () { | |
86d13ec2 | 318 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt') |
0e1dc3e7 C |
319 | const result = res.body |
320 | const total = result.total | |
321 | const users = result.data | |
322 | ||
afffe988 C |
323 | expect(total) |
324 | .to | |
325 | .equal(2) | |
326 | expect(users.length) | |
327 | .to | |
328 | .equal(1) | |
329 | ||
330 | const user = users[ 0 ] | |
331 | expect(user.username) | |
332 | .to | |
333 | .equal('user_1') | |
334 | expect(user.email) | |
335 | .to | |
336 | .equal('user_1@example.com') | |
0e1dc3e7 C |
337 | expect(user.displayNSFW).to.be.false |
338 | }) | |
339 | ||
340 | it('Should list all the users by createdAt asc', async function () { | |
86d13ec2 | 341 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt') |
0e1dc3e7 C |
342 | const result = res.body |
343 | const total = result.total | |
344 | const users = result.data | |
345 | ||
afffe988 C |
346 | expect(total) |
347 | .to | |
348 | .equal(2) | |
349 | expect(users.length) | |
350 | .to | |
351 | .equal(2) | |
352 | ||
353 | expect(users[ 0 ].username) | |
354 | .to | |
355 | .equal('root') | |
356 | expect(users[ 0 ].email) | |
357 | .to | |
358 | .equal('admin1@example.com') | |
359 | expect(users[ 0 ].displayNSFW).to.be.false | |
360 | ||
361 | expect(users[ 1 ].username) | |
362 | .to | |
363 | .equal('user_1') | |
364 | expect(users[ 1 ].email) | |
365 | .to | |
366 | .equal('user_1@example.com') | |
367 | expect(users[ 1 ].displayNSFW).to.be.false | |
0e1dc3e7 C |
368 | }) |
369 | ||
5c98d3bf | 370 | it('Should update my password', async function () { |
11ba2ab3 C |
371 | await updateMyUser({ |
372 | url: server.url, | |
373 | accessToken: accessTokenUser, | |
374 | newPassword: 'new password' | |
375 | }) | |
0e1dc3e7 C |
376 | server.user.password = 'new password' |
377 | ||
378 | await login(server.url, server.client, server.user, 200) | |
379 | }) | |
380 | ||
381 | it('Should be able to change the NSFW display attribute', async function () { | |
11ba2ab3 C |
382 | await updateMyUser({ |
383 | url: server.url, | |
384 | accessToken: accessTokenUser, | |
385 | displayNSFW: true | |
386 | }) | |
0e1dc3e7 | 387 | |
5c98d3bf | 388 | const res = await getMyUserInformation(server.url, accessTokenUser) |
0e1dc3e7 C |
389 | const user = res.body |
390 | ||
afffe988 C |
391 | expect(user.username) |
392 | .to | |
393 | .equal('user_1') | |
394 | expect(user.email) | |
395 | .to | |
396 | .equal('user_1@example.com') | |
0e1dc3e7 | 397 | expect(user.displayNSFW).to.be.ok |
afffe988 C |
398 | expect(user.videoQuota) |
399 | .to | |
400 | .equal(2 * 1024 * 1024) | |
401 | expect(user.id) | |
402 | .to | |
403 | .be | |
404 | .a('number') | |
5c98d3bf C |
405 | }) |
406 | ||
7efe153b | 407 | it('Should be able to change the autoPlayVideo attribute', async function () { |
11ba2ab3 C |
408 | await updateMyUser({ |
409 | url: server.url, | |
410 | accessToken: accessTokenUser, | |
411 | autoPlayVideo: false | |
412 | }) | |
7efe153b AL |
413 | |
414 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
415 | const user = res.body | |
416 | ||
417 | expect(user.autoPlayVideo).to.be.false | |
418 | }) | |
419 | ||
5c98d3bf | 420 | it('Should be able to change the email display attribute', async function () { |
11ba2ab3 C |
421 | await updateMyUser({ |
422 | url: server.url, | |
423 | accessToken: accessTokenUser, | |
424 | email: 'updated@example.com' | |
425 | }) | |
5c98d3bf C |
426 | |
427 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
428 | const user = res.body | |
429 | ||
afffe988 C |
430 | expect(user.username) |
431 | .to | |
432 | .equal('user_1') | |
433 | expect(user.email) | |
434 | .to | |
435 | .equal('updated@example.com') | |
5c98d3bf | 436 | expect(user.displayNSFW).to.be.ok |
afffe988 C |
437 | expect(user.videoQuota) |
438 | .to | |
439 | .equal(2 * 1024 * 1024) | |
440 | expect(user.id) | |
441 | .to | |
442 | .be | |
443 | .a('number') | |
5c98d3bf C |
444 | }) |
445 | ||
446 | it('Should be able to update another user', async function () { | |
11ba2ab3 C |
447 | await updateUser({ |
448 | url: server.url, | |
449 | userId, | |
450 | accessToken, | |
451 | email: 'updated2@example.com', | |
452 | videoQuota: 42, | |
453 | role: UserRole.MODERATOR | |
454 | }) | |
5c98d3bf | 455 | |
77a5501f | 456 | const res = await getUserInformation(server.url, accessToken, userId) |
5c98d3bf C |
457 | const user = res.body |
458 | ||
afffe988 C |
459 | expect(user.username) |
460 | .to | |
461 | .equal('user_1') | |
462 | expect(user.email) | |
463 | .to | |
464 | .equal('updated2@example.com') | |
5c98d3bf | 465 | expect(user.displayNSFW).to.be.ok |
afffe988 C |
466 | expect(user.videoQuota) |
467 | .to | |
468 | .equal(42) | |
469 | expect(user.roleLabel) | |
470 | .to | |
471 | .equal('Moderator') | |
472 | expect(user.id) | |
473 | .to | |
474 | .be | |
475 | .a('number') | |
0e1dc3e7 C |
476 | }) |
477 | ||
757f0da3 C |
478 | it('Should not be able to delete a user by a moderator', async function () { |
479 | await removeUser(server.url, 2, accessTokenUser, 403) | |
480 | }) | |
481 | ||
482 | it('Should be able to list video blacklist by a moderator', async function () { | |
483 | await getBlacklistedVideosList(server.url, accessTokenUser) | |
484 | }) | |
485 | ||
0e1dc3e7 C |
486 | it('Should be able to remove this user', async function () { |
487 | await removeUser(server.url, userId, accessToken) | |
488 | }) | |
489 | ||
490 | it('Should not be able to login with this user', async function () { | |
491 | // server.user is already set to user 1 | |
492 | await login(server.url, server.client, server.user, 400) | |
493 | }) | |
494 | ||
495 | it('Should not have videos of this user', async function () { | |
496 | const res = await getVideosList(server.url) | |
497 | ||
afffe988 C |
498 | expect(res.body.total) |
499 | .to | |
500 | .equal(1) | |
0e1dc3e7 | 501 | |
afffe988 | 502 | const video = res.body.data[ 0 ] |
b1fa3eba | 503 | expect(video.accountName) |
afffe988 C |
504 | .to |
505 | .equal('root') | |
0e1dc3e7 C |
506 | }) |
507 | ||
508 | it('Should register a new user', async function () { | |
509 | await registerUser(server.url, 'user_15', 'my super password') | |
510 | }) | |
511 | ||
512 | it('Should be able to login with this registered user', async function () { | |
513 | server.user = { | |
514 | username: 'user_15', | |
515 | password: 'my super password' | |
516 | } | |
517 | ||
eec63bbc | 518 | accessToken = await serverLogin(server) |
5c98d3bf C |
519 | }) |
520 | ||
521 | it('Should have the correct video quota', async function () { | |
522 | const res = await getMyUserInformation(server.url, accessToken) | |
523 | const user = res.body | |
524 | ||
afffe988 C |
525 | expect(user.videoQuota) |
526 | .to | |
527 | .equal(5 * 1024 * 1024) | |
0e1dc3e7 C |
528 | }) |
529 | ||
530 | after(async function () { | |
531 | killallServers([ server ]) | |
532 | ||
533 | // Keep the logs if the test failed | |
afffe988 | 534 | if (this[ 'ok' ]) { |
0e1dc3e7 C |
535 | await flushTests() |
536 | } | |
537 | }) | |
538 | }) |