1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { omit } from 'lodash'
5 import { HttpStatusCode } from '@shared/core-utils'
7 buildAbsoluteFixturePath,
8 checkBadCountPagination,
9 checkBadSortPagination,
10 checkBadStartPagination,
21 setAccessTokensToServers,
23 } from '@shared/extra-utils'
24 import { UserAdminFlag, UserRole, VideoCreateResult } from '@shared/models'
26 describe('Test users API validators', function () {
27 const path = '/api/v1/users/'
30 let moderatorId: number
31 let video: VideoCreateResult
32 let server: ServerInfo
33 let serverWithRegistrationDisabled: ServerInfo
35 let moderatorToken = ''
37 let overrideConfig: Object
39 // ---------------------------------------------------------------
41 before(async function () {
44 const emails: object[] = []
45 emailPort = await MockSmtpServer.Instance.collectEmails(emails)
47 overrideConfig = { signup: { limit: 8 } }
50 const res = await Promise.all([
51 flushAndRunServer(1, overrideConfig),
56 serverWithRegistrationDisabled = res[1]
58 await setAccessTokensToServers([ server ])
62 const user = { username: 'user1' }
63 await server.users.create({ ...user })
64 userToken = await server.login.getAccessToken(user)
68 const moderator = { username: 'moderator1' }
69 await server.users.create({ ...moderator, role: UserRole.MODERATOR })
70 moderatorToken = await server.login.getAccessToken(moderator)
74 const moderator = { username: 'moderator2' }
75 await server.users.create({ ...moderator, role: UserRole.MODERATOR })
79 video = await server.videos.upload()
83 const { data } = await server.users.list()
84 userId = data.find(u => u.username === 'user1').id
85 rootId = data.find(u => u.username === 'root').id
86 moderatorId = data.find(u => u.username === 'moderator2').id
90 describe('When listing users', function () {
91 it('Should fail with a bad start pagination', async function () {
92 await checkBadStartPagination(server.url, path, server.accessToken)
95 it('Should fail with a bad count pagination', async function () {
96 await checkBadCountPagination(server.url, path, server.accessToken)
99 it('Should fail with an incorrect sort', async function () {
100 await checkBadSortPagination(server.url, path, server.accessToken)
103 it('Should fail with a non authenticated user', async function () {
104 await makeGetRequest({
107 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
111 it('Should fail with a non admin user', async function () {
112 await makeGetRequest({
116 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
121 describe('When adding a new user', function () {
122 const baseCorrectParams = {
124 email: 'test@example.com',
125 password: 'my super password',
129 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
132 it('Should fail with a too small username', async function () {
133 const fields = { ...baseCorrectParams, username: '' }
135 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
138 it('Should fail with a too long username', async function () {
139 const fields = { ...baseCorrectParams, username: 'super'.repeat(50) }
141 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
144 it('Should fail with a not lowercase username', async function () {
145 const fields = { ...baseCorrectParams, username: 'Toto' }
147 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
150 it('Should fail with an incorrect username', async function () {
151 const fields = { ...baseCorrectParams, username: 'my username' }
153 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
156 it('Should fail with a missing email', async function () {
157 const fields = omit(baseCorrectParams, 'email')
159 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
162 it('Should fail with an invalid email', async function () {
163 const fields = { ...baseCorrectParams, email: 'test_example.com' }
165 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
168 it('Should fail with a too small password', async function () {
169 const fields = { ...baseCorrectParams, password: 'bla' }
171 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
174 it('Should fail with a too long password', async function () {
175 const fields = { ...baseCorrectParams, password: 'super'.repeat(61) }
177 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
180 it('Should fail with empty password and no smtp configured', async function () {
181 const fields = { ...baseCorrectParams, password: '' }
183 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
186 it('Should succeed with no password on a server with smtp enabled', async function () {
189 await killallServers([ server ])
195 hostname: 'localhost',
199 await reRunServer(server, config)
202 ...baseCorrectParams,
205 username: 'create_password',
206 email: 'create_password@example.com'
209 await makePostBodyRequest({
212 token: server.accessToken,
214 statusCodeExpected: HttpStatusCode.OK_200
218 it('Should fail with invalid admin flags', async function () {
219 const fields = { ...baseCorrectParams, adminFlags: 'toto' }
221 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
224 it('Should fail with an non authenticated user', async function () {
225 await makePostBodyRequest({
228 token: 'super token',
229 fields: baseCorrectParams,
230 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
234 it('Should fail if we add a user with the same username', async function () {
235 const fields = { ...baseCorrectParams, username: 'user1' }
237 await makePostBodyRequest({
240 token: server.accessToken,
242 statusCodeExpected: HttpStatusCode.CONFLICT_409
246 it('Should fail if we add a user with the same email', async function () {
247 const fields = { ...baseCorrectParams, email: 'user1@example.com' }
249 await makePostBodyRequest({
252 token: server.accessToken,
254 statusCodeExpected: HttpStatusCode.CONFLICT_409
258 it('Should fail without a videoQuota', async function () {
259 const fields = omit(baseCorrectParams, 'videoQuota')
261 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
264 it('Should fail without a videoQuotaDaily', async function () {
265 const fields = omit(baseCorrectParams, 'videoQuotaDaily')
267 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
270 it('Should fail with an invalid videoQuota', async function () {
271 const fields = { ...baseCorrectParams, videoQuota: -5 }
273 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
276 it('Should fail with an invalid videoQuotaDaily', async function () {
277 const fields = { ...baseCorrectParams, videoQuotaDaily: -7 }
279 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
282 it('Should fail without a user role', async function () {
283 const fields = omit(baseCorrectParams, 'role')
285 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
288 it('Should fail with an invalid user role', async function () {
289 const fields = { ...baseCorrectParams, role: 88989 }
291 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
294 it('Should fail with a "peertube" username', async function () {
295 const fields = { ...baseCorrectParams, username: 'peertube' }
297 await makePostBodyRequest({
300 token: server.accessToken,
302 statusCodeExpected: HttpStatusCode.CONFLICT_409
306 it('Should fail to create a moderator or an admin with a moderator', async function () {
307 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
308 const fields = { ...baseCorrectParams, role }
310 await makePostBodyRequest({
313 token: moderatorToken,
315 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
320 it('Should succeed to create a user with a moderator', async function () {
321 const fields = { ...baseCorrectParams, username: 'a4656', email: 'a4656@example.com', role: UserRole.USER }
323 await makePostBodyRequest({
326 token: moderatorToken,
328 statusCodeExpected: HttpStatusCode.OK_200
332 it('Should succeed with the correct params', async function () {
333 await makePostBodyRequest({
336 token: server.accessToken,
337 fields: baseCorrectParams,
338 statusCodeExpected: HttpStatusCode.OK_200
342 it('Should fail with a non admin user', async function () {
343 const user = { username: 'user1' }
344 userToken = await server.login.getAccessToken(user)
348 email: 'test@example.com',
349 password: 'my super password',
352 await makePostBodyRequest({ url: server.url, path, token: userToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
356 describe('When updating my account', function () {
358 it('Should fail with an invalid email attribute', async function () {
363 await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields })
366 it('Should fail with a too small password', async function () {
368 currentPassword: 'password',
372 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
375 it('Should fail with a too long password', async function () {
377 currentPassword: 'password',
378 password: 'super'.repeat(61)
381 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
384 it('Should fail without the current password', async function () {
386 currentPassword: 'password',
387 password: 'super'.repeat(61)
390 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
393 it('Should fail with an invalid current password', async function () {
395 currentPassword: 'my super password fail',
396 password: 'super'.repeat(61)
399 await makePutBodyRequest({
404 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
408 it('Should fail with an invalid NSFW policy attribute', async function () {
413 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
416 it('Should fail with an invalid autoPlayVideo attribute', async function () {
421 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
424 it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
426 autoPlayNextVideo: -1
429 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
432 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
434 videosHistoryEnabled: -1
437 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
440 it('Should fail with an non authenticated user', async function () {
442 currentPassword: 'password',
443 password: 'my super password'
446 await makePutBodyRequest({
449 token: 'super token',
451 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
455 it('Should fail with a too long description', async function () {
457 description: 'super'.repeat(201)
460 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
463 it('Should fail with an invalid videoLanguages attribute', async function () {
466 videoLanguages: 'toto'
469 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
474 for (let i = 0; i < 1000; i++) {
479 videoLanguages: languages
482 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
486 it('Should fail with an invalid theme', async function () {
487 const fields = { theme: 'invalid' }
488 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
491 it('Should fail with an unknown theme', async function () {
492 const fields = { theme: 'peertube-theme-unknown' }
493 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
496 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
498 noInstanceConfigWarningModal: -1
501 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
504 it('Should fail with an invalid noWelcomeModal attribute', async function () {
509 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
512 it('Should succeed to change password with the correct params', async function () {
514 currentPassword: 'password',
515 password: 'my super password',
517 autoPlayVideo: false,
518 email: 'super_email@example.com',
520 noInstanceConfigWarningModal: true,
524 await makePutBodyRequest({
529 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
533 it('Should succeed without password change with the correct params', async function () {
539 await makePutBodyRequest({
544 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
549 describe('When updating my avatar', function () {
550 it('Should fail without an incorrect input file', async function () {
553 avatarfile: buildAbsoluteFixturePath('video_short.mp4')
555 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
558 it('Should fail with a big file', async function () {
561 avatarfile: buildAbsoluteFixturePath('avatar-big.png')
563 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
566 it('Should fail with an unauthenticated user', async function () {
569 avatarfile: buildAbsoluteFixturePath('avatar.png')
571 await makeUploadRequest({
573 path: path + '/me/avatar/pick',
576 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
580 it('Should succeed with the correct params', async function () {
583 avatarfile: buildAbsoluteFixturePath('avatar.png')
585 await makeUploadRequest({
587 path: path + '/me/avatar/pick',
588 token: server.accessToken,
591 statusCodeExpected: HttpStatusCode.OK_200
596 describe('When managing my scoped tokens', function () {
598 it('Should fail to get my scoped tokens with an non authenticated user', async function () {
599 await server.users.getMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
602 it('Should fail to get my scoped tokens with a bad token', async function () {
603 await server.users.getMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
607 it('Should succeed to get my scoped tokens', async function () {
608 await server.users.getMyScopedTokens()
611 it('Should fail to renew my scoped tokens with an non authenticated user', async function () {
612 await server.users.renewMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
615 it('Should fail to renew my scoped tokens with a bad token', async function () {
616 await server.users.renewMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
619 it('Should succeed to renew my scoped tokens', async function () {
620 await server.users.renewMyScopedTokens()
624 describe('When getting a user', function () {
626 it('Should fail with an non authenticated user', async function () {
627 await makeGetRequest({
630 token: 'super token',
631 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
635 it('Should fail with a non admin user', async function () {
636 await makeGetRequest({ url: server.url, path, token: userToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
639 it('Should succeed with the correct params', async function () {
640 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: HttpStatusCode.OK_200 })
644 describe('When updating a user', function () {
646 it('Should fail with an invalid email attribute', async function () {
651 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
654 it('Should fail with an invalid emailVerified attribute', async function () {
659 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
662 it('Should fail with an invalid videoQuota attribute', async function () {
667 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
670 it('Should fail with an invalid user role attribute', async function () {
675 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
678 it('Should fail with a too small password', async function () {
680 currentPassword: 'password',
684 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
687 it('Should fail with a too long password', async function () {
689 currentPassword: 'password',
690 password: 'super'.repeat(61)
693 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
696 it('Should fail with an non authenticated user', async function () {
701 await makePutBodyRequest({
704 token: 'super token',
706 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
710 it('Should fail when updating root role', async function () {
712 role: UserRole.MODERATOR
715 await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
718 it('Should fail with invalid admin flags', async function () {
719 const fields = { adminFlags: 'toto' }
721 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
724 it('Should fail to update an admin with a moderator', async function () {
729 await makePutBodyRequest({
731 path: path + moderatorId,
732 token: moderatorToken,
734 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
738 it('Should succeed to update a user with a moderator', async function () {
743 await makePutBodyRequest({
746 token: moderatorToken,
748 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
752 it('Should succeed with the correct params', async function () {
754 email: 'email@example.com',
760 await makePutBodyRequest({
763 token: server.accessToken,
765 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
770 describe('When getting my information', function () {
771 it('Should fail with a non authenticated user', async function () {
772 await server.users.getMyInfo({ token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
775 it('Should success with the correct parameters', async function () {
776 await server.users.getMyInfo({ token: userToken })
780 describe('When getting my video rating', function () {
781 let command: UsersCommand
784 command = server.users
787 it('Should fail with a non authenticated user', async function () {
788 await command.getMyRating({ token: 'fake_token', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
791 it('Should fail with an incorrect video uuid', async function () {
792 await command.getMyRating({ videoId: 'blabla', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
795 it('Should fail with an unknown video', async function () {
796 await command.getMyRating({ videoId: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
799 it('Should succeed with the correct parameters', async function () {
800 await command.getMyRating({ videoId: video.id })
801 await command.getMyRating({ videoId: video.uuid })
802 await command.getMyRating({ videoId: video.shortUUID })
806 describe('When retrieving my global ratings', function () {
807 const path = '/api/v1/accounts/user1/ratings'
809 it('Should fail with a bad start pagination', async function () {
810 await checkBadStartPagination(server.url, path, userToken)
813 it('Should fail with a bad count pagination', async function () {
814 await checkBadCountPagination(server.url, path, userToken)
817 it('Should fail with an incorrect sort', async function () {
818 await checkBadSortPagination(server.url, path, userToken)
821 it('Should fail with a unauthenticated user', async function () {
822 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
825 it('Should fail with a another user', async function () {
826 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
829 it('Should fail with a bad type', async function () {
830 await makeGetRequest({
834 query: { rating: 'toto ' },
835 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
839 it('Should succeed with the correct params', async function () {
840 await makeGetRequest({ url: server.url, path, token: userToken, statusCodeExpected: HttpStatusCode.OK_200 })
844 describe('When blocking/unblocking/removing user', function () {
846 it('Should fail with an incorrect id', async function () {
847 const options = { userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
849 await server.users.remove(options)
850 await server.users.banUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
851 await server.users.unbanUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
854 it('Should fail with the root user', async function () {
855 const options = { userId: rootId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
857 await server.users.remove(options)
858 await server.users.banUser(options)
859 await server.users.unbanUser(options)
862 it('Should return 404 with a non existing id', async function () {
863 const options = { userId: 4545454, expectedStatus: HttpStatusCode.NOT_FOUND_404 }
865 await server.users.remove(options)
866 await server.users.banUser(options)
867 await server.users.unbanUser(options)
870 it('Should fail with a non admin user', async function () {
871 const options = { userId, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }
873 await server.users.remove(options)
874 await server.users.banUser(options)
875 await server.users.unbanUser(options)
878 it('Should fail on a moderator with a moderator', async function () {
879 const options = { userId: moderatorId, token: moderatorToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }
881 await server.users.remove(options)
882 await server.users.banUser(options)
883 await server.users.unbanUser(options)
886 it('Should succeed on a user with a moderator', async function () {
887 const options = { userId, token: moderatorToken }
889 await server.users.banUser(options)
890 await server.users.unbanUser(options)
894 describe('When deleting our account', function () {
895 it('Should fail with with the root account', async function () {
896 await server.users.deleteMe({ expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
900 describe('When registering a new user', function () {
901 const registrationPath = path + '/register'
902 const baseCorrectParams = {
904 displayName: 'super user',
905 email: 'test3@example.com',
906 password: 'my super password'
909 it('Should fail with a too small username', async function () {
910 const fields = { ...baseCorrectParams, username: '' }
912 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
915 it('Should fail with a too long username', async function () {
916 const fields = { ...baseCorrectParams, username: 'super'.repeat(50) }
918 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
921 it('Should fail with an incorrect username', async function () {
922 const fields = { ...baseCorrectParams, username: 'my username' }
924 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
927 it('Should fail with a missing email', async function () {
928 const fields = omit(baseCorrectParams, 'email')
930 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
933 it('Should fail with an invalid email', async function () {
934 const fields = { ...baseCorrectParams, email: 'test_example.com' }
936 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
939 it('Should fail with a too small password', async function () {
940 const fields = { ...baseCorrectParams, password: 'bla' }
942 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
945 it('Should fail with a too long password', async function () {
946 const fields = { ...baseCorrectParams, password: 'super'.repeat(61) }
948 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
951 it('Should fail if we register a user with the same username', async function () {
952 const fields = { ...baseCorrectParams, username: 'root' }
954 await makePostBodyRequest({
956 path: registrationPath,
957 token: server.accessToken,
959 statusCodeExpected: HttpStatusCode.CONFLICT_409
963 it('Should fail with a "peertube" username', async function () {
964 const fields = { ...baseCorrectParams, username: 'peertube' }
966 await makePostBodyRequest({
968 path: registrationPath,
969 token: server.accessToken,
971 statusCodeExpected: HttpStatusCode.CONFLICT_409
975 it('Should fail if we register a user with the same email', async function () {
976 const fields = { ...baseCorrectParams, email: 'admin' + server.internalServerNumber + '@example.com' }
978 await makePostBodyRequest({
980 path: registrationPath,
981 token: server.accessToken,
983 statusCodeExpected: HttpStatusCode.CONFLICT_409
987 it('Should fail with a bad display name', async function () {
988 const fields = { ...baseCorrectParams, displayName: 'a'.repeat(150) }
990 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
993 it('Should fail with a bad channel name', async function () {
994 const fields = { ...baseCorrectParams, channel: { name: '[]azf', displayName: 'toto' } }
996 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
999 it('Should fail with a bad channel display name', async function () {
1000 const fields = { ...baseCorrectParams, channel: { name: 'toto', displayName: '' } }
1002 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1005 it('Should fail with a channel name that is the same as username', async function () {
1006 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
1007 const fields = { ...baseCorrectParams, ...source }
1009 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1012 it('Should fail with an existing channel', async function () {
1013 const attributes = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
1014 await server.channels.create({ attributes })
1016 const fields = { ...baseCorrectParams, channel: { name: 'existing_channel', displayName: 'toto' } }
1018 await makePostBodyRequest({
1020 path: registrationPath,
1021 token: server.accessToken,
1023 statusCodeExpected: HttpStatusCode.CONFLICT_409
1027 it('Should succeed with the correct params', async function () {
1028 const fields = { ...baseCorrectParams, channel: { name: 'super_channel', displayName: 'toto' } }
1030 await makePostBodyRequest({
1032 path: registrationPath,
1033 token: server.accessToken,
1035 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1039 it('Should fail on a server with registration disabled', async function () {
1042 email: 'test4@example.com',
1043 password: 'my super password 4'
1046 await makePostBodyRequest({
1047 url: serverWithRegistrationDisabled.url,
1048 path: registrationPath,
1049 token: serverWithRegistrationDisabled.accessToken,
1051 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
1056 describe('When registering multiple users on a server with users limit', function () {
1057 it('Should fail when after 3 registrations', async function () {
1058 await server.users.register({ username: 'user42', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
1062 describe('When asking a password reset', function () {
1063 const path = '/api/v1/users/ask-reset-password'
1065 it('Should fail with a missing email', async function () {
1068 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1071 it('Should fail with an invalid email', async function () {
1072 const fields = { email: 'hello' }
1074 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1077 it('Should success with the correct params', async function () {
1078 const fields = { email: 'admin@example.com' }
1080 await makePostBodyRequest({
1083 token: server.accessToken,
1085 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1090 describe('When asking for an account verification email', function () {
1091 const path = '/api/v1/users/ask-send-verify-email'
1093 it('Should fail with a missing email', async function () {
1096 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1099 it('Should fail with an invalid email', async function () {
1100 const fields = { email: 'hello' }
1102 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1105 it('Should succeed with the correct params', async function () {
1106 const fields = { email: 'admin@example.com' }
1108 await makePostBodyRequest({
1111 token: server.accessToken,
1113 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1118 after(async function () {
1119 MockSmtpServer.Instance.kill()
1121 await cleanupTests([ server, serverWithRegistrationDisabled ])