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'
10 buildAbsoluteFixturePath,
27 renewUserScopedTokens,
30 setAccessTokensToServers,
34 } from '../../../../shared/extra-utils'
35 import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
37 checkBadCountPagination,
38 checkBadSortPagination,
39 checkBadStartPagination
40 } from '../../../../shared/extra-utils/requests/check-api-params'
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
48 let video: VideoCreateResult
49 let server: ServerInfo
50 let serverWithRegistrationDisabled: ServerInfo
51 let userAccessToken = ''
52 let moderatorAccessToken = ''
54 let overrideConfig: Object
56 // ---------------------------------------------------------------
58 before(async function () {
61 const emails: object[] = []
62 emailPort = await MockSmtpServer.Instance.collectEmails(emails)
64 overrideConfig = { signup: { limit: 8 } }
67 const res = await Promise.all([
68 flushAndRunServer(1, overrideConfig),
73 serverWithRegistrationDisabled = res[1]
75 await setAccessTokensToServers([ server ])
81 password: 'my super password'
84 const videoQuota = 42000000
87 accessToken: server.accessToken,
88 username: user.username,
89 password: user.password,
90 videoQuota: videoQuota
92 userAccessToken = await userLogin(server, user)
97 username: 'moderator1',
98 password: 'super password'
103 accessToken: server.accessToken,
104 username: moderator.username,
105 password: moderator.password,
106 role: UserRole.MODERATOR
109 moderatorAccessToken = await userLogin(server, moderator)
114 username: 'moderator2',
115 password: 'super password'
120 accessToken: server.accessToken,
121 username: moderator.username,
122 password: moderator.password,
123 role: UserRole.MODERATOR
128 const res = await uploadVideo(server.url, server.accessToken, {})
129 video = res.body.video
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: HttpStatusCode.UNAUTHORIZED_401
163 it('Should fail with a non admin user', async function () {
164 await makeGetRequest({
167 token: userAccessToken,
168 statusCodeExpected: HttpStatusCode.FORBIDDEN_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.BYPASS_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 empty password and no smtp configured', async function () {
233 const fields = immutableAssign(baseCorrectParams, { password: '' })
235 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
238 it('Should succeed with no password on a server with smtp enabled', async function () {
241 killallServers([ server ])
243 const config = immutableAssign(overrideConfig, {
245 hostname: 'localhost',
249 await reRunServer(server, config)
251 const fields = immutableAssign(baseCorrectParams, {
253 username: 'create_password',
254 email: 'create_password@example.com'
257 await makePostBodyRequest({
260 token: server.accessToken,
262 statusCodeExpected: HttpStatusCode.OK_200
266 it('Should fail with invalid admin flags', async function () {
267 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' })
269 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
272 it('Should fail with an non authenticated user', async function () {
273 await makePostBodyRequest({
276 token: 'super token',
277 fields: baseCorrectParams,
278 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
282 it('Should fail if we add a user with the same username', async function () {
283 const fields = immutableAssign(baseCorrectParams, { username: 'user1' })
285 await makePostBodyRequest({
288 token: server.accessToken,
290 statusCodeExpected: HttpStatusCode.CONFLICT_409
294 it('Should fail if we add a user with the same email', async function () {
295 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' })
297 await makePostBodyRequest({
300 token: server.accessToken,
302 statusCodeExpected: HttpStatusCode.CONFLICT_409
306 it('Should fail without a videoQuota', async function () {
307 const fields = omit(baseCorrectParams, 'videoQuota')
309 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
312 it('Should fail without a videoQuotaDaily', async function () {
313 const fields = omit(baseCorrectParams, 'videoQuotaDaily')
315 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
318 it('Should fail with an invalid videoQuota', async function () {
319 const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 })
321 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
324 it('Should fail with an invalid videoQuotaDaily', async function () {
325 const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 })
327 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
330 it('Should fail without a user role', async function () {
331 const fields = omit(baseCorrectParams, 'role')
333 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
336 it('Should fail with an invalid user role', async function () {
337 const fields = immutableAssign(baseCorrectParams, { role: 88989 })
339 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
342 it('Should fail with a "peertube" username', async function () {
343 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
345 await makePostBodyRequest({
348 token: server.accessToken,
350 statusCodeExpected: HttpStatusCode.CONFLICT_409
354 it('Should fail to create a moderator or an admin with a moderator', async function () {
355 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
356 const fields = immutableAssign(baseCorrectParams, { role })
358 await makePostBodyRequest({
361 token: moderatorAccessToken,
363 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
368 it('Should succeed to create a user with a moderator', async function () {
369 const fields = immutableAssign(baseCorrectParams, { username: 'a4656', email: 'a4656@example.com', role: UserRole.USER })
371 await makePostBodyRequest({
374 token: moderatorAccessToken,
376 statusCodeExpected: HttpStatusCode.OK_200
380 it('Should succeed with the correct params', async function () {
381 await makePostBodyRequest({
384 token: server.accessToken,
385 fields: baseCorrectParams,
386 statusCodeExpected: HttpStatusCode.OK_200
390 it('Should fail with a non admin user', async function () {
393 password: 'my super password'
395 userAccessToken = await userLogin(server, user)
399 email: 'test@example.com',
400 password: 'my super password',
403 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
407 describe('When updating my account', function () {
408 it('Should fail with an invalid email attribute', async function () {
413 await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields })
416 it('Should fail with a too small password', async function () {
418 currentPassword: 'my super password',
422 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
425 it('Should fail with a too long password', async function () {
427 currentPassword: 'my super password',
428 password: 'super'.repeat(61)
431 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
434 it('Should fail without the current password', async function () {
436 currentPassword: 'my super password',
437 password: 'super'.repeat(61)
440 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
443 it('Should fail with an invalid current password', async function () {
445 currentPassword: 'my super password fail',
446 password: 'super'.repeat(61)
449 await makePutBodyRequest({
452 token: userAccessToken,
454 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
458 it('Should fail with an invalid NSFW policy attribute', async function () {
463 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
466 it('Should fail with an invalid autoPlayVideo attribute', async function () {
471 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
474 it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
476 autoPlayNextVideo: -1
479 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
482 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
484 videosHistoryEnabled: -1
487 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
490 it('Should fail with an non authenticated user', async function () {
492 currentPassword: 'my super password',
493 password: 'my super password'
496 await makePutBodyRequest({
499 token: 'super token',
501 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
505 it('Should fail with a too long description', async function () {
507 description: 'super'.repeat(201)
510 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
513 it('Should fail with an invalid videoLanguages attribute', async function () {
516 videoLanguages: 'toto'
519 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
524 for (let i = 0; i < 1000; i++) {
529 videoLanguages: languages
532 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
536 it('Should fail with an invalid theme', async function () {
537 const fields = { theme: 'invalid' }
538 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
541 it('Should fail with an unknown theme', async function () {
542 const fields = { theme: 'peertube-theme-unknown' }
543 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
546 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
548 noInstanceConfigWarningModal: -1
551 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
554 it('Should fail with an invalid noWelcomeModal attribute', async function () {
559 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
562 it('Should succeed to change password with the correct params', async function () {
564 currentPassword: 'my super password',
565 password: 'my super password',
567 autoPlayVideo: false,
568 email: 'super_email@example.com',
570 noInstanceConfigWarningModal: true,
574 await makePutBodyRequest({
577 token: userAccessToken,
579 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
583 it('Should succeed without password change with the correct params', async function () {
589 await makePutBodyRequest({
592 token: userAccessToken,
594 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
599 describe('When updating my avatar', function () {
600 it('Should fail without an incorrect input file', async function () {
603 avatarfile: buildAbsoluteFixturePath('video_short.mp4')
605 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
608 it('Should fail with a big file', async function () {
611 avatarfile: buildAbsoluteFixturePath('avatar-big.png')
613 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
616 it('Should fail with an unauthenticated user', async function () {
619 avatarfile: buildAbsoluteFixturePath('avatar.png')
621 await makeUploadRequest({
623 path: path + '/me/avatar/pick',
626 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
630 it('Should succeed with the correct params', async function () {
633 avatarfile: buildAbsoluteFixturePath('avatar.png')
635 await makeUploadRequest({
637 path: path + '/me/avatar/pick',
638 token: server.accessToken,
641 statusCodeExpected: HttpStatusCode.OK_200
646 describe('When managing my scoped tokens', function () {
648 it('Should fail to get my scoped tokens with an non authenticated user', async function () {
649 await getUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401)
652 it('Should fail to get my scoped tokens with a bad token', async function () {
653 await getUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401)
657 it('Should succeed to get my scoped tokens', async function () {
658 await getUserScopedTokens(server.url, server.accessToken)
661 it('Should fail to renew my scoped tokens with an non authenticated user', async function () {
662 await renewUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401)
665 it('Should fail to renew my scoped tokens with a bad token', async function () {
666 await renewUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401)
669 it('Should succeed to renew my scoped tokens', async function () {
670 await renewUserScopedTokens(server.url, server.accessToken)
674 describe('When getting a user', function () {
676 it('Should fail with an non authenticated user', async function () {
677 await makeGetRequest({
680 token: 'super token',
681 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
685 it('Should fail with a non admin user', async function () {
686 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
689 it('Should succeed with the correct params', async function () {
690 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: HttpStatusCode.OK_200 })
694 describe('When updating a user', function () {
696 it('Should fail with an invalid email attribute', async function () {
701 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
704 it('Should fail with an invalid emailVerified attribute', async function () {
709 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
712 it('Should fail with an invalid videoQuota attribute', async function () {
717 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
720 it('Should fail with an invalid user role attribute', async function () {
725 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
728 it('Should fail with a too small password', async function () {
730 currentPassword: 'my super password',
734 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
737 it('Should fail with a too long password', async function () {
739 currentPassword: 'my super password',
740 password: 'super'.repeat(61)
743 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
746 it('Should fail with an non authenticated user', async function () {
751 await makePutBodyRequest({
754 token: 'super token',
756 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
760 it('Should fail when updating root role', async function () {
762 role: UserRole.MODERATOR
765 await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
768 it('Should fail with invalid admin flags', async function () {
769 const fields = { adminFlags: 'toto' }
771 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
774 it('Should fail to update an admin with a moderator', async function () {
779 await makePutBodyRequest({
781 path: path + moderatorId,
782 token: moderatorAccessToken,
784 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
788 it('Should succeed to update a user with a moderator', async function () {
793 await makePutBodyRequest({
796 token: moderatorAccessToken,
798 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
802 it('Should succeed with the correct params', async function () {
804 email: 'email@example.com',
810 await makePutBodyRequest({
813 token: server.accessToken,
815 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
820 describe('When getting my information', function () {
821 it('Should fail with a non authenticated user', async function () {
822 await getMyUserInformation(server.url, 'fake_token', HttpStatusCode.UNAUTHORIZED_401)
825 it('Should success with the correct parameters', async function () {
826 await getMyUserInformation(server.url, userAccessToken)
830 describe('When getting my video rating', function () {
831 it('Should fail with a non authenticated user', async function () {
832 await getMyUserVideoRating(server.url, 'fake_token', video.id, HttpStatusCode.UNAUTHORIZED_401)
835 it('Should fail with an incorrect video uuid', async function () {
836 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', HttpStatusCode.BAD_REQUEST_400)
839 it('Should fail with an unknown video', async function () {
840 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
843 it('Should succeed with the correct parameters', async function () {
844 await getMyUserVideoRating(server.url, server.accessToken, video.id)
845 await getMyUserVideoRating(server.url, server.accessToken, video.uuid)
846 await getMyUserVideoRating(server.url, server.accessToken, video.shortUUID)
850 describe('When retrieving my global ratings', function () {
851 const path = '/api/v1/accounts/user1/ratings'
853 it('Should fail with a bad start pagination', async function () {
854 await checkBadStartPagination(server.url, path, userAccessToken)
857 it('Should fail with a bad count pagination', async function () {
858 await checkBadCountPagination(server.url, path, userAccessToken)
861 it('Should fail with an incorrect sort', async function () {
862 await checkBadSortPagination(server.url, path, userAccessToken)
865 it('Should fail with a unauthenticated user', async function () {
866 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
869 it('Should fail with a another user', async function () {
870 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
873 it('Should fail with a bad type', async function () {
874 await makeGetRequest({
877 token: userAccessToken,
878 query: { rating: 'toto ' },
879 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
883 it('Should succeed with the correct params', async function () {
884 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.OK_200 })
888 describe('When blocking/unblocking/removing user', function () {
889 it('Should fail with an incorrect id', async function () {
890 await removeUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
891 await blockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
892 await unblockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
895 it('Should fail with the root user', async function () {
896 await removeUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
897 await blockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
898 await unblockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
901 it('Should return 404 with a non existing id', async function () {
902 await removeUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
903 await blockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
904 await unblockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
907 it('Should fail with a non admin user', async function () {
908 await removeUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
909 await blockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
910 await unblockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
913 it('Should fail on a moderator with a moderator', async function () {
914 await removeUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
915 await blockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
916 await unblockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
919 it('Should succeed on a user with a moderator', async function () {
920 await blockUser(server.url, userId, moderatorAccessToken)
921 await unblockUser(server.url, userId, moderatorAccessToken)
925 describe('When deleting our account', function () {
926 it('Should fail with with the root account', async function () {
927 await deleteMe(server.url, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
931 describe('When registering a new user', function () {
932 const registrationPath = path + '/register'
933 const baseCorrectParams = {
935 displayName: 'super user',
936 email: 'test3@example.com',
937 password: 'my super password'
940 it('Should fail with a too small username', async function () {
941 const fields = immutableAssign(baseCorrectParams, { username: '' })
943 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
946 it('Should fail with a too long username', async function () {
947 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
949 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
952 it('Should fail with an incorrect username', async function () {
953 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
955 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
958 it('Should fail with a missing email', async function () {
959 const fields = omit(baseCorrectParams, 'email')
961 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
964 it('Should fail with an invalid email', async function () {
965 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
967 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
970 it('Should fail with a too small password', async function () {
971 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
973 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
976 it('Should fail with a too long password', async function () {
977 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
979 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
982 it('Should fail if we register a user with the same username', async function () {
983 const fields = immutableAssign(baseCorrectParams, { username: 'root' })
985 await makePostBodyRequest({
987 path: registrationPath,
988 token: server.accessToken,
990 statusCodeExpected: HttpStatusCode.CONFLICT_409
994 it('Should fail with a "peertube" username', async function () {
995 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
997 await makePostBodyRequest({
999 path: registrationPath,
1000 token: server.accessToken,
1002 statusCodeExpected: HttpStatusCode.CONFLICT_409
1006 it('Should fail if we register a user with the same email', async function () {
1007 const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' })
1009 await makePostBodyRequest({
1011 path: registrationPath,
1012 token: server.accessToken,
1014 statusCodeExpected: HttpStatusCode.CONFLICT_409
1018 it('Should fail with a bad display name', async function () {
1019 const fields = immutableAssign(baseCorrectParams, { displayName: 'a'.repeat(150) })
1021 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1024 it('Should fail with a bad channel name', async function () {
1025 const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } })
1027 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1030 it('Should fail with a bad channel display name', async function () {
1031 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } })
1033 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1036 it('Should fail with a channel name that is the same as username', async function () {
1037 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
1038 const fields = immutableAssign(baseCorrectParams, source)
1040 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1043 it('Should fail with an existing channel', async function () {
1044 const videoChannelAttributesArg = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
1045 await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg)
1047 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } })
1049 await makePostBodyRequest({
1051 path: registrationPath,
1052 token: server.accessToken,
1054 statusCodeExpected: HttpStatusCode.CONFLICT_409
1058 it('Should succeed with the correct params', async function () {
1059 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } })
1061 await makePostBodyRequest({
1063 path: registrationPath,
1064 token: server.accessToken,
1066 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1070 it('Should fail on a server with registration disabled', async function () {
1073 email: 'test4@example.com',
1074 password: 'my super password 4'
1077 await makePostBodyRequest({
1078 url: serverWithRegistrationDisabled.url,
1079 path: registrationPath,
1080 token: serverWithRegistrationDisabled.accessToken,
1082 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
1087 describe('When registering multiple users on a server with users limit', function () {
1088 it('Should fail when after 3 registrations', async function () {
1089 await registerUser(server.url, 'user42', 'super password', HttpStatusCode.FORBIDDEN_403)
1093 describe('When asking a password reset', function () {
1094 const path = '/api/v1/users/ask-reset-password'
1096 it('Should fail with a missing email', async function () {
1099 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1102 it('Should fail with an invalid email', async function () {
1103 const fields = { email: 'hello' }
1105 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1108 it('Should success with the correct params', async function () {
1109 const fields = { email: 'admin@example.com' }
1111 await makePostBodyRequest({
1114 token: server.accessToken,
1116 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1121 describe('When asking for an account verification email', function () {
1122 const path = '/api/v1/users/ask-send-verify-email'
1124 it('Should fail with a missing email', async function () {
1127 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1130 it('Should fail with an invalid email', async function () {
1131 const fields = { email: 'hello' }
1133 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1136 it('Should succeed with the correct params', async function () {
1137 const fields = { email: 'admin@example.com' }
1139 await makePostBodyRequest({
1142 token: server.accessToken,
1144 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1149 after(async function () {
1150 MockSmtpServer.Instance.kill()
1152 await cleanupTests([ server, serverWithRegistrationDisabled ])