]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import { omit } from 'lodash' | |
4 | import 'mocha' | |
5 | import { join } from 'path' | |
6 | import { UserRole, VideoImport, VideoImportState } from '../../../../shared' | |
7 | ||
8 | import { | |
9 | createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest, | |
10 | makePostBodyRequest, makeUploadRequest, makePutBodyRequest, registerUser, removeUser, runServer, ServerInfo, setAccessTokensToServers, | |
11 | updateUser, uploadVideo, userLogin, deleteMe, unblockUser, blockUser | |
12 | } from '../../../../shared/extra-utils' | |
13 | import { | |
14 | checkBadCountPagination, | |
15 | checkBadSortPagination, | |
16 | checkBadStartPagination | |
17 | } from '../../../../shared/extra-utils/requests/check-api-params' | |
18 | import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' | |
19 | import { VideoPrivacy } from '../../../../shared/models/videos' | |
20 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
21 | import { expect } from 'chai' | |
22 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | |
23 | ||
24 | describe('Test users API validators', function () { | |
25 | const path = '/api/v1/users/' | |
26 | let userId: number | |
27 | let rootId: number | |
28 | let videoId: number | |
29 | let server: ServerInfo | |
30 | let serverWithRegistrationDisabled: ServerInfo | |
31 | let userAccessToken = '' | |
32 | let channelId: number | |
33 | const user = { | |
34 | username: 'user1', | |
35 | password: 'my super password' | |
36 | } | |
37 | ||
38 | // --------------------------------------------------------------- | |
39 | ||
40 | before(async function () { | |
41 | this.timeout(30000) | |
42 | ||
43 | await flushTests() | |
44 | ||
45 | server = await runServer(1) | |
46 | serverWithRegistrationDisabled = await runServer(2) | |
47 | ||
48 | await setAccessTokensToServers([ server ]) | |
49 | ||
50 | const videoQuota = 42000000 | |
51 | await createUser({ | |
52 | url: server.url, | |
53 | accessToken: server.accessToken, | |
54 | username: user.username, | |
55 | password: user.password, | |
56 | videoQuota: videoQuota | |
57 | }) | |
58 | userAccessToken = await userLogin(server, user) | |
59 | ||
60 | { | |
61 | const res = await getMyUserInformation(server.url, server.accessToken) | |
62 | channelId = res.body.videoChannels[ 0 ].id | |
63 | } | |
64 | ||
65 | { | |
66 | const res = await uploadVideo(server.url, server.accessToken, {}) | |
67 | videoId = res.body.video.id | |
68 | } | |
69 | }) | |
70 | ||
71 | describe('When listing users', function () { | |
72 | it('Should fail with a bad start pagination', async function () { | |
73 | await checkBadStartPagination(server.url, path, server.accessToken) | |
74 | }) | |
75 | ||
76 | it('Should fail with a bad count pagination', async function () { | |
77 | await checkBadCountPagination(server.url, path, server.accessToken) | |
78 | }) | |
79 | ||
80 | it('Should fail with an incorrect sort', async function () { | |
81 | await checkBadSortPagination(server.url, path, server.accessToken) | |
82 | }) | |
83 | ||
84 | it('Should fail with a non authenticated user', async function () { | |
85 | await makeGetRequest({ | |
86 | url: server.url, | |
87 | path, | |
88 | statusCodeExpected: 401 | |
89 | }) | |
90 | }) | |
91 | ||
92 | it('Should fail with a non admin user', async function () { | |
93 | await makeGetRequest({ | |
94 | url: server.url, | |
95 | path, | |
96 | token: userAccessToken, | |
97 | statusCodeExpected: 403 | |
98 | }) | |
99 | }) | |
100 | }) | |
101 | ||
102 | describe('When adding a new user', function () { | |
103 | const baseCorrectParams = { | |
104 | username: 'user2', | |
105 | email: 'test@example.com', | |
106 | password: 'my super password', | |
107 | videoQuota: -1, | |
108 | videoQuotaDaily: -1, | |
109 | role: UserRole.USER, | |
110 | adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST | |
111 | } | |
112 | ||
113 | it('Should fail with a too small username', async function () { | |
114 | const fields = immutableAssign(baseCorrectParams, { username: '' }) | |
115 | ||
116 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
117 | }) | |
118 | ||
119 | it('Should fail with a too long username', async function () { | |
120 | const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) | |
121 | ||
122 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
123 | }) | |
124 | ||
125 | it('Should fail with a not lowercase username', async function () { | |
126 | const fields = immutableAssign(baseCorrectParams, { username: 'Toto' }) | |
127 | ||
128 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
129 | }) | |
130 | ||
131 | it('Should fail with an incorrect username', async function () { | |
132 | const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) | |
133 | ||
134 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
135 | }) | |
136 | ||
137 | it('Should fail with a missing email', async function () { | |
138 | const fields = omit(baseCorrectParams, 'email') | |
139 | ||
140 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
141 | }) | |
142 | ||
143 | it('Should fail with an invalid email', async function () { | |
144 | const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) | |
145 | ||
146 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
147 | }) | |
148 | ||
149 | it('Should fail with a too small password', async function () { | |
150 | const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) | |
151 | ||
152 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
153 | }) | |
154 | ||
155 | it('Should fail with a too long password', async function () { | |
156 | const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) | |
157 | ||
158 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
159 | }) | |
160 | ||
161 | it('Should fail with invalid admin flags', async function () { | |
162 | const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' }) | |
163 | ||
164 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
165 | }) | |
166 | ||
167 | it('Should fail with an non authenticated user', async function () { | |
168 | await makePostBodyRequest({ | |
169 | url: server.url, | |
170 | path, | |
171 | token: 'super token', | |
172 | fields: baseCorrectParams, | |
173 | statusCodeExpected: 401 | |
174 | }) | |
175 | }) | |
176 | ||
177 | it('Should fail if we add a user with the same username', async function () { | |
178 | const fields = immutableAssign(baseCorrectParams, { username: 'user1' }) | |
179 | ||
180 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) | |
181 | }) | |
182 | ||
183 | it('Should fail if we add a user with the same email', async function () { | |
184 | const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' }) | |
185 | ||
186 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) | |
187 | }) | |
188 | ||
189 | it('Should fail without a videoQuota', async function () { | |
190 | const fields = omit(baseCorrectParams, 'videoQuota') | |
191 | ||
192 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
193 | }) | |
194 | ||
195 | it('Should fail without a videoQuotaDaily', async function () { | |
196 | const fields = omit(baseCorrectParams, 'videoQuotaDaily') | |
197 | ||
198 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
199 | }) | |
200 | ||
201 | it('Should fail with an invalid videoQuota', async function () { | |
202 | const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 }) | |
203 | ||
204 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
205 | }) | |
206 | ||
207 | it('Should fail with an invalid videoQuotaDaily', async function () { | |
208 | const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 }) | |
209 | ||
210 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
211 | }) | |
212 | ||
213 | it('Should fail without a user role', async function () { | |
214 | const fields = omit(baseCorrectParams, 'role') | |
215 | ||
216 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
217 | }) | |
218 | ||
219 | it('Should fail with an invalid user role', async function () { | |
220 | const fields = immutableAssign(baseCorrectParams, { role: 88989 }) | |
221 | ||
222 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
223 | }) | |
224 | ||
225 | it('Should fail with a "peertube" username', async function () { | |
226 | const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) | |
227 | ||
228 | await makePostBodyRequest({ | |
229 | url: server.url, | |
230 | path, | |
231 | token: server.accessToken, | |
232 | fields, | |
233 | statusCodeExpected: 409 | |
234 | }) | |
235 | }) | |
236 | ||
237 | it('Should succeed with the correct params', async function () { | |
238 | await makePostBodyRequest({ | |
239 | url: server.url, | |
240 | path, | |
241 | token: server.accessToken, | |
242 | fields: baseCorrectParams, | |
243 | statusCodeExpected: 200 | |
244 | }) | |
245 | }) | |
246 | ||
247 | it('Should fail with a non admin user', async function () { | |
248 | const user = { | |
249 | username: 'user1', | |
250 | password: 'my super password' | |
251 | } | |
252 | userAccessToken = await userLogin(server, user) | |
253 | ||
254 | const fields = { | |
255 | username: 'user3', | |
256 | email: 'test@example.com', | |
257 | password: 'my super password', | |
258 | videoQuota: 42000000 | |
259 | } | |
260 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) | |
261 | }) | |
262 | }) | |
263 | ||
264 | describe('When updating my account', function () { | |
265 | it('Should fail with an invalid email attribute', async function () { | |
266 | const fields = { | |
267 | email: 'blabla' | |
268 | } | |
269 | ||
270 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields }) | |
271 | }) | |
272 | ||
273 | it('Should fail with a too small password', async function () { | |
274 | const fields = { | |
275 | currentPassword: 'my super password', | |
276 | password: 'bla' | |
277 | } | |
278 | ||
279 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
280 | }) | |
281 | ||
282 | it('Should fail with a too long password', async function () { | |
283 | const fields = { | |
284 | currentPassword: 'my super password', | |
285 | password: 'super'.repeat(61) | |
286 | } | |
287 | ||
288 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
289 | }) | |
290 | ||
291 | it('Should fail without the current password', async function () { | |
292 | const fields = { | |
293 | currentPassword: 'my super password', | |
294 | password: 'super'.repeat(61) | |
295 | } | |
296 | ||
297 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
298 | }) | |
299 | ||
300 | it('Should fail with an invalid current password', async function () { | |
301 | const fields = { | |
302 | currentPassword: 'my super password fail', | |
303 | password: 'super'.repeat(61) | |
304 | } | |
305 | ||
306 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 401 }) | |
307 | }) | |
308 | ||
309 | it('Should fail with an invalid NSFW policy attribute', async function () { | |
310 | const fields = { | |
311 | nsfwPolicy: 'hello' | |
312 | } | |
313 | ||
314 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
315 | }) | |
316 | ||
317 | it('Should fail with an invalid autoPlayVideo attribute', async function () { | |
318 | const fields = { | |
319 | autoPlayVideo: -1 | |
320 | } | |
321 | ||
322 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
323 | }) | |
324 | ||
325 | it('Should fail with an invalid videosHistoryEnabled attribute', async function () { | |
326 | const fields = { | |
327 | videosHistoryEnabled: -1 | |
328 | } | |
329 | ||
330 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
331 | }) | |
332 | ||
333 | it('Should fail with an non authenticated user', async function () { | |
334 | const fields = { | |
335 | currentPassword: 'my super password', | |
336 | password: 'my super password' | |
337 | } | |
338 | ||
339 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 }) | |
340 | }) | |
341 | ||
342 | it('Should fail with a too long description', async function () { | |
343 | const fields = { | |
344 | description: 'super'.repeat(201) | |
345 | } | |
346 | ||
347 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | |
348 | }) | |
349 | ||
350 | it('Should succeed to change password with the correct params', async function () { | |
351 | const fields = { | |
352 | currentPassword: 'my super password', | |
353 | password: 'my super password', | |
354 | nsfwPolicy: 'blur', | |
355 | autoPlayVideo: false, | |
356 | email: 'super_email@example.com' | |
357 | } | |
358 | ||
359 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) | |
360 | }) | |
361 | ||
362 | it('Should succeed without password change with the correct params', async function () { | |
363 | const fields = { | |
364 | nsfwPolicy: 'blur', | |
365 | autoPlayVideo: false, | |
366 | email: 'super_email@example.com' | |
367 | } | |
368 | ||
369 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) | |
370 | }) | |
371 | }) | |
372 | ||
373 | describe('When updating my avatar', function () { | |
374 | it('Should fail without an incorrect input file', async function () { | |
375 | const fields = {} | |
376 | const attaches = { | |
377 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') | |
378 | } | |
379 | await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) | |
380 | }) | |
381 | ||
382 | it('Should fail with a big file', async function () { | |
383 | const fields = {} | |
384 | const attaches = { | |
385 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') | |
386 | } | |
387 | await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) | |
388 | }) | |
389 | ||
390 | it('Should fail with an unauthenticated user', async function () { | |
391 | const fields = {} | |
392 | const attaches = { | |
393 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') | |
394 | } | |
395 | await makeUploadRequest({ | |
396 | url: server.url, | |
397 | path: path + '/me/avatar/pick', | |
398 | fields, | |
399 | attaches, | |
400 | statusCodeExpected: 401 | |
401 | }) | |
402 | }) | |
403 | ||
404 | it('Should succeed with the correct params', async function () { | |
405 | const fields = {} | |
406 | const attaches = { | |
407 | 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') | |
408 | } | |
409 | await makeUploadRequest({ | |
410 | url: server.url, | |
411 | path: path + '/me/avatar/pick', | |
412 | token: server.accessToken, | |
413 | fields, | |
414 | attaches, | |
415 | statusCodeExpected: 200 | |
416 | }) | |
417 | }) | |
418 | }) | |
419 | ||
420 | describe('When getting a user', function () { | |
421 | before(async function () { | |
422 | const res = await getUsersList(server.url, server.accessToken) | |
423 | ||
424 | userId = res.body.data[1].id | |
425 | }) | |
426 | ||
427 | it('Should fail with an non authenticated user', async function () { | |
428 | await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 }) | |
429 | }) | |
430 | ||
431 | it('Should fail with a non admin user', async function () { | |
432 | await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 }) | |
433 | }) | |
434 | ||
435 | it('Should succeed with the correct params', async function () { | |
436 | await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 }) | |
437 | }) | |
438 | }) | |
439 | ||
440 | describe('When updating a user', function () { | |
441 | ||
442 | before(async function () { | |
443 | const res = await getUsersList(server.url, server.accessToken) | |
444 | ||
445 | userId = res.body.data[1].id | |
446 | rootId = res.body.data[2].id | |
447 | }) | |
448 | ||
449 | it('Should fail with an invalid email attribute', async function () { | |
450 | const fields = { | |
451 | email: 'blabla' | |
452 | } | |
453 | ||
454 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
455 | }) | |
456 | ||
457 | it('Should fail with an invalid emailVerified attribute', async function () { | |
458 | const fields = { | |
459 | emailVerified: 'yes' | |
460 | } | |
461 | ||
462 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
463 | }) | |
464 | ||
465 | it('Should fail with an invalid videoQuota attribute', async function () { | |
466 | const fields = { | |
467 | videoQuota: -90 | |
468 | } | |
469 | ||
470 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
471 | }) | |
472 | ||
473 | it('Should fail with an invalid user role attribute', async function () { | |
474 | const fields = { | |
475 | role: 54878 | |
476 | } | |
477 | ||
478 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
479 | }) | |
480 | ||
481 | it('Should fail with a too small password', async function () { | |
482 | const fields = { | |
483 | currentPassword: 'my super password', | |
484 | password: 'bla' | |
485 | } | |
486 | ||
487 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
488 | }) | |
489 | ||
490 | it('Should fail with a too long password', async function () { | |
491 | const fields = { | |
492 | currentPassword: 'my super password', | |
493 | password: 'super'.repeat(61) | |
494 | } | |
495 | ||
496 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) | |
497 | }) | |
498 | ||
499 | it('Should fail with an non authenticated user', async function () { | |
500 | const fields = { | |
501 | videoQuota: 42 | |
502 | } | |
503 | ||
504 | await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 }) | |
505 | }) | |
506 | ||
507 | it('Should fail when updating root role', async function () { | |
508 | const fields = { | |
509 | role: UserRole.MODERATOR | |
510 | } | |
511 | ||
512 | await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields }) | |
513 | }) | |
514 | ||
515 | it('Should fail with invalid admin flags', async function () { | |
516 | const fields = { adminFlags: 'toto' } | |
517 | ||
518 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
519 | }) | |
520 | ||
521 | it('Should succeed with the correct params', async function () { | |
522 | const fields = { | |
523 | email: 'email@example.com', | |
524 | emailVerified: true, | |
525 | videoQuota: 42, | |
526 | role: UserRole.USER | |
527 | } | |
528 | ||
529 | await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
530 | }) | |
531 | }) | |
532 | ||
533 | describe('When getting my information', function () { | |
534 | it('Should fail with a non authenticated user', async function () { | |
535 | await getMyUserInformation(server.url, 'fake_token', 401) | |
536 | }) | |
537 | ||
538 | it('Should success with the correct parameters', async function () { | |
539 | await getMyUserInformation(server.url, userAccessToken) | |
540 | }) | |
541 | }) | |
542 | ||
543 | describe('When getting my video rating', function () { | |
544 | it('Should fail with a non authenticated user', async function () { | |
545 | await getMyUserVideoRating(server.url, 'fake_token', videoId, 401) | |
546 | }) | |
547 | ||
548 | it('Should fail with an incorrect video uuid', async function () { | |
549 | await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400) | |
550 | }) | |
551 | ||
552 | it('Should fail with an unknown video', async function () { | |
553 | await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) | |
554 | }) | |
555 | ||
556 | it('Should succeed with the correct parameters', async function () { | |
557 | await getMyUserVideoRating(server.url, server.accessToken, videoId) | |
558 | }) | |
559 | }) | |
560 | ||
561 | describe('When retrieving my global ratings', function () { | |
562 | const path = '/api/v1/accounts/user1/ratings' | |
563 | ||
564 | it('Should fail with a bad start pagination', async function () { | |
565 | await checkBadStartPagination(server.url, path, userAccessToken) | |
566 | }) | |
567 | ||
568 | it('Should fail with a bad count pagination', async function () { | |
569 | await checkBadCountPagination(server.url, path, userAccessToken) | |
570 | }) | |
571 | ||
572 | it('Should fail with an incorrect sort', async function () { | |
573 | await checkBadSortPagination(server.url, path, userAccessToken) | |
574 | }) | |
575 | ||
576 | it('Should fail with a unauthenticated user', async function () { | |
577 | await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 }) | |
578 | }) | |
579 | ||
580 | it('Should fail with a another user', async function () { | |
581 | await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 }) | |
582 | }) | |
583 | ||
584 | it('Should fail with a bad type', async function () { | |
585 | await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 }) | |
586 | }) | |
587 | ||
588 | it('Should succeed with the correct params', async function () { | |
589 | await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 }) | |
590 | }) | |
591 | }) | |
592 | ||
593 | describe('When blocking/unblocking/removing user', function () { | |
594 | it('Should fail with an incorrect id', async function () { | |
595 | await removeUser(server.url, 'blabla', server.accessToken, 400) | |
596 | await blockUser(server.url, 'blabla', server.accessToken, 400) | |
597 | await unblockUser(server.url, 'blabla', server.accessToken, 400) | |
598 | }) | |
599 | ||
600 | it('Should fail with the root user', async function () { | |
601 | await removeUser(server.url, rootId, server.accessToken, 400) | |
602 | await blockUser(server.url, rootId, server.accessToken, 400) | |
603 | await unblockUser(server.url, rootId, server.accessToken, 400) | |
604 | }) | |
605 | ||
606 | it('Should return 404 with a non existing id', async function () { | |
607 | await removeUser(server.url, 4545454, server.accessToken, 404) | |
608 | await blockUser(server.url, 4545454, server.accessToken, 404) | |
609 | await unblockUser(server.url, 4545454, server.accessToken, 404) | |
610 | }) | |
611 | ||
612 | it('Should fail with a non admin user', async function () { | |
613 | await removeUser(server.url, userId, userAccessToken, 403) | |
614 | await blockUser(server.url, userId, userAccessToken, 403) | |
615 | await unblockUser(server.url, userId, userAccessToken, 403) | |
616 | }) | |
617 | }) | |
618 | ||
619 | describe('When deleting our account', function () { | |
620 | it('Should fail with with the root account', async function () { | |
621 | await deleteMe(server.url, server.accessToken, 400) | |
622 | }) | |
623 | }) | |
624 | ||
625 | describe('When register a new user', function () { | |
626 | const registrationPath = path + '/register' | |
627 | const baseCorrectParams = { | |
628 | username: 'user3', | |
629 | email: 'test3@example.com', | |
630 | password: 'my super password' | |
631 | } | |
632 | ||
633 | it('Should fail with a too small username', async function () { | |
634 | const fields = immutableAssign(baseCorrectParams, { username: '' }) | |
635 | ||
636 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
637 | }) | |
638 | ||
639 | it('Should fail with a too long username', async function () { | |
640 | const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) | |
641 | ||
642 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
643 | }) | |
644 | ||
645 | it('Should fail with an incorrect username', async function () { | |
646 | const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) | |
647 | ||
648 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
649 | }) | |
650 | ||
651 | it('Should fail with a missing email', async function () { | |
652 | const fields = omit(baseCorrectParams, 'email') | |
653 | ||
654 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
655 | }) | |
656 | ||
657 | it('Should fail with an invalid email', async function () { | |
658 | const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) | |
659 | ||
660 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
661 | }) | |
662 | ||
663 | it('Should fail with a too small password', async function () { | |
664 | const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) | |
665 | ||
666 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
667 | }) | |
668 | ||
669 | it('Should fail with a too long password', async function () { | |
670 | const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) | |
671 | ||
672 | await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) | |
673 | }) | |
674 | ||
675 | it('Should fail if we register a user with the same username', async function () { | |
676 | const fields = immutableAssign(baseCorrectParams, { username: 'root' }) | |
677 | ||
678 | await makePostBodyRequest({ | |
679 | url: server.url, | |
680 | path: registrationPath, | |
681 | token: server.accessToken, | |
682 | fields, | |
683 | statusCodeExpected: 409 | |
684 | }) | |
685 | }) | |
686 | ||
687 | it('Should fail with a "peertube" username', async function () { | |
688 | const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) | |
689 | ||
690 | await makePostBodyRequest({ | |
691 | url: server.url, | |
692 | path: registrationPath, | |
693 | token: server.accessToken, | |
694 | fields, | |
695 | statusCodeExpected: 409 | |
696 | }) | |
697 | }) | |
698 | ||
699 | it('Should fail if we register a user with the same email', async function () { | |
700 | const fields = immutableAssign(baseCorrectParams, { email: 'admin1@example.com' }) | |
701 | ||
702 | await makePostBodyRequest({ | |
703 | url: server.url, | |
704 | path: registrationPath, | |
705 | token: server.accessToken, | |
706 | fields, | |
707 | statusCodeExpected: 409 | |
708 | }) | |
709 | }) | |
710 | ||
711 | it('Should succeed with the correct params', async function () { | |
712 | await makePostBodyRequest({ | |
713 | url: server.url, | |
714 | path: registrationPath, | |
715 | token: server.accessToken, | |
716 | fields: baseCorrectParams, | |
717 | statusCodeExpected: 204 | |
718 | }) | |
719 | }) | |
720 | ||
721 | it('Should fail on a server with registration disabled', async function () { | |
722 | const fields = { | |
723 | username: 'user4', | |
724 | email: 'test4@example.com', | |
725 | password: 'my super password 4' | |
726 | } | |
727 | ||
728 | await makePostBodyRequest({ | |
729 | url: serverWithRegistrationDisabled.url, | |
730 | path: registrationPath, | |
731 | token: serverWithRegistrationDisabled.accessToken, | |
732 | fields, | |
733 | statusCodeExpected: 403 | |
734 | }) | |
735 | }) | |
736 | }) | |
737 | ||
738 | describe('When registering multiple users on a server with users limit', function () { | |
739 | it('Should fail when after 3 registrations', async function () { | |
740 | await registerUser(server.url, 'user42', 'super password', 403) | |
741 | }) | |
742 | }) | |
743 | ||
744 | describe('When having a video quota', function () { | |
745 | it('Should fail with a user having too many videos', async function () { | |
746 | await updateUser({ | |
747 | url: server.url, | |
748 | userId: rootId, | |
749 | accessToken: server.accessToken, | |
750 | videoQuota: 42 | |
751 | }) | |
752 | ||
753 | await uploadVideo(server.url, server.accessToken, {}, 403) | |
754 | }) | |
755 | ||
756 | it('Should fail with a registered user having too many videos', async function () { | |
757 | this.timeout(30000) | |
758 | ||
759 | const user = { | |
760 | username: 'user3', | |
761 | password: 'my super password' | |
762 | } | |
763 | userAccessToken = await userLogin(server, user) | |
764 | ||
765 | const videoAttributes = { fixture: 'video_short2.webm' } | |
766 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
767 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
768 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
769 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
770 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
771 | await uploadVideo(server.url, userAccessToken, videoAttributes, 403) | |
772 | }) | |
773 | ||
774 | it('Should fail to import with HTTP/Torrent/magnet', async function () { | |
775 | this.timeout(120000) | |
776 | ||
777 | const baseAttributes = { | |
778 | channelId: 1, | |
779 | privacy: VideoPrivacy.PUBLIC | |
780 | } | |
781 | await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })) | |
782 | await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() })) | |
783 | await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' })) | |
784 | ||
785 | await waitJobs([ server ]) | |
786 | ||
787 | const res = await getMyVideoImports(server.url, server.accessToken) | |
788 | ||
789 | expect(res.body.total).to.equal(3) | |
790 | const videoImports: VideoImport[] = res.body.data | |
791 | expect(videoImports).to.have.lengthOf(3) | |
792 | ||
793 | for (const videoImport of videoImports) { | |
794 | expect(videoImport.state.id).to.equal(VideoImportState.FAILED) | |
795 | expect(videoImport.error).not.to.be.undefined | |
796 | expect(videoImport.error).to.contain('user video quota is exceeded') | |
797 | } | |
798 | }) | |
799 | }) | |
800 | ||
801 | describe('When having a daily video quota', function () { | |
802 | it('Should fail with a user having too many videos', async function () { | |
803 | await updateUser({ | |
804 | url: server.url, | |
805 | userId: rootId, | |
806 | accessToken: server.accessToken, | |
807 | videoQuotaDaily: 42 | |
808 | }) | |
809 | ||
810 | await uploadVideo(server.url, server.accessToken, {}, 403) | |
811 | }) | |
812 | }) | |
813 | ||
814 | describe('When having an absolute and daily video quota', function () { | |
815 | it('Should fail if exceeding total quota', async function () { | |
816 | await updateUser({ | |
817 | url: server.url, | |
818 | userId: rootId, | |
819 | accessToken: server.accessToken, | |
820 | videoQuota: 42, | |
821 | videoQuotaDaily: 1024 * 1024 * 1024 | |
822 | }) | |
823 | ||
824 | await uploadVideo(server.url, server.accessToken, {}, 403) | |
825 | }) | |
826 | ||
827 | it('Should fail if exceeding daily quota', async function () { | |
828 | await updateUser({ | |
829 | url: server.url, | |
830 | userId: rootId, | |
831 | accessToken: server.accessToken, | |
832 | videoQuota: 1024 * 1024 * 1024, | |
833 | videoQuotaDaily: 42 | |
834 | }) | |
835 | ||
836 | await uploadVideo(server.url, server.accessToken, {}, 403) | |
837 | }) | |
838 | }) | |
839 | ||
840 | describe('When asking a password reset', function () { | |
841 | const path = '/api/v1/users/ask-reset-password' | |
842 | ||
843 | it('Should fail with a missing email', async function () { | |
844 | const fields = {} | |
845 | ||
846 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
847 | }) | |
848 | ||
849 | it('Should fail with an invalid email', async function () { | |
850 | const fields = { email: 'hello' } | |
851 | ||
852 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
853 | }) | |
854 | ||
855 | it('Should success with the correct params', async function () { | |
856 | const fields = { email: 'admin@example.com' } | |
857 | ||
858 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
859 | }) | |
860 | }) | |
861 | ||
862 | describe('When asking for an account verification email', function () { | |
863 | const path = '/api/v1/users/ask-send-verify-email' | |
864 | ||
865 | it('Should fail with a missing email', async function () { | |
866 | const fields = {} | |
867 | ||
868 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
869 | }) | |
870 | ||
871 | it('Should fail with an invalid email', async function () { | |
872 | const fields = { email: 'hello' } | |
873 | ||
874 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
875 | }) | |
876 | ||
877 | it('Should succeed with the correct params', async function () { | |
878 | const fields = { email: 'admin@example.com' } | |
879 | ||
880 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
881 | }) | |
882 | }) | |
883 | ||
884 | after(async function () { | |
885 | killallServers([ server, serverWithRegistrationDisabled ]) | |
886 | ||
887 | // Keep the logs if the test failed | |
888 | if (this['ok']) { | |
889 | await flushTests() | |
890 | } | |
891 | }) | |
892 | }) |