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