1 /* tslint:disable:no-unused-expression */
3 import { omit } from 'lodash'
5 import { join } from 'path'
6 import { User, UserRole, VideoImport, VideoImportState } from '../../../../shared'
26 setAccessTokensToServers,
31 } from '../../../../shared/extra-utils'
33 checkBadCountPagination,
34 checkBadSortPagination,
35 checkBadStartPagination
36 } from '../../../../shared/extra-utils/requests/check-api-params'
37 import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
38 import { VideoPrivacy } from '../../../../shared/models/videos'
39 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
40 import { expect } from 'chai'
41 import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
43 describe('Test users API validators', function () {
44 const path = '/api/v1/users/'
47 let moderatorId: number
49 let server: ServerInfo
50 let serverWithRegistrationDisabled: ServerInfo
51 let userAccessToken = ''
52 let moderatorAccessToken = ''
55 // ---------------------------------------------------------------
57 before(async function () {
61 const res = await Promise.all([
62 flushAndRunServer(1, { signup: { limit: 7 } }),
67 serverWithRegistrationDisabled = res[1]
69 await setAccessTokensToServers([ server ])
75 password: 'my super password'
78 const videoQuota = 42000000
81 accessToken: server.accessToken,
82 username: user.username,
83 password: user.password,
84 videoQuota: videoQuota
86 userAccessToken = await userLogin(server, user)
91 username: 'moderator1',
92 password: 'super password'
97 accessToken: server.accessToken,
98 username: moderator.username,
99 password: moderator.password,
100 role: UserRole.MODERATOR
103 moderatorAccessToken = await userLogin(server, moderator)
108 username: 'moderator2',
109 password: 'super password'
114 accessToken: server.accessToken,
115 username: moderator.username,
116 password: moderator.password,
117 role: UserRole.MODERATOR
122 const res = await getMyUserInformation(server.url, server.accessToken)
123 channelId = res.body.videoChannels[ 0 ].id
127 const res = await uploadVideo(server.url, server.accessToken, {})
128 videoId = res.body.video.id
132 const res = await getUsersList(server.url, server.accessToken)
133 const users: User[] = res.body.data
135 userId = users.find(u => u.username === 'user1').id
136 rootId = users.find(u => u.username === 'root').id
137 moderatorId = users.find(u => u.username === 'moderator2').id
141 describe('When listing users', function () {
142 it('Should fail with a bad start pagination', async function () {
143 await checkBadStartPagination(server.url, path, server.accessToken)
146 it('Should fail with a bad count pagination', async function () {
147 await checkBadCountPagination(server.url, path, server.accessToken)
150 it('Should fail with an incorrect sort', async function () {
151 await checkBadSortPagination(server.url, path, server.accessToken)
154 it('Should fail with a non authenticated user', async function () {
155 await makeGetRequest({
158 statusCodeExpected: 401
162 it('Should fail with a non admin user', async function () {
163 await makeGetRequest({
166 token: userAccessToken,
167 statusCodeExpected: 403
172 describe('When adding a new user', function () {
173 const baseCorrectParams = {
175 email: 'test@example.com',
176 password: 'my super password',
180 adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST
183 it('Should fail with a too small username', async function () {
184 const fields = immutableAssign(baseCorrectParams, { username: '' })
186 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
189 it('Should fail with a too long username', async function () {
190 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
192 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
195 it('Should fail with a not lowercase username', async function () {
196 const fields = immutableAssign(baseCorrectParams, { username: 'Toto' })
198 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
201 it('Should fail with an incorrect username', async function () {
202 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
204 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
207 it('Should fail with a missing email', async function () {
208 const fields = omit(baseCorrectParams, 'email')
210 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
213 it('Should fail with an invalid email', async function () {
214 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
216 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
219 it('Should fail with a too small password', async function () {
220 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
222 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
225 it('Should fail with a too long password', async function () {
226 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
228 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
231 it('Should fail with invalid admin flags', async function () {
232 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' })
234 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
237 it('Should fail with an non authenticated user', async function () {
238 await makePostBodyRequest({
241 token: 'super token',
242 fields: baseCorrectParams,
243 statusCodeExpected: 401
247 it('Should fail if we add a user with the same username', async function () {
248 const fields = immutableAssign(baseCorrectParams, { username: 'user1' })
250 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
253 it('Should fail if we add a user with the same email', async function () {
254 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' })
256 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
259 it('Should fail without a videoQuota', async function () {
260 const fields = omit(baseCorrectParams, 'videoQuota')
262 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
265 it('Should fail without a videoQuotaDaily', async function () {
266 const fields = omit(baseCorrectParams, 'videoQuotaDaily')
268 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
271 it('Should fail with an invalid videoQuota', async function () {
272 const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 })
274 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
277 it('Should fail with an invalid videoQuotaDaily', async function () {
278 const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 })
280 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
283 it('Should fail without a user role', async function () {
284 const fields = omit(baseCorrectParams, 'role')
286 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
289 it('Should fail with an invalid user role', async function () {
290 const fields = immutableAssign(baseCorrectParams, { role: 88989 })
292 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
295 it('Should fail with a "peertube" username', async function () {
296 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
298 await makePostBodyRequest({
301 token: server.accessToken,
303 statusCodeExpected: 409
307 it('Should fail to create a moderator or an admin with a moderator', async function () {
308 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
309 const fields = immutableAssign(baseCorrectParams, { role })
311 await makePostBodyRequest({
314 token: moderatorAccessToken,
316 statusCodeExpected: 403
321 it('Should succeed to create a user with a moderator', async function () {
322 const fields = immutableAssign(baseCorrectParams, { username: 'a4656', email: 'a4656@example.com', role: UserRole.USER })
324 await makePostBodyRequest({
327 token: moderatorAccessToken,
329 statusCodeExpected: 200
333 it('Should succeed with the correct params', async function () {
334 await makePostBodyRequest({
337 token: server.accessToken,
338 fields: baseCorrectParams,
339 statusCodeExpected: 200
343 it('Should fail with a non admin user', async function () {
346 password: 'my super password'
348 userAccessToken = await userLogin(server, user)
352 email: 'test@example.com',
353 password: 'my super password',
356 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
360 describe('When updating my account', function () {
361 it('Should fail with an invalid email attribute', async function () {
366 await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields })
369 it('Should fail with a too small password', async function () {
371 currentPassword: 'my super password',
375 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
378 it('Should fail with a too long password', async function () {
380 currentPassword: 'my super password',
381 password: 'super'.repeat(61)
384 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
387 it('Should fail without the current password', async function () {
389 currentPassword: 'my super password',
390 password: 'super'.repeat(61)
393 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
396 it('Should fail with an invalid current password', async function () {
398 currentPassword: 'my super password fail',
399 password: 'super'.repeat(61)
402 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 401 })
405 it('Should fail with an invalid NSFW policy attribute', async function () {
410 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
413 it('Should fail with an invalid autoPlayVideo attribute', async function () {
418 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
421 it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
423 autoPlayNextVideo: -1
426 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
429 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
431 videosHistoryEnabled: -1
434 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
437 it('Should fail with an non authenticated user', async function () {
439 currentPassword: 'my super password',
440 password: 'my super password'
443 await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 })
446 it('Should fail with a too long description', async function () {
448 description: 'super'.repeat(201)
451 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
454 it('Should fail with an invalid videoLanguages attribute', async function () {
457 videoLanguages: 'toto'
460 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
465 for (let i = 0; i < 1000; i++) {
470 videoLanguages: languages
473 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
477 it('Should fail with an invalid theme', async function () {
478 const fields = { theme: 'invalid' }
479 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
482 it('Should fail with an unknown theme', async function () {
483 const fields = { theme: 'peertube-theme-unknown' }
484 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
487 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
489 noInstanceConfigWarningModal: -1
492 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
495 it('Should fail with an invalid noWelcomeModal attribute', async function () {
500 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
503 it('Should succeed to change password with the correct params', async function () {
505 currentPassword: 'my super password',
506 password: 'my super password',
508 autoPlayVideo: false,
509 email: 'super_email@example.com',
511 noInstanceConfigWarningModal: true,
515 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
518 it('Should succeed without password change with the correct params', async function () {
524 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
528 describe('When updating my avatar', function () {
529 it('Should fail without an incorrect input file', async function () {
532 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
534 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
537 it('Should fail with a big file', async function () {
540 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
542 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
545 it('Should fail with an unauthenticated user', async function () {
548 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
550 await makeUploadRequest({
552 path: path + '/me/avatar/pick',
555 statusCodeExpected: 401
559 it('Should succeed with the correct params', async function () {
562 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
564 await makeUploadRequest({
566 path: path + '/me/avatar/pick',
567 token: server.accessToken,
570 statusCodeExpected: 200
575 describe('When getting a user', function () {
577 it('Should fail with an non authenticated user', async function () {
578 await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 })
581 it('Should fail with a non admin user', async function () {
582 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 })
585 it('Should succeed with the correct params', async function () {
586 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 })
590 describe('When updating a user', function () {
592 it('Should fail with an invalid email attribute', async function () {
597 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
600 it('Should fail with an invalid emailVerified attribute', async function () {
605 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
608 it('Should fail with an invalid videoQuota attribute', async function () {
613 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
616 it('Should fail with an invalid user role attribute', async function () {
621 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
624 it('Should fail with a too small password', async function () {
626 currentPassword: 'my super password',
630 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
633 it('Should fail with a too long password', async function () {
635 currentPassword: 'my super password',
636 password: 'super'.repeat(61)
639 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
642 it('Should fail with an non authenticated user', async function () {
647 await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 })
650 it('Should fail when updating root role', async function () {
652 role: UserRole.MODERATOR
655 await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
658 it('Should fail with invalid admin flags', async function () {
659 const fields = { adminFlags: 'toto' }
661 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
664 it('Should fail to update an admin with a moderator', async function () {
669 await makePutBodyRequest({
671 path: path + moderatorId,
672 token: moderatorAccessToken,
674 statusCodeExpected: 403
678 it('Should succeed to update a user with a moderator', async function () {
683 await makePutBodyRequest({
686 token: moderatorAccessToken,
688 statusCodeExpected: 204
692 it('Should succeed with the correct params', async function () {
694 email: 'email@example.com',
700 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 })
704 describe('When getting my information', function () {
705 it('Should fail with a non authenticated user', async function () {
706 await getMyUserInformation(server.url, 'fake_token', 401)
709 it('Should success with the correct parameters', async function () {
710 await getMyUserInformation(server.url, userAccessToken)
714 describe('When getting my video rating', function () {
715 it('Should fail with a non authenticated user', async function () {
716 await getMyUserVideoRating(server.url, 'fake_token', videoId, 401)
719 it('Should fail with an incorrect video uuid', async function () {
720 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400)
723 it('Should fail with an unknown video', async function () {
724 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
727 it('Should succeed with the correct parameters', async function () {
728 await getMyUserVideoRating(server.url, server.accessToken, videoId)
732 describe('When retrieving my global ratings', function () {
733 const path = '/api/v1/accounts/user1/ratings'
735 it('Should fail with a bad start pagination', async function () {
736 await checkBadStartPagination(server.url, path, userAccessToken)
739 it('Should fail with a bad count pagination', async function () {
740 await checkBadCountPagination(server.url, path, userAccessToken)
743 it('Should fail with an incorrect sort', async function () {
744 await checkBadSortPagination(server.url, path, userAccessToken)
747 it('Should fail with a unauthenticated user', async function () {
748 await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 })
751 it('Should fail with a another user', async function () {
752 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 })
755 it('Should fail with a bad type', async function () {
756 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 })
759 it('Should succeed with the correct params', async function () {
760 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 })
764 describe('When blocking/unblocking/removing user', function () {
765 it('Should fail with an incorrect id', async function () {
766 await removeUser(server.url, 'blabla', server.accessToken, 400)
767 await blockUser(server.url, 'blabla', server.accessToken, 400)
768 await unblockUser(server.url, 'blabla', server.accessToken, 400)
771 it('Should fail with the root user', async function () {
772 await removeUser(server.url, rootId, server.accessToken, 400)
773 await blockUser(server.url, rootId, server.accessToken, 400)
774 await unblockUser(server.url, rootId, server.accessToken, 400)
777 it('Should return 404 with a non existing id', async function () {
778 await removeUser(server.url, 4545454, server.accessToken, 404)
779 await blockUser(server.url, 4545454, server.accessToken, 404)
780 await unblockUser(server.url, 4545454, server.accessToken, 404)
783 it('Should fail with a non admin user', async function () {
784 await removeUser(server.url, userId, userAccessToken, 403)
785 await blockUser(server.url, userId, userAccessToken, 403)
786 await unblockUser(server.url, userId, userAccessToken, 403)
789 it('Should fail on a moderator with a moderator', async function () {
790 await removeUser(server.url, moderatorId, moderatorAccessToken, 403)
791 await blockUser(server.url, moderatorId, moderatorAccessToken, 403)
792 await unblockUser(server.url, moderatorId, moderatorAccessToken, 403)
795 it('Should succeed on a user with a moderator', async function () {
796 await blockUser(server.url, userId, moderatorAccessToken)
797 await unblockUser(server.url, userId, moderatorAccessToken)
801 describe('When deleting our account', function () {
802 it('Should fail with with the root account', async function () {
803 await deleteMe(server.url, server.accessToken, 400)
807 describe('When registering a new user', function () {
808 const registrationPath = path + '/register'
809 const baseCorrectParams = {
811 displayName: 'super user',
812 email: 'test3@example.com',
813 password: 'my super password'
816 it('Should fail with a too small username', async function () {
817 const fields = immutableAssign(baseCorrectParams, { username: '' })
819 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
822 it('Should fail with a too long username', async function () {
823 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
825 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
828 it('Should fail with an incorrect username', async function () {
829 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
831 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
834 it('Should fail with a missing email', async function () {
835 const fields = omit(baseCorrectParams, 'email')
837 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
840 it('Should fail with an invalid email', async function () {
841 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
843 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
846 it('Should fail with a too small password', async function () {
847 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
849 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
852 it('Should fail with a too long password', async function () {
853 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
855 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
858 it('Should fail if we register a user with the same username', async function () {
859 const fields = immutableAssign(baseCorrectParams, { username: 'root' })
861 await makePostBodyRequest({
863 path: registrationPath,
864 token: server.accessToken,
866 statusCodeExpected: 409
870 it('Should fail with a "peertube" username', async function () {
871 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
873 await makePostBodyRequest({
875 path: registrationPath,
876 token: server.accessToken,
878 statusCodeExpected: 409
882 it('Should fail if we register a user with the same email', async function () {
883 const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' })
885 await makePostBodyRequest({
887 path: registrationPath,
888 token: server.accessToken,
890 statusCodeExpected: 409
894 it('Should fail with a bad display name', async function () {
895 const fields = immutableAssign(baseCorrectParams, { displayName: 'a'.repeat(150) })
897 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
900 it('Should fail with a bad channel name', async function () {
901 const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } })
903 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
906 it('Should fail with a bad channel display name', async function () {
907 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } })
909 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
912 it('Should fail with a channel name that is the same as username', async function () {
913 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
914 const fields = immutableAssign(baseCorrectParams, source)
916 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
919 it('Should fail with an existing channel', async function () {
920 const videoChannelAttributesArg = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
921 await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg)
923 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } })
925 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields, statusCodeExpected: 409 })
928 it('Should succeed with the correct params', async function () {
929 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } })
931 await makePostBodyRequest({
933 path: registrationPath,
934 token: server.accessToken,
936 statusCodeExpected: 204
940 it('Should fail on a server with registration disabled', async function () {
943 email: 'test4@example.com',
944 password: 'my super password 4'
947 await makePostBodyRequest({
948 url: serverWithRegistrationDisabled.url,
949 path: registrationPath,
950 token: serverWithRegistrationDisabled.accessToken,
952 statusCodeExpected: 403
957 describe('When registering multiple users on a server with users limit', function () {
958 it('Should fail when after 3 registrations', async function () {
959 await registerUser(server.url, 'user42', 'super password', 403)
963 describe('When having a video quota', function () {
964 it('Should fail with a user having too many videos', async function () {
968 accessToken: server.accessToken,
972 await uploadVideo(server.url, server.accessToken, {}, 403)
975 it('Should fail with a registered user having too many videos', async function () {
980 password: 'my super password'
982 userAccessToken = await userLogin(server, user)
984 const videoAttributes = { fixture: 'video_short2.webm' }
985 await uploadVideo(server.url, userAccessToken, videoAttributes)
986 await uploadVideo(server.url, userAccessToken, videoAttributes)
987 await uploadVideo(server.url, userAccessToken, videoAttributes)
988 await uploadVideo(server.url, userAccessToken, videoAttributes)
989 await uploadVideo(server.url, userAccessToken, videoAttributes)
990 await uploadVideo(server.url, userAccessToken, videoAttributes, 403)
993 it('Should fail to import with HTTP/Torrent/magnet', async function () {
996 const baseAttributes = {
998 privacy: VideoPrivacy.PUBLIC
1000 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }))
1001 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() }))
1002 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' }))
1004 await waitJobs([ server ])
1006 const res = await getMyVideoImports(server.url, server.accessToken)
1008 expect(res.body.total).to.equal(3)
1009 const videoImports: VideoImport[] = res.body.data
1010 expect(videoImports).to.have.lengthOf(3)
1012 for (const videoImport of videoImports) {
1013 expect(videoImport.state.id).to.equal(VideoImportState.FAILED)
1014 expect(videoImport.error).not.to.be.undefined
1015 expect(videoImport.error).to.contain('user video quota is exceeded')
1020 describe('When having a daily video quota', function () {
1021 it('Should fail with a user having too many videos', async function () {
1025 accessToken: server.accessToken,
1029 await uploadVideo(server.url, server.accessToken, {}, 403)
1033 describe('When having an absolute and daily video quota', function () {
1034 it('Should fail if exceeding total quota', async function () {
1038 accessToken: server.accessToken,
1040 videoQuotaDaily: 1024 * 1024 * 1024
1043 await uploadVideo(server.url, server.accessToken, {}, 403)
1046 it('Should fail if exceeding daily quota', async function () {
1050 accessToken: server.accessToken,
1051 videoQuota: 1024 * 1024 * 1024,
1055 await uploadVideo(server.url, server.accessToken, {}, 403)
1059 describe('When asking a password reset', function () {
1060 const path = '/api/v1/users/ask-reset-password'
1062 it('Should fail with a missing email', async function () {
1065 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1068 it('Should fail with an invalid email', async function () {
1069 const fields = { email: 'hello' }
1071 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1074 it('Should success with the correct params', async function () {
1075 const fields = { email: 'admin@example.com' }
1077 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
1081 describe('When asking for an account verification email', function () {
1082 const path = '/api/v1/users/ask-send-verify-email'
1084 it('Should fail with a missing email', async function () {
1087 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1090 it('Should fail with an invalid email', async function () {
1091 const fields = { email: 'hello' }
1093 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1096 it('Should succeed with the correct params', async function () {
1097 const fields = { email: 'admin@example.com' }
1099 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
1103 after(async function () {
1104 await cleanupTests([ server, serverWithRegistrationDisabled ])