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