1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
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 = ''
53 // eslint-disable-next-line @typescript-eslint/no-unused-vars
56 // ---------------------------------------------------------------
58 before(async function () {
62 const res = await Promise.all([
63 flushAndRunServer(1, { signup: { limit: 7 } }),
68 serverWithRegistrationDisabled = res[1]
70 await setAccessTokensToServers([ server ])
76 password: 'my super password'
79 const videoQuota = 42000000
82 accessToken: server.accessToken,
83 username: user.username,
84 password: user.password,
85 videoQuota: videoQuota
87 userAccessToken = await userLogin(server, user)
92 username: 'moderator1',
93 password: 'super password'
98 accessToken: server.accessToken,
99 username: moderator.username,
100 password: moderator.password,
101 role: UserRole.MODERATOR
104 moderatorAccessToken = await userLogin(server, moderator)
109 username: 'moderator2',
110 password: 'super password'
115 accessToken: server.accessToken,
116 username: moderator.username,
117 password: moderator.password,
118 role: UserRole.MODERATOR
123 const res = await getMyUserInformation(server.url, server.accessToken)
124 channelId = res.body.videoChannels[0].id
128 const res = await uploadVideo(server.url, server.accessToken, {})
129 videoId = res.body.video.id
133 const res = await getUsersList(server.url, server.accessToken)
134 const users: User[] = res.body.data
136 userId = users.find(u => u.username === 'user1').id
137 rootId = users.find(u => u.username === 'root').id
138 moderatorId = users.find(u => u.username === 'moderator2').id
142 describe('When listing users', function () {
143 it('Should fail with a bad start pagination', async function () {
144 await checkBadStartPagination(server.url, path, server.accessToken)
147 it('Should fail with a bad count pagination', async function () {
148 await checkBadCountPagination(server.url, path, server.accessToken)
151 it('Should fail with an incorrect sort', async function () {
152 await checkBadSortPagination(server.url, path, server.accessToken)
155 it('Should fail with a non authenticated user', async function () {
156 await makeGetRequest({
159 statusCodeExpected: 401
163 it('Should fail with a non admin user', async function () {
164 await makeGetRequest({
167 token: userAccessToken,
168 statusCodeExpected: 403
173 describe('When adding a new user', function () {
174 const baseCorrectParams = {
176 email: 'test@example.com',
177 password: 'my super password',
181 adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST
184 it('Should fail with a too small username', async function () {
185 const fields = immutableAssign(baseCorrectParams, { username: '' })
187 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
190 it('Should fail with a too long username', async function () {
191 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
193 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
196 it('Should fail with a not lowercase username', async function () {
197 const fields = immutableAssign(baseCorrectParams, { username: 'Toto' })
199 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
202 it('Should fail with an incorrect username', async function () {
203 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
205 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
208 it('Should fail with a missing email', async function () {
209 const fields = omit(baseCorrectParams, 'email')
211 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
214 it('Should fail with an invalid email', async function () {
215 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
217 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
220 it('Should fail with a too small password', async function () {
221 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
223 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
226 it('Should fail with a too long password', async function () {
227 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
229 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
232 it('Should fail with invalid admin flags', async function () {
233 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' })
235 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
238 it('Should fail with an non authenticated user', async function () {
239 await makePostBodyRequest({
242 token: 'super token',
243 fields: baseCorrectParams,
244 statusCodeExpected: 401
248 it('Should fail if we add a user with the same username', async function () {
249 const fields = immutableAssign(baseCorrectParams, { username: 'user1' })
251 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
254 it('Should fail if we add a user with the same email', async function () {
255 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' })
257 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
260 it('Should fail without a videoQuota', async function () {
261 const fields = omit(baseCorrectParams, 'videoQuota')
263 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
266 it('Should fail without a videoQuotaDaily', async function () {
267 const fields = omit(baseCorrectParams, 'videoQuotaDaily')
269 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
272 it('Should fail with an invalid videoQuota', async function () {
273 const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 })
275 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
278 it('Should fail with an invalid videoQuotaDaily', async function () {
279 const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 })
281 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
284 it('Should fail without a user role', async function () {
285 const fields = omit(baseCorrectParams, 'role')
287 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
290 it('Should fail with an invalid user role', async function () {
291 const fields = immutableAssign(baseCorrectParams, { role: 88989 })
293 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
296 it('Should fail with a "peertube" username', async function () {
297 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
299 await makePostBodyRequest({
302 token: server.accessToken,
304 statusCodeExpected: 409
308 it('Should fail to create a moderator or an admin with a moderator', async function () {
309 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
310 const fields = immutableAssign(baseCorrectParams, { role })
312 await makePostBodyRequest({
315 token: moderatorAccessToken,
317 statusCodeExpected: 403
322 it('Should succeed to create a user with a moderator', async function () {
323 const fields = immutableAssign(baseCorrectParams, { username: 'a4656', email: 'a4656@example.com', role: UserRole.USER })
325 await makePostBodyRequest({
328 token: moderatorAccessToken,
330 statusCodeExpected: 200
334 it('Should succeed with the correct params', async function () {
335 await makePostBodyRequest({
338 token: server.accessToken,
339 fields: baseCorrectParams,
340 statusCodeExpected: 200
344 it('Should fail with a non admin user', async function () {
347 password: 'my super password'
349 userAccessToken = await userLogin(server, user)
353 email: 'test@example.com',
354 password: 'my super password',
357 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
361 describe('When updating my account', function () {
362 it('Should fail with an invalid email attribute', async function () {
367 await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields })
370 it('Should fail with a too small password', async function () {
372 currentPassword: 'my super password',
376 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
379 it('Should fail with a too long password', async function () {
381 currentPassword: 'my super password',
382 password: 'super'.repeat(61)
385 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
388 it('Should fail without the current password', async function () {
390 currentPassword: 'my super password',
391 password: 'super'.repeat(61)
394 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
397 it('Should fail with an invalid current password', async function () {
399 currentPassword: 'my super password fail',
400 password: 'super'.repeat(61)
403 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 401 })
406 it('Should fail with an invalid NSFW policy attribute', async function () {
411 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
414 it('Should fail with an invalid autoPlayVideo attribute', async function () {
419 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
422 it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
424 autoPlayNextVideo: -1
427 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
430 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
432 videosHistoryEnabled: -1
435 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
438 it('Should fail with an non authenticated user', async function () {
440 currentPassword: 'my super password',
441 password: 'my super password'
444 await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 })
447 it('Should fail with a too long description', async function () {
449 description: 'super'.repeat(201)
452 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
455 it('Should fail with an invalid videoLanguages attribute', async function () {
458 videoLanguages: 'toto'
461 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
466 for (let i = 0; i < 1000; i++) {
471 videoLanguages: languages
474 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
478 it('Should fail with an invalid theme', async function () {
479 const fields = { theme: 'invalid' }
480 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
483 it('Should fail with an unknown theme', async function () {
484 const fields = { theme: 'peertube-theme-unknown' }
485 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
488 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
490 noInstanceConfigWarningModal: -1
493 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
496 it('Should fail with an invalid noWelcomeModal attribute', async function () {
501 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
504 it('Should succeed to change password with the correct params', async function () {
506 currentPassword: 'my super password',
507 password: 'my super password',
509 autoPlayVideo: false,
510 email: 'super_email@example.com',
512 noInstanceConfigWarningModal: true,
516 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
519 it('Should succeed without password change with the correct params', async function () {
525 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
529 describe('When updating my avatar', function () {
530 it('Should fail without an incorrect input file', async function () {
533 avatarfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
535 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
538 it('Should fail with a big file', async function () {
541 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
543 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
546 it('Should fail with an unauthenticated user', async function () {
549 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
551 await makeUploadRequest({
553 path: path + '/me/avatar/pick',
556 statusCodeExpected: 401
560 it('Should succeed with the correct params', async function () {
563 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
565 await makeUploadRequest({
567 path: path + '/me/avatar/pick',
568 token: server.accessToken,
571 statusCodeExpected: 200
576 describe('When getting a user', function () {
578 it('Should fail with an non authenticated user', async function () {
579 await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 })
582 it('Should fail with a non admin user', async function () {
583 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 })
586 it('Should succeed with the correct params', async function () {
587 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 })
591 describe('When updating a user', function () {
593 it('Should fail with an invalid email attribute', async function () {
598 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
601 it('Should fail with an invalid emailVerified attribute', async function () {
606 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
609 it('Should fail with an invalid videoQuota attribute', async function () {
614 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
617 it('Should fail with an invalid user role attribute', async function () {
622 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
625 it('Should fail with a too small password', async function () {
627 currentPassword: 'my super password',
631 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
634 it('Should fail with a too long password', async function () {
636 currentPassword: 'my super password',
637 password: 'super'.repeat(61)
640 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
643 it('Should fail with an non authenticated user', async function () {
648 await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 })
651 it('Should fail when updating root role', async function () {
653 role: UserRole.MODERATOR
656 await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
659 it('Should fail with invalid admin flags', async function () {
660 const fields = { adminFlags: 'toto' }
662 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
665 it('Should fail to update an admin with a moderator', async function () {
670 await makePutBodyRequest({
672 path: path + moderatorId,
673 token: moderatorAccessToken,
675 statusCodeExpected: 403
679 it('Should succeed to update a user with a moderator', async function () {
684 await makePutBodyRequest({
687 token: moderatorAccessToken,
689 statusCodeExpected: 204
693 it('Should succeed with the correct params', async function () {
695 email: 'email@example.com',
701 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 })
705 describe('When getting my information', function () {
706 it('Should fail with a non authenticated user', async function () {
707 await getMyUserInformation(server.url, 'fake_token', 401)
710 it('Should success with the correct parameters', async function () {
711 await getMyUserInformation(server.url, userAccessToken)
715 describe('When getting my video rating', function () {
716 it('Should fail with a non authenticated user', async function () {
717 await getMyUserVideoRating(server.url, 'fake_token', videoId, 401)
720 it('Should fail with an incorrect video uuid', async function () {
721 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400)
724 it('Should fail with an unknown video', async function () {
725 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
728 it('Should succeed with the correct parameters', async function () {
729 await getMyUserVideoRating(server.url, server.accessToken, videoId)
733 describe('When retrieving my global ratings', function () {
734 const path = '/api/v1/accounts/user1/ratings'
736 it('Should fail with a bad start pagination', async function () {
737 await checkBadStartPagination(server.url, path, userAccessToken)
740 it('Should fail with a bad count pagination', async function () {
741 await checkBadCountPagination(server.url, path, userAccessToken)
744 it('Should fail with an incorrect sort', async function () {
745 await checkBadSortPagination(server.url, path, userAccessToken)
748 it('Should fail with a unauthenticated user', async function () {
749 await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 })
752 it('Should fail with a another user', async function () {
753 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 })
756 it('Should fail with a bad type', async function () {
757 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 })
760 it('Should succeed with the correct params', async function () {
761 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 })
765 describe('When blocking/unblocking/removing user', function () {
766 it('Should fail with an incorrect id', async function () {
767 await removeUser(server.url, 'blabla', server.accessToken, 400)
768 await blockUser(server.url, 'blabla', server.accessToken, 400)
769 await unblockUser(server.url, 'blabla', server.accessToken, 400)
772 it('Should fail with the root user', async function () {
773 await removeUser(server.url, rootId, server.accessToken, 400)
774 await blockUser(server.url, rootId, server.accessToken, 400)
775 await unblockUser(server.url, rootId, server.accessToken, 400)
778 it('Should return 404 with a non existing id', async function () {
779 await removeUser(server.url, 4545454, server.accessToken, 404)
780 await blockUser(server.url, 4545454, server.accessToken, 404)
781 await unblockUser(server.url, 4545454, server.accessToken, 404)
784 it('Should fail with a non admin user', async function () {
785 await removeUser(server.url, userId, userAccessToken, 403)
786 await blockUser(server.url, userId, userAccessToken, 403)
787 await unblockUser(server.url, userId, userAccessToken, 403)
790 it('Should fail on a moderator with a moderator', async function () {
791 await removeUser(server.url, moderatorId, moderatorAccessToken, 403)
792 await blockUser(server.url, moderatorId, moderatorAccessToken, 403)
793 await unblockUser(server.url, moderatorId, moderatorAccessToken, 403)
796 it('Should succeed on a user with a moderator', async function () {
797 await blockUser(server.url, userId, moderatorAccessToken)
798 await unblockUser(server.url, userId, moderatorAccessToken)
802 describe('When deleting our account', function () {
803 it('Should fail with with the root account', async function () {
804 await deleteMe(server.url, server.accessToken, 400)
808 describe('When registering a new user', function () {
809 const registrationPath = path + '/register'
810 const baseCorrectParams = {
812 displayName: 'super user',
813 email: 'test3@example.com',
814 password: 'my super password'
817 it('Should fail with a too small username', async function () {
818 const fields = immutableAssign(baseCorrectParams, { username: '' })
820 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
823 it('Should fail with a too long username', async function () {
824 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
826 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
829 it('Should fail with an incorrect username', async function () {
830 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
832 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
835 it('Should fail with a missing email', async function () {
836 const fields = omit(baseCorrectParams, 'email')
838 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
841 it('Should fail with an invalid email', async function () {
842 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
844 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
847 it('Should fail with a too small password', async function () {
848 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
850 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
853 it('Should fail with a too long password', async function () {
854 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
856 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
859 it('Should fail if we register a user with the same username', async function () {
860 const fields = immutableAssign(baseCorrectParams, { username: 'root' })
862 await makePostBodyRequest({
864 path: registrationPath,
865 token: server.accessToken,
867 statusCodeExpected: 409
871 it('Should fail with a "peertube" username', async function () {
872 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
874 await makePostBodyRequest({
876 path: registrationPath,
877 token: server.accessToken,
879 statusCodeExpected: 409
883 it('Should fail if we register a user with the same email', async function () {
884 const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' })
886 await makePostBodyRequest({
888 path: registrationPath,
889 token: server.accessToken,
891 statusCodeExpected: 409
895 it('Should fail with a bad display name', async function () {
896 const fields = immutableAssign(baseCorrectParams, { displayName: 'a'.repeat(150) })
898 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
901 it('Should fail with a bad channel name', async function () {
902 const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } })
904 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
907 it('Should fail with a bad channel display name', async function () {
908 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } })
910 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
913 it('Should fail with a channel name that is the same as username', async function () {
914 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
915 const fields = immutableAssign(baseCorrectParams, source)
917 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
920 it('Should fail with an existing channel', async function () {
921 const videoChannelAttributesArg = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
922 await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg)
924 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } })
926 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields, statusCodeExpected: 409 })
929 it('Should succeed with the correct params', async function () {
930 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } })
932 await makePostBodyRequest({
934 path: registrationPath,
935 token: server.accessToken,
937 statusCodeExpected: 204
941 it('Should fail on a server with registration disabled', async function () {
944 email: 'test4@example.com',
945 password: 'my super password 4'
948 await makePostBodyRequest({
949 url: serverWithRegistrationDisabled.url,
950 path: registrationPath,
951 token: serverWithRegistrationDisabled.accessToken,
953 statusCodeExpected: 403
958 describe('When registering multiple users on a server with users limit', function () {
959 it('Should fail when after 3 registrations', async function () {
960 await registerUser(server.url, 'user42', 'super password', 403)
964 describe('When having a video quota', function () {
965 it('Should fail with a user having too many videos', async function () {
969 accessToken: server.accessToken,
973 await uploadVideo(server.url, server.accessToken, {}, 403)
976 it('Should fail with a registered user having too many videos', async function () {
981 password: 'my super password'
983 userAccessToken = await userLogin(server, user)
985 const videoAttributes = { fixture: 'video_short2.webm' }
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)
991 await uploadVideo(server.url, userAccessToken, videoAttributes, 403)
994 it('Should fail to import with HTTP/Torrent/magnet', async function () {
997 const baseAttributes = {
999 privacy: VideoPrivacy.PUBLIC
1001 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }))
1002 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() }))
1003 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' }))
1005 await waitJobs([ server ])
1007 const res = await getMyVideoImports(server.url, server.accessToken)
1009 expect(res.body.total).to.equal(3)
1010 const videoImports: VideoImport[] = res.body.data
1011 expect(videoImports).to.have.lengthOf(3)
1013 for (const videoImport of videoImports) {
1014 expect(videoImport.state.id).to.equal(VideoImportState.FAILED)
1015 expect(videoImport.error).not.to.be.undefined
1016 expect(videoImport.error).to.contain('user video quota is exceeded')
1021 describe('When having a daily video quota', function () {
1022 it('Should fail with a user having too many videos', async function () {
1026 accessToken: server.accessToken,
1030 await uploadVideo(server.url, server.accessToken, {}, 403)
1034 describe('When having an absolute and daily video quota', function () {
1035 it('Should fail if exceeding total quota', async function () {
1039 accessToken: server.accessToken,
1041 videoQuotaDaily: 1024 * 1024 * 1024
1044 await uploadVideo(server.url, server.accessToken, {}, 403)
1047 it('Should fail if exceeding daily quota', async function () {
1051 accessToken: server.accessToken,
1052 videoQuota: 1024 * 1024 * 1024,
1056 await uploadVideo(server.url, server.accessToken, {}, 403)
1060 describe('When asking a password reset', function () {
1061 const path = '/api/v1/users/ask-reset-password'
1063 it('Should fail with a missing email', async function () {
1066 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1069 it('Should fail with an invalid email', async function () {
1070 const fields = { email: 'hello' }
1072 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1075 it('Should success with the correct params', async function () {
1076 const fields = { email: 'admin@example.com' }
1078 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
1082 describe('When asking for an account verification email', function () {
1083 const path = '/api/v1/users/ask-send-verify-email'
1085 it('Should fail with a missing email', async function () {
1088 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1091 it('Should fail with an invalid email', async function () {
1092 const fields = { email: 'hello' }
1094 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1097 it('Should succeed with the correct params', async function () {
1098 const fields = { email: 'admin@example.com' }
1100 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
1104 after(async function () {
1105 await cleanupTests([ server, serverWithRegistrationDisabled ])