1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { omit } from 'lodash'
6 import { join } from 'path'
7 import { User, UserRole, VideoImport, VideoImportState } from '../../../../shared'
27 renewUserScopedTokens,
30 setAccessTokensToServers,
35 } from '../../../../shared/extra-utils'
36 import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
38 checkBadCountPagination,
39 checkBadSortPagination,
40 checkBadStartPagination
41 } from '../../../../shared/extra-utils/requests/check-api-params'
42 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
43 import { getGoodVideoUrl, getMagnetURI, getMyVideoImports, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
44 import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
45 import { VideoPrivacy } from '../../../../shared/models/videos'
46 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
48 describe('Test users API validators', function () {
49 const path = '/api/v1/users/'
52 let moderatorId: number
54 let server: ServerInfo
55 let serverWithRegistrationDisabled: ServerInfo
56 let userAccessToken = ''
57 let moderatorAccessToken = ''
59 let overrideConfig: Object
61 // ---------------------------------------------------------------
63 before(async function () {
66 const emails: object[] = []
67 emailPort = await MockSmtpServer.Instance.collectEmails(emails)
69 overrideConfig = { signup: { limit: 8 } }
72 const res = await Promise.all([
73 flushAndRunServer(1, overrideConfig),
78 serverWithRegistrationDisabled = res[1]
80 await setAccessTokensToServers([ server ])
86 password: 'my super password'
89 const videoQuota = 42000000
92 accessToken: server.accessToken,
93 username: user.username,
94 password: user.password,
95 videoQuota: videoQuota
97 userAccessToken = await userLogin(server, user)
102 username: 'moderator1',
103 password: 'super password'
108 accessToken: server.accessToken,
109 username: moderator.username,
110 password: moderator.password,
111 role: UserRole.MODERATOR
114 moderatorAccessToken = await userLogin(server, moderator)
119 username: 'moderator2',
120 password: 'super password'
125 accessToken: server.accessToken,
126 username: moderator.username,
127 password: moderator.password,
128 role: UserRole.MODERATOR
133 const res = await uploadVideo(server.url, server.accessToken, {})
134 videoId = res.body.video.id
138 const res = await getUsersList(server.url, server.accessToken)
139 const users: User[] = res.body.data
141 userId = users.find(u => u.username === 'user1').id
142 rootId = users.find(u => u.username === 'root').id
143 moderatorId = users.find(u => u.username === 'moderator2').id
147 describe('When listing users', function () {
148 it('Should fail with a bad start pagination', async function () {
149 await checkBadStartPagination(server.url, path, server.accessToken)
152 it('Should fail with a bad count pagination', async function () {
153 await checkBadCountPagination(server.url, path, server.accessToken)
156 it('Should fail with an incorrect sort', async function () {
157 await checkBadSortPagination(server.url, path, server.accessToken)
160 it('Should fail with a non authenticated user', async function () {
161 await makeGetRequest({
164 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
168 it('Should fail with a non admin user', async function () {
169 await makeGetRequest({
172 token: userAccessToken,
173 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
178 describe('When adding a new user', function () {
179 const baseCorrectParams = {
181 email: 'test@example.com',
182 password: 'my super password',
186 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
189 it('Should fail with a too small username', async function () {
190 const fields = immutableAssign(baseCorrectParams, { username: '' })
192 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
195 it('Should fail with a too long username', async function () {
196 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
198 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
201 it('Should fail with a not lowercase username', async function () {
202 const fields = immutableAssign(baseCorrectParams, { username: 'Toto' })
204 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
207 it('Should fail with an incorrect username', async function () {
208 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
210 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
213 it('Should fail with a missing email', async function () {
214 const fields = omit(baseCorrectParams, 'email')
216 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
219 it('Should fail with an invalid email', async function () {
220 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
222 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
225 it('Should fail with a too small password', async function () {
226 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
228 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
231 it('Should fail with a too long password', async function () {
232 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
234 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
237 it('Should fail with empty password and no smtp configured', async function () {
238 const fields = immutableAssign(baseCorrectParams, { password: '' })
240 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
243 it('Should succeed with no password on a server with smtp enabled', async function () {
246 killallServers([ server ])
248 const config = immutableAssign(overrideConfig, {
250 hostname: 'localhost',
254 await reRunServer(server, config)
256 const fields = immutableAssign(baseCorrectParams, {
258 username: 'create_password',
259 email: 'create_password@example.com'
262 await makePostBodyRequest({
265 token: server.accessToken,
267 statusCodeExpected: HttpStatusCode.OK_200
271 it('Should fail with invalid admin flags', async function () {
272 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' })
274 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
277 it('Should fail with an non authenticated user', async function () {
278 await makePostBodyRequest({
281 token: 'super token',
282 fields: baseCorrectParams,
283 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
287 it('Should fail if we add a user with the same username', async function () {
288 const fields = immutableAssign(baseCorrectParams, { username: 'user1' })
290 await makePostBodyRequest({
293 token: server.accessToken,
295 statusCodeExpected: HttpStatusCode.CONFLICT_409
299 it('Should fail if we add a user with the same email', async function () {
300 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' })
302 await makePostBodyRequest({
305 token: server.accessToken,
307 statusCodeExpected: HttpStatusCode.CONFLICT_409
311 it('Should fail without a videoQuota', async function () {
312 const fields = omit(baseCorrectParams, 'videoQuota')
314 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
317 it('Should fail without a videoQuotaDaily', async function () {
318 const fields = omit(baseCorrectParams, 'videoQuotaDaily')
320 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
323 it('Should fail with an invalid videoQuota', async function () {
324 const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 })
326 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
329 it('Should fail with an invalid videoQuotaDaily', async function () {
330 const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 })
332 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
335 it('Should fail without a user role', async function () {
336 const fields = omit(baseCorrectParams, 'role')
338 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
341 it('Should fail with an invalid user role', async function () {
342 const fields = immutableAssign(baseCorrectParams, { role: 88989 })
344 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
347 it('Should fail with a "peertube" username', async function () {
348 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
350 await makePostBodyRequest({
353 token: server.accessToken,
355 statusCodeExpected: HttpStatusCode.CONFLICT_409
359 it('Should fail to create a moderator or an admin with a moderator', async function () {
360 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
361 const fields = immutableAssign(baseCorrectParams, { role })
363 await makePostBodyRequest({
366 token: moderatorAccessToken,
368 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
373 it('Should succeed to create a user with a moderator', async function () {
374 const fields = immutableAssign(baseCorrectParams, { username: 'a4656', email: 'a4656@example.com', role: UserRole.USER })
376 await makePostBodyRequest({
379 token: moderatorAccessToken,
381 statusCodeExpected: HttpStatusCode.OK_200
385 it('Should succeed with the correct params', async function () {
386 await makePostBodyRequest({
389 token: server.accessToken,
390 fields: baseCorrectParams,
391 statusCodeExpected: HttpStatusCode.OK_200
395 it('Should fail with a non admin user', async function () {
398 password: 'my super password'
400 userAccessToken = await userLogin(server, user)
404 email: 'test@example.com',
405 password: 'my super password',
408 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
412 describe('When updating my account', function () {
413 it('Should fail with an invalid email attribute', async function () {
418 await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields })
421 it('Should fail with a too small password', async function () {
423 currentPassword: 'my super password',
427 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
430 it('Should fail with a too long password', async function () {
432 currentPassword: 'my super password',
433 password: 'super'.repeat(61)
436 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
439 it('Should fail without the current password', async function () {
441 currentPassword: 'my super password',
442 password: 'super'.repeat(61)
445 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
448 it('Should fail with an invalid current password', async function () {
450 currentPassword: 'my super password fail',
451 password: 'super'.repeat(61)
454 await makePutBodyRequest({
457 token: userAccessToken,
459 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
463 it('Should fail with an invalid NSFW policy attribute', async function () {
468 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
471 it('Should fail with an invalid autoPlayVideo attribute', async function () {
476 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
479 it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
481 autoPlayNextVideo: -1
484 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
487 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
489 videosHistoryEnabled: -1
492 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
495 it('Should fail with an non authenticated user', async function () {
497 currentPassword: 'my super password',
498 password: 'my super password'
501 await makePutBodyRequest({
504 token: 'super token',
506 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
510 it('Should fail with a too long description', async function () {
512 description: 'super'.repeat(201)
515 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
518 it('Should fail with an invalid videoLanguages attribute', async function () {
521 videoLanguages: 'toto'
524 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
529 for (let i = 0; i < 1000; i++) {
534 videoLanguages: languages
537 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
541 it('Should fail with an invalid theme', async function () {
542 const fields = { theme: 'invalid' }
543 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
546 it('Should fail with an unknown theme', async function () {
547 const fields = { theme: 'peertube-theme-unknown' }
548 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
551 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
553 noInstanceConfigWarningModal: -1
556 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
559 it('Should fail with an invalid noWelcomeModal attribute', async function () {
564 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
567 it('Should succeed to change password with the correct params', async function () {
569 currentPassword: 'my super password',
570 password: 'my super password',
572 autoPlayVideo: false,
573 email: 'super_email@example.com',
575 noInstanceConfigWarningModal: true,
579 await makePutBodyRequest({
582 token: userAccessToken,
584 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
588 it('Should succeed without password change with the correct params', async function () {
594 await makePutBodyRequest({
597 token: userAccessToken,
599 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
604 describe('When updating my avatar', function () {
605 it('Should fail without an incorrect input file', async function () {
608 avatarfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
610 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
613 it('Should fail with a big file', async function () {
616 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
618 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
621 it('Should fail with an unauthenticated user', async function () {
624 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
626 await makeUploadRequest({
628 path: path + '/me/avatar/pick',
631 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
635 it('Should succeed with the correct params', async function () {
638 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
640 await makeUploadRequest({
642 path: path + '/me/avatar/pick',
643 token: server.accessToken,
646 statusCodeExpected: HttpStatusCode.OK_200
651 describe('When managing my scoped tokens', function () {
653 it('Should fail to get my scoped tokens with an non authenticated user', async function () {
654 await getUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401)
657 it('Should fail to get my scoped tokens with a bad token', async function () {
658 await getUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401)
662 it('Should succeed to get my scoped tokens', async function () {
663 await getUserScopedTokens(server.url, server.accessToken)
666 it('Should fail to renew my scoped tokens with an non authenticated user', async function () {
667 await renewUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401)
670 it('Should fail to renew my scoped tokens with a bad token', async function () {
671 await renewUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401)
674 it('Should succeed to renew my scoped tokens', async function () {
675 await renewUserScopedTokens(server.url, server.accessToken)
679 describe('When getting a user', function () {
681 it('Should fail with an non authenticated user', async function () {
682 await makeGetRequest({
685 token: 'super token',
686 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
690 it('Should fail with a non admin user', async function () {
691 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
694 it('Should succeed with the correct params', async function () {
695 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: HttpStatusCode.OK_200 })
699 describe('When updating a user', function () {
701 it('Should fail with an invalid email attribute', async function () {
706 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
709 it('Should fail with an invalid emailVerified attribute', async function () {
714 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
717 it('Should fail with an invalid videoQuota attribute', async function () {
722 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
725 it('Should fail with an invalid user role attribute', async function () {
730 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
733 it('Should fail with a too small password', async function () {
735 currentPassword: 'my super password',
739 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
742 it('Should fail with a too long password', async function () {
744 currentPassword: 'my super password',
745 password: 'super'.repeat(61)
748 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
751 it('Should fail with an non authenticated user', async function () {
756 await makePutBodyRequest({
759 token: 'super token',
761 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
765 it('Should fail when updating root role', async function () {
767 role: UserRole.MODERATOR
770 await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
773 it('Should fail with invalid admin flags', async function () {
774 const fields = { adminFlags: 'toto' }
776 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
779 it('Should fail to update an admin with a moderator', async function () {
784 await makePutBodyRequest({
786 path: path + moderatorId,
787 token: moderatorAccessToken,
789 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
793 it('Should succeed to update a user with a moderator', async function () {
798 await makePutBodyRequest({
801 token: moderatorAccessToken,
803 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
807 it('Should succeed with the correct params', async function () {
809 email: 'email@example.com',
815 await makePutBodyRequest({
818 token: server.accessToken,
820 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
825 describe('When getting my information', function () {
826 it('Should fail with a non authenticated user', async function () {
827 await getMyUserInformation(server.url, 'fake_token', HttpStatusCode.UNAUTHORIZED_401)
830 it('Should success with the correct parameters', async function () {
831 await getMyUserInformation(server.url, userAccessToken)
835 describe('When getting my video rating', function () {
836 it('Should fail with a non authenticated user', async function () {
837 await getMyUserVideoRating(server.url, 'fake_token', videoId, HttpStatusCode.UNAUTHORIZED_401)
840 it('Should fail with an incorrect video uuid', async function () {
841 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', HttpStatusCode.BAD_REQUEST_400)
844 it('Should fail with an unknown video', async function () {
845 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
848 it('Should succeed with the correct parameters', async function () {
849 await getMyUserVideoRating(server.url, server.accessToken, videoId)
853 describe('When retrieving my global ratings', function () {
854 const path = '/api/v1/accounts/user1/ratings'
856 it('Should fail with a bad start pagination', async function () {
857 await checkBadStartPagination(server.url, path, userAccessToken)
860 it('Should fail with a bad count pagination', async function () {
861 await checkBadCountPagination(server.url, path, userAccessToken)
864 it('Should fail with an incorrect sort', async function () {
865 await checkBadSortPagination(server.url, path, userAccessToken)
868 it('Should fail with a unauthenticated user', async function () {
869 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
872 it('Should fail with a another user', async function () {
873 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
876 it('Should fail with a bad type', async function () {
877 await makeGetRequest({
880 token: userAccessToken,
881 query: { rating: 'toto ' },
882 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
886 it('Should succeed with the correct params', async function () {
887 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.OK_200 })
891 describe('When blocking/unblocking/removing user', function () {
892 it('Should fail with an incorrect id', async function () {
893 await removeUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
894 await blockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
895 await unblockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
898 it('Should fail with the root user', async function () {
899 await removeUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
900 await blockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
901 await unblockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
904 it('Should return 404 with a non existing id', async function () {
905 await removeUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
906 await blockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
907 await unblockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
910 it('Should fail with a non admin user', async function () {
911 await removeUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
912 await blockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
913 await unblockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
916 it('Should fail on a moderator with a moderator', async function () {
917 await removeUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
918 await blockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
919 await unblockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
922 it('Should succeed on a user with a moderator', async function () {
923 await blockUser(server.url, userId, moderatorAccessToken)
924 await unblockUser(server.url, userId, moderatorAccessToken)
928 describe('When deleting our account', function () {
929 it('Should fail with with the root account', async function () {
930 await deleteMe(server.url, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
934 describe('When registering a new user', function () {
935 const registrationPath = path + '/register'
936 const baseCorrectParams = {
938 displayName: 'super user',
939 email: 'test3@example.com',
940 password: 'my super password'
943 it('Should fail with a too small username', async function () {
944 const fields = immutableAssign(baseCorrectParams, { username: '' })
946 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
949 it('Should fail with a too long username', async function () {
950 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
952 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
955 it('Should fail with an incorrect username', async function () {
956 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
958 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
961 it('Should fail with a missing email', async function () {
962 const fields = omit(baseCorrectParams, 'email')
964 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
967 it('Should fail with an invalid email', async function () {
968 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
970 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
973 it('Should fail with a too small password', async function () {
974 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
976 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
979 it('Should fail with a too long password', async function () {
980 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
982 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
985 it('Should fail if we register a user with the same username', async function () {
986 const fields = immutableAssign(baseCorrectParams, { username: 'root' })
988 await makePostBodyRequest({
990 path: registrationPath,
991 token: server.accessToken,
993 statusCodeExpected: HttpStatusCode.CONFLICT_409
997 it('Should fail with a "peertube" username', async function () {
998 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
1000 await makePostBodyRequest({
1002 path: registrationPath,
1003 token: server.accessToken,
1005 statusCodeExpected: HttpStatusCode.CONFLICT_409
1009 it('Should fail if we register a user with the same email', async function () {
1010 const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' })
1012 await makePostBodyRequest({
1014 path: registrationPath,
1015 token: server.accessToken,
1017 statusCodeExpected: HttpStatusCode.CONFLICT_409
1021 it('Should fail with a bad display name', async function () {
1022 const fields = immutableAssign(baseCorrectParams, { displayName: 'a'.repeat(150) })
1024 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1027 it('Should fail with a bad channel name', async function () {
1028 const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } })
1030 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1033 it('Should fail with a bad channel display name', async function () {
1034 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } })
1036 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1039 it('Should fail with a channel name that is the same as username', async function () {
1040 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
1041 const fields = immutableAssign(baseCorrectParams, source)
1043 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1046 it('Should fail with an existing channel', async function () {
1047 const videoChannelAttributesArg = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
1048 await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg)
1050 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } })
1052 await makePostBodyRequest({
1054 path: registrationPath,
1055 token: server.accessToken,
1057 statusCodeExpected: HttpStatusCode.CONFLICT_409
1061 it('Should succeed with the correct params', async function () {
1062 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } })
1064 await makePostBodyRequest({
1066 path: registrationPath,
1067 token: server.accessToken,
1069 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1073 it('Should fail on a server with registration disabled', async function () {
1076 email: 'test4@example.com',
1077 password: 'my super password 4'
1080 await makePostBodyRequest({
1081 url: serverWithRegistrationDisabled.url,
1082 path: registrationPath,
1083 token: serverWithRegistrationDisabled.accessToken,
1085 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
1090 describe('When registering multiple users on a server with users limit', function () {
1091 it('Should fail when after 3 registrations', async function () {
1092 await registerUser(server.url, 'user42', 'super password', HttpStatusCode.FORBIDDEN_403)
1096 describe('When having a video quota', function () {
1097 it('Should fail with a user having too many videos', async function () {
1101 accessToken: server.accessToken,
1105 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413)
1108 it('Should fail with a registered user having too many videos', async function () {
1113 password: 'my super password'
1115 userAccessToken = await userLogin(server, user)
1117 const videoAttributes = { fixture: 'video_short2.webm' }
1118 await uploadVideo(server.url, userAccessToken, videoAttributes)
1119 await uploadVideo(server.url, userAccessToken, videoAttributes)
1120 await uploadVideo(server.url, userAccessToken, videoAttributes)
1121 await uploadVideo(server.url, userAccessToken, videoAttributes)
1122 await uploadVideo(server.url, userAccessToken, videoAttributes)
1123 await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413)
1126 it('Should fail to import with HTTP/Torrent/magnet', async function () {
1127 this.timeout(120000)
1129 const baseAttributes = {
1131 privacy: VideoPrivacy.PUBLIC
1133 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getGoodVideoUrl() }))
1134 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() }))
1135 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' as any }))
1137 await waitJobs([ server ])
1139 const res = await getMyVideoImports(server.url, server.accessToken)
1141 expect(res.body.total).to.equal(3)
1142 const videoImports: VideoImport[] = res.body.data
1143 expect(videoImports).to.have.lengthOf(3)
1145 for (const videoImport of videoImports) {
1146 expect(videoImport.state.id).to.equal(VideoImportState.FAILED)
1147 expect(videoImport.error).not.to.be.undefined
1148 expect(videoImport.error).to.contain('user video quota is exceeded')
1153 describe('When having a daily video quota', function () {
1154 it('Should fail with a user having too many videos daily', async function () {
1158 accessToken: server.accessToken,
1162 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413)
1166 describe('When having an absolute and daily video quota', function () {
1167 it('Should fail if exceeding total quota', async function () {
1171 accessToken: server.accessToken,
1173 videoQuotaDaily: 1024 * 1024 * 1024
1176 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413)
1179 it('Should fail if exceeding daily quota', async function () {
1183 accessToken: server.accessToken,
1184 videoQuota: 1024 * 1024 * 1024,
1188 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413)
1192 describe('When asking a password reset', function () {
1193 const path = '/api/v1/users/ask-reset-password'
1195 it('Should fail with a missing email', async function () {
1198 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1201 it('Should fail with an invalid email', async function () {
1202 const fields = { email: 'hello' }
1204 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1207 it('Should success with the correct params', async function () {
1208 const fields = { email: 'admin@example.com' }
1210 await makePostBodyRequest({
1213 token: server.accessToken,
1215 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1220 describe('When asking for an account verification email', function () {
1221 const path = '/api/v1/users/ask-send-verify-email'
1223 it('Should fail with a missing email', async function () {
1226 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1229 it('Should fail with an invalid email', async function () {
1230 const fields = { email: 'hello' }
1232 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1235 it('Should succeed with the correct params', async function () {
1236 const fields = { email: 'admin@example.com' }
1238 await makePostBodyRequest({
1241 token: server.accessToken,
1243 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1248 after(async function () {
1249 MockSmtpServer.Instance.kill()
1251 await cleanupTests([ server, serverWithRegistrationDisabled ])