1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { omit } from 'lodash'
5 import { User, UserRole, VideoCreateResult } from '../../../../shared'
6 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
9 buildAbsoluteFixturePath,
25 renewUserScopedTokens,
28 setAccessTokensToServers,
31 } from '../../../../shared/extra-utils'
32 import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email'
34 checkBadCountPagination,
35 checkBadSortPagination,
36 checkBadStartPagination
37 } from '../../../../shared/extra-utils/requests/check-api-params'
38 import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
40 describe('Test users API validators', function () {
41 const path = '/api/v1/users/'
44 let moderatorId: number
45 let video: VideoCreateResult
46 let server: ServerInfo
47 let serverWithRegistrationDisabled: ServerInfo
48 let userAccessToken = ''
49 let moderatorAccessToken = ''
51 let overrideConfig: Object
53 // ---------------------------------------------------------------
55 before(async function () {
58 const emails: object[] = []
59 emailPort = await MockSmtpServer.Instance.collectEmails(emails)
61 overrideConfig = { signup: { limit: 8 } }
64 const res = await Promise.all([
65 flushAndRunServer(1, overrideConfig),
70 serverWithRegistrationDisabled = res[1]
72 await setAccessTokensToServers([ server ])
78 password: 'my super password'
81 const videoQuota = 42000000
84 accessToken: server.accessToken,
85 username: user.username,
86 password: user.password,
87 videoQuota: videoQuota
89 userAccessToken = await server.loginCommand.getAccessToken(user)
94 username: 'moderator1',
95 password: 'super password'
100 accessToken: server.accessToken,
101 username: moderator.username,
102 password: moderator.password,
103 role: UserRole.MODERATOR
106 moderatorAccessToken = await server.loginCommand.getAccessToken(moderator)
111 username: 'moderator2',
112 password: 'super password'
117 accessToken: server.accessToken,
118 username: moderator.username,
119 password: moderator.password,
120 role: UserRole.MODERATOR
125 const res = await uploadVideo(server.url, server.accessToken, {})
126 video = res.body.video
130 const res = await getUsersList(server.url, server.accessToken)
131 const users: User[] = res.body.data
133 userId = users.find(u => u.username === 'user1').id
134 rootId = users.find(u => u.username === 'root').id
135 moderatorId = users.find(u => u.username === 'moderator2').id
139 describe('When listing users', function () {
140 it('Should fail with a bad start pagination', async function () {
141 await checkBadStartPagination(server.url, path, server.accessToken)
144 it('Should fail with a bad count pagination', async function () {
145 await checkBadCountPagination(server.url, path, server.accessToken)
148 it('Should fail with an incorrect sort', async function () {
149 await checkBadSortPagination(server.url, path, server.accessToken)
152 it('Should fail with a non authenticated user', async function () {
153 await makeGetRequest({
156 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
160 it('Should fail with a non admin user', async function () {
161 await makeGetRequest({
164 token: userAccessToken,
165 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
170 describe('When adding a new user', function () {
171 const baseCorrectParams = {
173 email: 'test@example.com',
174 password: 'my super password',
178 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
181 it('Should fail with a too small username', async function () {
182 const fields = { ...baseCorrectParams, username: '' }
184 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
187 it('Should fail with a too long username', async function () {
188 const fields = { ...baseCorrectParams, username: 'super'.repeat(50) }
190 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
193 it('Should fail with a not lowercase username', async function () {
194 const fields = { ...baseCorrectParams, username: 'Toto' }
196 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
199 it('Should fail with an incorrect username', async function () {
200 const fields = { ...baseCorrectParams, username: 'my username' }
202 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
205 it('Should fail with a missing email', async function () {
206 const fields = omit(baseCorrectParams, 'email')
208 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
211 it('Should fail with an invalid email', async function () {
212 const fields = { ...baseCorrectParams, email: 'test_example.com' }
214 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
217 it('Should fail with a too small password', async function () {
218 const fields = { ...baseCorrectParams, password: 'bla' }
220 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
223 it('Should fail with a too long password', async function () {
224 const fields = { ...baseCorrectParams, password: 'super'.repeat(61) }
226 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
229 it('Should fail with empty password and no smtp configured', async function () {
230 const fields = { ...baseCorrectParams, password: '' }
232 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
235 it('Should succeed with no password on a server with smtp enabled', async function () {
238 await killallServers([ server ])
244 hostname: 'localhost',
248 await reRunServer(server, config)
251 ...baseCorrectParams,
254 username: 'create_password',
255 email: 'create_password@example.com'
258 await makePostBodyRequest({
261 token: server.accessToken,
263 statusCodeExpected: HttpStatusCode.OK_200
267 it('Should fail with invalid admin flags', async function () {
268 const fields = { ...baseCorrectParams, adminFlags: 'toto' }
270 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
273 it('Should fail with an non authenticated user', async function () {
274 await makePostBodyRequest({
277 token: 'super token',
278 fields: baseCorrectParams,
279 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
283 it('Should fail if we add a user with the same username', async function () {
284 const fields = { ...baseCorrectParams, username: 'user1' }
286 await makePostBodyRequest({
289 token: server.accessToken,
291 statusCodeExpected: HttpStatusCode.CONFLICT_409
295 it('Should fail if we add a user with the same email', async function () {
296 const fields = { ...baseCorrectParams, email: 'user1@example.com' }
298 await makePostBodyRequest({
301 token: server.accessToken,
303 statusCodeExpected: HttpStatusCode.CONFLICT_409
307 it('Should fail without a videoQuota', async function () {
308 const fields = omit(baseCorrectParams, 'videoQuota')
310 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
313 it('Should fail without a videoQuotaDaily', async function () {
314 const fields = omit(baseCorrectParams, 'videoQuotaDaily')
316 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
319 it('Should fail with an invalid videoQuota', async function () {
320 const fields = { ...baseCorrectParams, videoQuota: -5 }
322 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
325 it('Should fail with an invalid videoQuotaDaily', async function () {
326 const fields = { ...baseCorrectParams, videoQuotaDaily: -7 }
328 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
331 it('Should fail without a user role', async function () {
332 const fields = omit(baseCorrectParams, 'role')
334 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
337 it('Should fail with an invalid user role', async function () {
338 const fields = { ...baseCorrectParams, role: 88989 }
340 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
343 it('Should fail with a "peertube" username', async function () {
344 const fields = { ...baseCorrectParams, username: 'peertube' }
346 await makePostBodyRequest({
349 token: server.accessToken,
351 statusCodeExpected: HttpStatusCode.CONFLICT_409
355 it('Should fail to create a moderator or an admin with a moderator', async function () {
356 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
357 const fields = { ...baseCorrectParams, role }
359 await makePostBodyRequest({
362 token: moderatorAccessToken,
364 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
369 it('Should succeed to create a user with a moderator', async function () {
370 const fields = { ...baseCorrectParams, username: 'a4656', email: 'a4656@example.com', role: UserRole.USER }
372 await makePostBodyRequest({
375 token: moderatorAccessToken,
377 statusCodeExpected: HttpStatusCode.OK_200
381 it('Should succeed with the correct params', async function () {
382 await makePostBodyRequest({
385 token: server.accessToken,
386 fields: baseCorrectParams,
387 statusCodeExpected: HttpStatusCode.OK_200
391 it('Should fail with a non admin user', async function () {
394 password: 'my super password'
396 userAccessToken = await server.loginCommand.getAccessToken(user)
400 email: 'test@example.com',
401 password: 'my super password',
404 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
408 describe('When updating my account', function () {
409 it('Should fail with an invalid email attribute', async function () {
414 await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields })
417 it('Should fail with a too small password', async function () {
419 currentPassword: 'my super password',
423 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
426 it('Should fail with a too long password', async function () {
428 currentPassword: 'my super password',
429 password: 'super'.repeat(61)
432 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
435 it('Should fail without the current password', async function () {
437 currentPassword: 'my super password',
438 password: 'super'.repeat(61)
441 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
444 it('Should fail with an invalid current password', async function () {
446 currentPassword: 'my super password fail',
447 password: 'super'.repeat(61)
450 await makePutBodyRequest({
453 token: userAccessToken,
455 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
459 it('Should fail with an invalid NSFW policy attribute', async function () {
464 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
467 it('Should fail with an invalid autoPlayVideo attribute', async function () {
472 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
475 it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
477 autoPlayNextVideo: -1
480 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
483 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
485 videosHistoryEnabled: -1
488 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
491 it('Should fail with an non authenticated user', async function () {
493 currentPassword: 'my super password',
494 password: 'my super password'
497 await makePutBodyRequest({
500 token: 'super token',
502 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
506 it('Should fail with a too long description', async function () {
508 description: 'super'.repeat(201)
511 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
514 it('Should fail with an invalid videoLanguages attribute', async function () {
517 videoLanguages: 'toto'
520 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
525 for (let i = 0; i < 1000; i++) {
530 videoLanguages: languages
533 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
537 it('Should fail with an invalid theme', async function () {
538 const fields = { theme: 'invalid' }
539 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
542 it('Should fail with an unknown theme', async function () {
543 const fields = { theme: 'peertube-theme-unknown' }
544 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
547 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
549 noInstanceConfigWarningModal: -1
552 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
555 it('Should fail with an invalid noWelcomeModal attribute', async function () {
560 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
563 it('Should succeed to change password with the correct params', async function () {
565 currentPassword: 'my super password',
566 password: 'my super password',
568 autoPlayVideo: false,
569 email: 'super_email@example.com',
571 noInstanceConfigWarningModal: true,
575 await makePutBodyRequest({
578 token: userAccessToken,
580 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
584 it('Should succeed without password change with the correct params', async function () {
590 await makePutBodyRequest({
593 token: userAccessToken,
595 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
600 describe('When updating my avatar', function () {
601 it('Should fail without an incorrect input file', async function () {
604 avatarfile: buildAbsoluteFixturePath('video_short.mp4')
606 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
609 it('Should fail with a big file', async function () {
612 avatarfile: buildAbsoluteFixturePath('avatar-big.png')
614 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
617 it('Should fail with an unauthenticated user', async function () {
620 avatarfile: buildAbsoluteFixturePath('avatar.png')
622 await makeUploadRequest({
624 path: path + '/me/avatar/pick',
627 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
631 it('Should succeed with the correct params', async function () {
634 avatarfile: buildAbsoluteFixturePath('avatar.png')
636 await makeUploadRequest({
638 path: path + '/me/avatar/pick',
639 token: server.accessToken,
642 statusCodeExpected: HttpStatusCode.OK_200
647 describe('When managing my scoped tokens', function () {
649 it('Should fail to get my scoped tokens with an non authenticated user', async function () {
650 await getUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401)
653 it('Should fail to get my scoped tokens with a bad token', async function () {
654 await getUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401)
658 it('Should succeed to get my scoped tokens', async function () {
659 await getUserScopedTokens(server.url, server.accessToken)
662 it('Should fail to renew my scoped tokens with an non authenticated user', async function () {
663 await renewUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401)
666 it('Should fail to renew my scoped tokens with a bad token', async function () {
667 await renewUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401)
670 it('Should succeed to renew my scoped tokens', async function () {
671 await renewUserScopedTokens(server.url, server.accessToken)
675 describe('When getting a user', function () {
677 it('Should fail with an non authenticated user', async function () {
678 await makeGetRequest({
681 token: 'super token',
682 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
686 it('Should fail with a non admin user', async function () {
687 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
690 it('Should succeed with the correct params', async function () {
691 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: HttpStatusCode.OK_200 })
695 describe('When updating a user', function () {
697 it('Should fail with an invalid email attribute', async function () {
702 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
705 it('Should fail with an invalid emailVerified attribute', async function () {
710 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
713 it('Should fail with an invalid videoQuota attribute', async function () {
718 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
721 it('Should fail with an invalid user role attribute', async function () {
726 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
729 it('Should fail with a too small password', async function () {
731 currentPassword: 'my super password',
735 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
738 it('Should fail with a too long password', async function () {
740 currentPassword: 'my super password',
741 password: 'super'.repeat(61)
744 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
747 it('Should fail with an non authenticated user', async function () {
752 await makePutBodyRequest({
755 token: 'super token',
757 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
761 it('Should fail when updating root role', async function () {
763 role: UserRole.MODERATOR
766 await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
769 it('Should fail with invalid admin flags', async function () {
770 const fields = { adminFlags: 'toto' }
772 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
775 it('Should fail to update an admin with a moderator', async function () {
780 await makePutBodyRequest({
782 path: path + moderatorId,
783 token: moderatorAccessToken,
785 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
789 it('Should succeed to update a user with a moderator', async function () {
794 await makePutBodyRequest({
797 token: moderatorAccessToken,
799 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
803 it('Should succeed with the correct params', async function () {
805 email: 'email@example.com',
811 await makePutBodyRequest({
814 token: server.accessToken,
816 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
821 describe('When getting my information', function () {
822 it('Should fail with a non authenticated user', async function () {
823 await getMyUserInformation(server.url, 'fake_token', HttpStatusCode.UNAUTHORIZED_401)
826 it('Should success with the correct parameters', async function () {
827 await getMyUserInformation(server.url, userAccessToken)
831 describe('When getting my video rating', function () {
832 it('Should fail with a non authenticated user', async function () {
833 await getMyUserVideoRating(server.url, 'fake_token', video.id, HttpStatusCode.UNAUTHORIZED_401)
836 it('Should fail with an incorrect video uuid', async function () {
837 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', HttpStatusCode.BAD_REQUEST_400)
840 it('Should fail with an unknown video', async function () {
841 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
844 it('Should succeed with the correct parameters', async function () {
845 await getMyUserVideoRating(server.url, server.accessToken, video.id)
846 await getMyUserVideoRating(server.url, server.accessToken, video.uuid)
847 await getMyUserVideoRating(server.url, server.accessToken, video.shortUUID)
851 describe('When retrieving my global ratings', function () {
852 const path = '/api/v1/accounts/user1/ratings'
854 it('Should fail with a bad start pagination', async function () {
855 await checkBadStartPagination(server.url, path, userAccessToken)
858 it('Should fail with a bad count pagination', async function () {
859 await checkBadCountPagination(server.url, path, userAccessToken)
862 it('Should fail with an incorrect sort', async function () {
863 await checkBadSortPagination(server.url, path, userAccessToken)
866 it('Should fail with a unauthenticated user', async function () {
867 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
870 it('Should fail with a another user', async function () {
871 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
874 it('Should fail with a bad type', async function () {
875 await makeGetRequest({
878 token: userAccessToken,
879 query: { rating: 'toto ' },
880 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
884 it('Should succeed with the correct params', async function () {
885 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.OK_200 })
889 describe('When blocking/unblocking/removing user', function () {
890 it('Should fail with an incorrect id', async function () {
891 await removeUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
892 await blockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
893 await unblockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
896 it('Should fail with the root user', async function () {
897 await removeUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
898 await blockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
899 await unblockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
902 it('Should return 404 with a non existing id', async function () {
903 await removeUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
904 await blockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
905 await unblockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
908 it('Should fail with a non admin user', async function () {
909 await removeUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
910 await blockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
911 await unblockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
914 it('Should fail on a moderator with a moderator', async function () {
915 await removeUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
916 await blockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
917 await unblockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
920 it('Should succeed on a user with a moderator', async function () {
921 await blockUser(server.url, userId, moderatorAccessToken)
922 await unblockUser(server.url, userId, moderatorAccessToken)
926 describe('When deleting our account', function () {
927 it('Should fail with with the root account', async function () {
928 await deleteMe(server.url, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
932 describe('When registering a new user', function () {
933 const registrationPath = path + '/register'
934 const baseCorrectParams = {
936 displayName: 'super user',
937 email: 'test3@example.com',
938 password: 'my super password'
941 it('Should fail with a too small username', async function () {
942 const fields = { ...baseCorrectParams, username: '' }
944 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
947 it('Should fail with a too long username', async function () {
948 const fields = { ...baseCorrectParams, username: 'super'.repeat(50) }
950 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
953 it('Should fail with an incorrect username', async function () {
954 const fields = { ...baseCorrectParams, username: 'my username' }
956 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
959 it('Should fail with a missing email', async function () {
960 const fields = omit(baseCorrectParams, 'email')
962 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
965 it('Should fail with an invalid email', async function () {
966 const fields = { ...baseCorrectParams, email: 'test_example.com' }
968 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
971 it('Should fail with a too small password', async function () {
972 const fields = { ...baseCorrectParams, password: 'bla' }
974 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
977 it('Should fail with a too long password', async function () {
978 const fields = { ...baseCorrectParams, password: 'super'.repeat(61) }
980 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
983 it('Should fail if we register a user with the same username', async function () {
984 const fields = { ...baseCorrectParams, username: 'root' }
986 await makePostBodyRequest({
988 path: registrationPath,
989 token: server.accessToken,
991 statusCodeExpected: HttpStatusCode.CONFLICT_409
995 it('Should fail with a "peertube" username', async function () {
996 const fields = { ...baseCorrectParams, username: 'peertube' }
998 await makePostBodyRequest({
1000 path: registrationPath,
1001 token: server.accessToken,
1003 statusCodeExpected: HttpStatusCode.CONFLICT_409
1007 it('Should fail if we register a user with the same email', async function () {
1008 const fields = { ...baseCorrectParams, email: 'admin' + server.internalServerNumber + '@example.com' }
1010 await makePostBodyRequest({
1012 path: registrationPath,
1013 token: server.accessToken,
1015 statusCodeExpected: HttpStatusCode.CONFLICT_409
1019 it('Should fail with a bad display name', async function () {
1020 const fields = { ...baseCorrectParams, displayName: 'a'.repeat(150) }
1022 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1025 it('Should fail with a bad channel name', async function () {
1026 const fields = { ...baseCorrectParams, channel: { name: '[]azf', displayName: 'toto' } }
1028 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1031 it('Should fail with a bad channel display name', async function () {
1032 const fields = { ...baseCorrectParams, channel: { name: 'toto', displayName: '' } }
1034 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1037 it('Should fail with a channel name that is the same as username', async function () {
1038 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
1039 const fields = { ...baseCorrectParams, ...source }
1041 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1044 it('Should fail with an existing channel', async function () {
1045 const attributes = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
1046 await server.channelsCommand.create({ attributes })
1048 const fields = { ...baseCorrectParams, channel: { name: 'existing_channel', displayName: 'toto' } }
1050 await makePostBodyRequest({
1052 path: registrationPath,
1053 token: server.accessToken,
1055 statusCodeExpected: HttpStatusCode.CONFLICT_409
1059 it('Should succeed with the correct params', async function () {
1060 const fields = { ...baseCorrectParams, channel: { name: 'super_channel', displayName: 'toto' } }
1062 await makePostBodyRequest({
1064 path: registrationPath,
1065 token: server.accessToken,
1067 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1071 it('Should fail on a server with registration disabled', async function () {
1074 email: 'test4@example.com',
1075 password: 'my super password 4'
1078 await makePostBodyRequest({
1079 url: serverWithRegistrationDisabled.url,
1080 path: registrationPath,
1081 token: serverWithRegistrationDisabled.accessToken,
1083 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
1088 describe('When registering multiple users on a server with users limit', function () {
1089 it('Should fail when after 3 registrations', async function () {
1090 await registerUser(server.url, 'user42', 'super password', HttpStatusCode.FORBIDDEN_403)
1094 describe('When asking a password reset', function () {
1095 const path = '/api/v1/users/ask-reset-password'
1097 it('Should fail with a missing email', async function () {
1100 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1103 it('Should fail with an invalid email', async function () {
1104 const fields = { email: 'hello' }
1106 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1109 it('Should success with the correct params', async function () {
1110 const fields = { email: 'admin@example.com' }
1112 await makePostBodyRequest({
1115 token: server.accessToken,
1117 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1122 describe('When asking for an account verification email', function () {
1123 const path = '/api/v1/users/ask-send-verify-email'
1125 it('Should fail with a missing email', async function () {
1128 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1131 it('Should fail with an invalid email', async function () {
1132 const fields = { email: 'hello' }
1134 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1137 it('Should succeed with the correct params', async function () {
1138 const fields = { email: 'admin@example.com' }
1140 await makePostBodyRequest({
1143 token: server.accessToken,
1145 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1150 after(async function () {
1151 MockSmtpServer.Instance.kill()
1153 await cleanupTests([ server, serverWithRegistrationDisabled ])