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,
20 setAccessTokensToServers,
22 } from '@shared/extra-utils'
23 import { UserAdminFlag, UserRole, VideoCreateResult } from '@shared/models'
25 describe('Test users API validators', function () {
26 const path = '/api/v1/users/'
29 let moderatorId: number
30 let video: VideoCreateResult
31 let server: PeerTubeServer
32 let serverWithRegistrationDisabled: PeerTubeServer
34 let moderatorToken = ''
36 let overrideConfig: Object
38 // ---------------------------------------------------------------
40 before(async function () {
43 const emails: object[] = []
44 emailPort = await MockSmtpServer.Instance.collectEmails(emails)
46 overrideConfig = { signup: { limit: 8 } }
49 const res = await Promise.all([
50 createSingleServer(1, overrideConfig),
55 serverWithRegistrationDisabled = res[1]
57 await setAccessTokensToServers([ server ])
61 const user = { username: 'user1' }
62 await server.users.create({ ...user })
63 userToken = await server.login.getAccessToken(user)
67 const moderator = { username: 'moderator1' }
68 await server.users.create({ ...moderator, role: UserRole.MODERATOR })
69 moderatorToken = await server.login.getAccessToken(moderator)
73 const moderator = { username: 'moderator2' }
74 await server.users.create({ ...moderator, role: UserRole.MODERATOR })
78 video = await server.videos.upload()
82 const { data } = await server.users.list()
83 userId = data.find(u => u.username === 'user1').id
84 rootId = data.find(u => u.username === 'root').id
85 moderatorId = data.find(u => u.username === 'moderator2').id
89 describe('When listing users', function () {
90 it('Should fail with a bad start pagination', async function () {
91 await checkBadStartPagination(server.url, path, server.accessToken)
94 it('Should fail with a bad count pagination', async function () {
95 await checkBadCountPagination(server.url, path, server.accessToken)
98 it('Should fail with an incorrect sort', async function () {
99 await checkBadSortPagination(server.url, path, server.accessToken)
102 it('Should fail with a non authenticated user', async function () {
103 await makeGetRequest({
106 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
110 it('Should fail with a non admin user', async function () {
111 await makeGetRequest({
115 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
120 describe('When adding a new user', function () {
121 const baseCorrectParams = {
123 email: 'test@example.com',
124 password: 'my super password',
128 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
131 it('Should fail with a too small username', async function () {
132 const fields = { ...baseCorrectParams, username: '' }
134 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
137 it('Should fail with a too long username', async function () {
138 const fields = { ...baseCorrectParams, username: 'super'.repeat(50) }
140 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
143 it('Should fail with a not lowercase username', async function () {
144 const fields = { ...baseCorrectParams, username: 'Toto' }
146 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
149 it('Should fail with an incorrect username', async function () {
150 const fields = { ...baseCorrectParams, username: 'my username' }
152 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
155 it('Should fail with a missing email', async function () {
156 const fields = omit(baseCorrectParams, 'email')
158 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
161 it('Should fail with an invalid email', async function () {
162 const fields = { ...baseCorrectParams, email: 'test_example.com' }
164 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
167 it('Should fail with a too small password', async function () {
168 const fields = { ...baseCorrectParams, password: 'bla' }
170 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
173 it('Should fail with a too long password', async function () {
174 const fields = { ...baseCorrectParams, password: 'super'.repeat(61) }
176 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
179 it('Should fail with empty password and no smtp configured', async function () {
180 const fields = { ...baseCorrectParams, password: '' }
182 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
185 it('Should succeed with no password on a server with smtp enabled', async function () {
188 await killallServers([ server ])
194 hostname: 'localhost',
198 await server.run(config)
201 ...baseCorrectParams,
204 username: 'create_password',
205 email: 'create_password@example.com'
208 await makePostBodyRequest({
211 token: server.accessToken,
213 statusCodeExpected: HttpStatusCode.OK_200
217 it('Should fail with invalid admin flags', async function () {
218 const fields = { ...baseCorrectParams, adminFlags: 'toto' }
220 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
223 it('Should fail with an non authenticated user', async function () {
224 await makePostBodyRequest({
227 token: 'super token',
228 fields: baseCorrectParams,
229 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
233 it('Should fail if we add a user with the same username', async function () {
234 const fields = { ...baseCorrectParams, username: 'user1' }
236 await makePostBodyRequest({
239 token: server.accessToken,
241 statusCodeExpected: HttpStatusCode.CONFLICT_409
245 it('Should fail if we add a user with the same email', async function () {
246 const fields = { ...baseCorrectParams, email: 'user1@example.com' }
248 await makePostBodyRequest({
251 token: server.accessToken,
253 statusCodeExpected: HttpStatusCode.CONFLICT_409
257 it('Should fail without a videoQuota', async function () {
258 const fields = omit(baseCorrectParams, 'videoQuota')
260 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
263 it('Should fail without a videoQuotaDaily', async function () {
264 const fields = omit(baseCorrectParams, 'videoQuotaDaily')
266 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
269 it('Should fail with an invalid videoQuota', async function () {
270 const fields = { ...baseCorrectParams, videoQuota: -5 }
272 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
275 it('Should fail with an invalid videoQuotaDaily', async function () {
276 const fields = { ...baseCorrectParams, videoQuotaDaily: -7 }
278 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
281 it('Should fail without a user role', async function () {
282 const fields = omit(baseCorrectParams, 'role')
284 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
287 it('Should fail with an invalid user role', async function () {
288 const fields = { ...baseCorrectParams, role: 88989 }
290 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
293 it('Should fail with a "peertube" username', async function () {
294 const fields = { ...baseCorrectParams, username: 'peertube' }
296 await makePostBodyRequest({
299 token: server.accessToken,
301 statusCodeExpected: HttpStatusCode.CONFLICT_409
305 it('Should fail to create a moderator or an admin with a moderator', async function () {
306 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
307 const fields = { ...baseCorrectParams, role }
309 await makePostBodyRequest({
312 token: moderatorToken,
314 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
319 it('Should succeed to create a user with a moderator', async function () {
320 const fields = { ...baseCorrectParams, username: 'a4656', email: 'a4656@example.com', role: UserRole.USER }
322 await makePostBodyRequest({
325 token: moderatorToken,
327 statusCodeExpected: HttpStatusCode.OK_200
331 it('Should succeed with the correct params', async function () {
332 await makePostBodyRequest({
335 token: server.accessToken,
336 fields: baseCorrectParams,
337 statusCodeExpected: HttpStatusCode.OK_200
341 it('Should fail with a non admin user', async function () {
342 const user = { username: 'user1' }
343 userToken = await server.login.getAccessToken(user)
347 email: 'test@example.com',
348 password: 'my super password',
351 await makePostBodyRequest({ url: server.url, path, token: userToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
355 describe('When updating my account', function () {
357 it('Should fail with an invalid email attribute', async function () {
362 await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields })
365 it('Should fail with a too small password', async function () {
367 currentPassword: 'password',
371 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
374 it('Should fail with a too long password', async function () {
376 currentPassword: 'password',
377 password: 'super'.repeat(61)
380 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
383 it('Should fail without the current password', async function () {
385 currentPassword: 'password',
386 password: 'super'.repeat(61)
389 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
392 it('Should fail with an invalid current password', async function () {
394 currentPassword: 'my super password fail',
395 password: 'super'.repeat(61)
398 await makePutBodyRequest({
403 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
407 it('Should fail with an invalid NSFW policy attribute', async function () {
412 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
415 it('Should fail with an invalid autoPlayVideo attribute', async function () {
420 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
423 it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
425 autoPlayNextVideo: -1
428 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
431 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
433 videosHistoryEnabled: -1
436 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
439 it('Should fail with an non authenticated user', async function () {
441 currentPassword: 'password',
442 password: 'my super password'
445 await makePutBodyRequest({
448 token: 'super token',
450 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
454 it('Should fail with a too long description', async function () {
456 description: 'super'.repeat(201)
459 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
462 it('Should fail with an invalid videoLanguages attribute', async function () {
465 videoLanguages: 'toto'
468 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
473 for (let i = 0; i < 1000; i++) {
478 videoLanguages: languages
481 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
485 it('Should fail with an invalid theme', async function () {
486 const fields = { theme: 'invalid' }
487 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
490 it('Should fail with an unknown theme', async function () {
491 const fields = { theme: 'peertube-theme-unknown' }
492 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
495 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
497 noInstanceConfigWarningModal: -1
500 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
503 it('Should fail with an invalid noWelcomeModal attribute', async function () {
508 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
511 it('Should succeed to change password with the correct params', async function () {
513 currentPassword: 'password',
514 password: 'my super password',
516 autoPlayVideo: false,
517 email: 'super_email@example.com',
519 noInstanceConfigWarningModal: true,
523 await makePutBodyRequest({
528 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
532 it('Should succeed without password change with the correct params', async function () {
538 await makePutBodyRequest({
543 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
548 describe('When updating my avatar', function () {
549 it('Should fail without an incorrect input file', async function () {
552 avatarfile: buildAbsoluteFixturePath('video_short.mp4')
554 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
557 it('Should fail with a big file', async function () {
560 avatarfile: buildAbsoluteFixturePath('avatar-big.png')
562 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
565 it('Should fail with an unauthenticated user', async function () {
568 avatarfile: buildAbsoluteFixturePath('avatar.png')
570 await makeUploadRequest({
572 path: path + '/me/avatar/pick',
575 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
579 it('Should succeed with the correct params', async function () {
582 avatarfile: buildAbsoluteFixturePath('avatar.png')
584 await makeUploadRequest({
586 path: path + '/me/avatar/pick',
587 token: server.accessToken,
590 statusCodeExpected: HttpStatusCode.OK_200
595 describe('When managing my scoped tokens', function () {
597 it('Should fail to get my scoped tokens with an non authenticated user', async function () {
598 await server.users.getMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
601 it('Should fail to get my scoped tokens with a bad token', async function () {
602 await server.users.getMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
606 it('Should succeed to get my scoped tokens', async function () {
607 await server.users.getMyScopedTokens()
610 it('Should fail to renew my scoped tokens with an non authenticated user', async function () {
611 await server.users.renewMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
614 it('Should fail to renew my scoped tokens with a bad token', async function () {
615 await server.users.renewMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
618 it('Should succeed to renew my scoped tokens', async function () {
619 await server.users.renewMyScopedTokens()
623 describe('When getting a user', function () {
625 it('Should fail with an non authenticated user', async function () {
626 await makeGetRequest({
629 token: 'super token',
630 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
634 it('Should fail with a non admin user', async function () {
635 await makeGetRequest({ url: server.url, path, token: userToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
638 it('Should succeed with the correct params', async function () {
639 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: HttpStatusCode.OK_200 })
643 describe('When updating a user', function () {
645 it('Should fail with an invalid email attribute', async function () {
650 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
653 it('Should fail with an invalid emailVerified attribute', async function () {
658 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
661 it('Should fail with an invalid videoQuota attribute', async function () {
666 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
669 it('Should fail with an invalid user role attribute', async function () {
674 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
677 it('Should fail with a too small password', async function () {
679 currentPassword: 'password',
683 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
686 it('Should fail with a too long password', async function () {
688 currentPassword: 'password',
689 password: 'super'.repeat(61)
692 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
695 it('Should fail with an non authenticated user', async function () {
700 await makePutBodyRequest({
703 token: 'super token',
705 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
709 it('Should fail when updating root role', async function () {
711 role: UserRole.MODERATOR
714 await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
717 it('Should fail with invalid admin flags', async function () {
718 const fields = { adminFlags: 'toto' }
720 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
723 it('Should fail to update an admin with a moderator', async function () {
728 await makePutBodyRequest({
730 path: path + moderatorId,
731 token: moderatorToken,
733 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
737 it('Should succeed to update a user with a moderator', async function () {
742 await makePutBodyRequest({
745 token: moderatorToken,
747 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
751 it('Should succeed with the correct params', async function () {
753 email: 'email@example.com',
759 await makePutBodyRequest({
762 token: server.accessToken,
764 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
769 describe('When getting my information', function () {
770 it('Should fail with a non authenticated user', async function () {
771 await server.users.getMyInfo({ token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
774 it('Should success with the correct parameters', async function () {
775 await server.users.getMyInfo({ token: userToken })
779 describe('When getting my video rating', function () {
780 let command: UsersCommand
783 command = server.users
786 it('Should fail with a non authenticated user', async function () {
787 await command.getMyRating({ token: 'fake_token', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
790 it('Should fail with an incorrect video uuid', async function () {
791 await command.getMyRating({ videoId: 'blabla', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
794 it('Should fail with an unknown video', async function () {
795 await command.getMyRating({ videoId: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
798 it('Should succeed with the correct parameters', async function () {
799 await command.getMyRating({ videoId: video.id })
800 await command.getMyRating({ videoId: video.uuid })
801 await command.getMyRating({ videoId: video.shortUUID })
805 describe('When retrieving my global ratings', function () {
806 const path = '/api/v1/accounts/user1/ratings'
808 it('Should fail with a bad start pagination', async function () {
809 await checkBadStartPagination(server.url, path, userToken)
812 it('Should fail with a bad count pagination', async function () {
813 await checkBadCountPagination(server.url, path, userToken)
816 it('Should fail with an incorrect sort', async function () {
817 await checkBadSortPagination(server.url, path, userToken)
820 it('Should fail with a unauthenticated user', async function () {
821 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
824 it('Should fail with a another user', async function () {
825 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
828 it('Should fail with a bad type', async function () {
829 await makeGetRequest({
833 query: { rating: 'toto ' },
834 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
838 it('Should succeed with the correct params', async function () {
839 await makeGetRequest({ url: server.url, path, token: userToken, statusCodeExpected: HttpStatusCode.OK_200 })
843 describe('When blocking/unblocking/removing user', function () {
845 it('Should fail with an incorrect id', async function () {
846 const options = { userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
848 await server.users.remove(options)
849 await server.users.banUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
850 await server.users.unbanUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
853 it('Should fail with the root user', async function () {
854 const options = { userId: rootId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
856 await server.users.remove(options)
857 await server.users.banUser(options)
858 await server.users.unbanUser(options)
861 it('Should return 404 with a non existing id', async function () {
862 const options = { userId: 4545454, expectedStatus: HttpStatusCode.NOT_FOUND_404 }
864 await server.users.remove(options)
865 await server.users.banUser(options)
866 await server.users.unbanUser(options)
869 it('Should fail with a non admin user', async function () {
870 const options = { userId, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }
872 await server.users.remove(options)
873 await server.users.banUser(options)
874 await server.users.unbanUser(options)
877 it('Should fail on a moderator with a moderator', async function () {
878 const options = { userId: moderatorId, token: moderatorToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }
880 await server.users.remove(options)
881 await server.users.banUser(options)
882 await server.users.unbanUser(options)
885 it('Should succeed on a user with a moderator', async function () {
886 const options = { userId, token: moderatorToken }
888 await server.users.banUser(options)
889 await server.users.unbanUser(options)
893 describe('When deleting our account', function () {
894 it('Should fail with with the root account', async function () {
895 await server.users.deleteMe({ expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
899 describe('When registering a new user', function () {
900 const registrationPath = path + '/register'
901 const baseCorrectParams = {
903 displayName: 'super user',
904 email: 'test3@example.com',
905 password: 'my super password'
908 it('Should fail with a too small username', async function () {
909 const fields = { ...baseCorrectParams, username: '' }
911 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
914 it('Should fail with a too long username', async function () {
915 const fields = { ...baseCorrectParams, username: 'super'.repeat(50) }
917 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
920 it('Should fail with an incorrect username', async function () {
921 const fields = { ...baseCorrectParams, username: 'my username' }
923 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
926 it('Should fail with a missing email', async function () {
927 const fields = omit(baseCorrectParams, 'email')
929 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
932 it('Should fail with an invalid email', async function () {
933 const fields = { ...baseCorrectParams, email: 'test_example.com' }
935 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
938 it('Should fail with a too small password', async function () {
939 const fields = { ...baseCorrectParams, password: 'bla' }
941 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
944 it('Should fail with a too long password', async function () {
945 const fields = { ...baseCorrectParams, password: 'super'.repeat(61) }
947 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
950 it('Should fail if we register a user with the same username', async function () {
951 const fields = { ...baseCorrectParams, username: 'root' }
953 await makePostBodyRequest({
955 path: registrationPath,
956 token: server.accessToken,
958 statusCodeExpected: HttpStatusCode.CONFLICT_409
962 it('Should fail with a "peertube" username', async function () {
963 const fields = { ...baseCorrectParams, username: 'peertube' }
965 await makePostBodyRequest({
967 path: registrationPath,
968 token: server.accessToken,
970 statusCodeExpected: HttpStatusCode.CONFLICT_409
974 it('Should fail if we register a user with the same email', async function () {
975 const fields = { ...baseCorrectParams, email: 'admin' + server.internalServerNumber + '@example.com' }
977 await makePostBodyRequest({
979 path: registrationPath,
980 token: server.accessToken,
982 statusCodeExpected: HttpStatusCode.CONFLICT_409
986 it('Should fail with a bad display name', async function () {
987 const fields = { ...baseCorrectParams, displayName: 'a'.repeat(150) }
989 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
992 it('Should fail with a bad channel name', async function () {
993 const fields = { ...baseCorrectParams, channel: { name: '[]azf', displayName: 'toto' } }
995 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
998 it('Should fail with a bad channel display name', async function () {
999 const fields = { ...baseCorrectParams, channel: { name: 'toto', displayName: '' } }
1001 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1004 it('Should fail with a channel name that is the same as username', async function () {
1005 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
1006 const fields = { ...baseCorrectParams, ...source }
1008 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1011 it('Should fail with an existing channel', async function () {
1012 const attributes = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
1013 await server.channels.create({ attributes })
1015 const fields = { ...baseCorrectParams, channel: { name: 'existing_channel', displayName: 'toto' } }
1017 await makePostBodyRequest({
1019 path: registrationPath,
1020 token: server.accessToken,
1022 statusCodeExpected: HttpStatusCode.CONFLICT_409
1026 it('Should succeed with the correct params', async function () {
1027 const fields = { ...baseCorrectParams, channel: { name: 'super_channel', displayName: 'toto' } }
1029 await makePostBodyRequest({
1031 path: registrationPath,
1032 token: server.accessToken,
1034 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1038 it('Should fail on a server with registration disabled', async function () {
1041 email: 'test4@example.com',
1042 password: 'my super password 4'
1045 await makePostBodyRequest({
1046 url: serverWithRegistrationDisabled.url,
1047 path: registrationPath,
1048 token: serverWithRegistrationDisabled.accessToken,
1050 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
1055 describe('When registering multiple users on a server with users limit', function () {
1056 it('Should fail when after 3 registrations', async function () {
1057 await server.users.register({ username: 'user42', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
1061 describe('When asking a password reset', function () {
1062 const path = '/api/v1/users/ask-reset-password'
1064 it('Should fail with a missing email', async function () {
1067 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1070 it('Should fail with an invalid email', async function () {
1071 const fields = { email: 'hello' }
1073 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1076 it('Should success with the correct params', async function () {
1077 const fields = { email: 'admin@example.com' }
1079 await makePostBodyRequest({
1082 token: server.accessToken,
1084 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1089 describe('When asking for an account verification email', function () {
1090 const path = '/api/v1/users/ask-send-verify-email'
1092 it('Should fail with a missing email', async function () {
1095 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1098 it('Should fail with an invalid email', async function () {
1099 const fields = { email: 'hello' }
1101 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1104 it('Should succeed with the correct params', async function () {
1105 const fields = { email: 'admin@example.com' }
1107 await makePostBodyRequest({
1110 token: server.accessToken,
1112 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1117 after(async function () {
1118 MockSmtpServer.Instance.kill()
1120 await cleanupTests([ server, serverWithRegistrationDisabled ])