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'
47 describe('Test users API validators', function () {
48 const path = '/api/v1/users/'
51 let moderatorId: number
53 let server: ServerInfo
54 let serverWithRegistrationDisabled: ServerInfo
55 let userAccessToken = ''
56 let moderatorAccessToken = ''
58 let overrideConfig: Object
60 // ---------------------------------------------------------------
62 before(async function () {
65 const emails: object[] = []
66 emailPort = await MockSmtpServer.Instance.collectEmails(emails)
68 overrideConfig = { signup: { limit: 8 } }
71 const res = await Promise.all([
72 flushAndRunServer(1, overrideConfig),
77 serverWithRegistrationDisabled = res[1]
79 await setAccessTokensToServers([ server ])
85 password: 'my super password'
88 const videoQuota = 42000000
91 accessToken: server.accessToken,
92 username: user.username,
93 password: user.password,
94 videoQuota: videoQuota
96 userAccessToken = await userLogin(server, user)
101 username: 'moderator1',
102 password: 'super password'
107 accessToken: server.accessToken,
108 username: moderator.username,
109 password: moderator.password,
110 role: UserRole.MODERATOR
113 moderatorAccessToken = await userLogin(server, moderator)
118 username: 'moderator2',
119 password: 'super password'
124 accessToken: server.accessToken,
125 username: moderator.username,
126 password: moderator.password,
127 role: UserRole.MODERATOR
132 const res = await uploadVideo(server.url, server.accessToken, {})
133 videoId = res.body.video.id
137 const res = await getUsersList(server.url, server.accessToken)
138 const users: User[] = res.body.data
140 userId = users.find(u => u.username === 'user1').id
141 rootId = users.find(u => u.username === 'root').id
142 moderatorId = users.find(u => u.username === 'moderator2').id
146 describe('When listing users', function () {
147 it('Should fail with a bad start pagination', async function () {
148 await checkBadStartPagination(server.url, path, server.accessToken)
151 it('Should fail with a bad count pagination', async function () {
152 await checkBadCountPagination(server.url, path, server.accessToken)
155 it('Should fail with an incorrect sort', async function () {
156 await checkBadSortPagination(server.url, path, server.accessToken)
159 it('Should fail with a non authenticated user', async function () {
160 await makeGetRequest({
163 statusCodeExpected: 401
167 it('Should fail with a non admin user', async function () {
168 await makeGetRequest({
171 token: userAccessToken,
172 statusCodeExpected: 403
177 describe('When adding a new user', function () {
178 const baseCorrectParams = {
180 email: 'test@example.com',
181 password: 'my super password',
185 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
188 it('Should fail with a too small username', async function () {
189 const fields = immutableAssign(baseCorrectParams, { username: '' })
191 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
194 it('Should fail with a too long username', async function () {
195 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
197 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
200 it('Should fail with a not lowercase username', async function () {
201 const fields = immutableAssign(baseCorrectParams, { username: 'Toto' })
203 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
206 it('Should fail with an incorrect username', async function () {
207 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
209 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
212 it('Should fail with a missing email', async function () {
213 const fields = omit(baseCorrectParams, 'email')
215 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
218 it('Should fail with an invalid email', async function () {
219 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
221 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
224 it('Should fail with a too small password', async function () {
225 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
227 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
230 it('Should fail with a too long password', async function () {
231 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
233 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
236 it('Should fail with empty password and no smtp configured', async function () {
237 const fields = immutableAssign(baseCorrectParams, { password: '' })
239 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
242 it('Should succeed with no password on a server with smtp enabled', async function () {
245 killallServers([ server ])
247 const config = immutableAssign(overrideConfig, {
249 hostname: 'localhost',
253 await reRunServer(server, config)
255 const fields = immutableAssign(baseCorrectParams, {
257 username: 'create_password',
258 email: 'create_password@example.com'
261 await makePostBodyRequest({
264 token: server.accessToken,
266 statusCodeExpected: 200
270 it('Should fail with invalid admin flags', async function () {
271 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' })
273 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
276 it('Should fail with an non authenticated user', async function () {
277 await makePostBodyRequest({
280 token: 'super token',
281 fields: baseCorrectParams,
282 statusCodeExpected: 401
286 it('Should fail if we add a user with the same username', async function () {
287 const fields = immutableAssign(baseCorrectParams, { username: 'user1' })
289 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
292 it('Should fail if we add a user with the same email', async function () {
293 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' })
295 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
298 it('Should fail without a videoQuota', async function () {
299 const fields = omit(baseCorrectParams, 'videoQuota')
301 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
304 it('Should fail without a videoQuotaDaily', async function () {
305 const fields = omit(baseCorrectParams, 'videoQuotaDaily')
307 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
310 it('Should fail with an invalid videoQuota', async function () {
311 const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 })
313 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
316 it('Should fail with an invalid videoQuotaDaily', async function () {
317 const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 })
319 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
322 it('Should fail without a user role', async function () {
323 const fields = omit(baseCorrectParams, 'role')
325 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
328 it('Should fail with an invalid user role', async function () {
329 const fields = immutableAssign(baseCorrectParams, { role: 88989 })
331 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
334 it('Should fail with a "peertube" username', async function () {
335 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
337 await makePostBodyRequest({
340 token: server.accessToken,
342 statusCodeExpected: 409
346 it('Should fail to create a moderator or an admin with a moderator', async function () {
347 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
348 const fields = immutableAssign(baseCorrectParams, { role })
350 await makePostBodyRequest({
353 token: moderatorAccessToken,
355 statusCodeExpected: 403
360 it('Should succeed to create a user with a moderator', async function () {
361 const fields = immutableAssign(baseCorrectParams, { username: 'a4656', email: 'a4656@example.com', role: UserRole.USER })
363 await makePostBodyRequest({
366 token: moderatorAccessToken,
368 statusCodeExpected: 200
372 it('Should succeed with the correct params', async function () {
373 await makePostBodyRequest({
376 token: server.accessToken,
377 fields: baseCorrectParams,
378 statusCodeExpected: 200
382 it('Should fail with a non admin user', async function () {
385 password: 'my super password'
387 userAccessToken = await userLogin(server, user)
391 email: 'test@example.com',
392 password: 'my super password',
395 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
399 describe('When updating my account', function () {
400 it('Should fail with an invalid email attribute', async function () {
405 await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields })
408 it('Should fail with a too small password', async function () {
410 currentPassword: 'my super password',
414 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
417 it('Should fail with a too long password', async function () {
419 currentPassword: 'my super password',
420 password: 'super'.repeat(61)
423 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
426 it('Should fail without the current password', async function () {
428 currentPassword: 'my super password',
429 password: 'super'.repeat(61)
432 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
435 it('Should fail with an invalid current password', async function () {
437 currentPassword: 'my super password fail',
438 password: 'super'.repeat(61)
441 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 401 })
444 it('Should fail with an invalid NSFW policy attribute', async function () {
449 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
452 it('Should fail with an invalid autoPlayVideo attribute', async function () {
457 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
460 it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
462 autoPlayNextVideo: -1
465 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
468 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
470 videosHistoryEnabled: -1
473 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
476 it('Should fail with an non authenticated user', async function () {
478 currentPassword: 'my super password',
479 password: 'my super password'
482 await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 })
485 it('Should fail with a too long description', async function () {
487 description: 'super'.repeat(201)
490 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
493 it('Should fail with an invalid videoLanguages attribute', async function () {
496 videoLanguages: 'toto'
499 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
504 for (let i = 0; i < 1000; i++) {
509 videoLanguages: languages
512 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
516 it('Should fail with an invalid theme', async function () {
517 const fields = { theme: 'invalid' }
518 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
521 it('Should fail with an unknown theme', async function () {
522 const fields = { theme: 'peertube-theme-unknown' }
523 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
526 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
528 noInstanceConfigWarningModal: -1
531 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
534 it('Should fail with an invalid noWelcomeModal attribute', async function () {
539 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
542 it('Should succeed to change password with the correct params', async function () {
544 currentPassword: 'my super password',
545 password: 'my super password',
547 autoPlayVideo: false,
548 email: 'super_email@example.com',
550 noInstanceConfigWarningModal: true,
554 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
557 it('Should succeed without password change with the correct params', async function () {
563 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
567 describe('When updating my avatar', function () {
568 it('Should fail without an incorrect input file', async function () {
571 avatarfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
573 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
576 it('Should fail with a big file', async function () {
579 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
581 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
584 it('Should fail with an unauthenticated user', async function () {
587 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
589 await makeUploadRequest({
591 path: path + '/me/avatar/pick',
594 statusCodeExpected: 401
598 it('Should succeed with the correct params', async function () {
601 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
603 await makeUploadRequest({
605 path: path + '/me/avatar/pick',
606 token: server.accessToken,
609 statusCodeExpected: 200
614 describe('When managing my scoped tokens', function () {
616 it('Should fail to get my scoped tokens with an non authenticated user', async function () {
617 await getUserScopedTokens(server.url, null, 401)
620 it('Should fail to get my scoped tokens with a bad token', async function () {
621 await getUserScopedTokens(server.url, 'bad', 401)
625 it('Should succeed to get my scoped tokens', async function () {
626 await getUserScopedTokens(server.url, server.accessToken)
629 it('Should fail to renew my scoped tokens with an non authenticated user', async function () {
630 await renewUserScopedTokens(server.url, null, 401)
633 it('Should fail to renew my scoped tokens with a bad token', async function () {
634 await renewUserScopedTokens(server.url, 'bad', 401)
637 it('Should succeed to renew my scoped tokens', async function () {
638 await renewUserScopedTokens(server.url, server.accessToken)
642 describe('When getting a user', function () {
644 it('Should fail with an non authenticated user', async function () {
645 await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 })
648 it('Should fail with a non admin user', async function () {
649 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 })
652 it('Should succeed with the correct params', async function () {
653 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 })
657 describe('When updating a user', function () {
659 it('Should fail with an invalid email attribute', async function () {
664 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
667 it('Should fail with an invalid emailVerified attribute', async function () {
672 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
675 it('Should fail with an invalid videoQuota attribute', async function () {
680 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
683 it('Should fail with an invalid user role attribute', async function () {
688 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
691 it('Should fail with a too small password', async function () {
693 currentPassword: 'my super password',
697 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
700 it('Should fail with a too long password', async function () {
702 currentPassword: 'my super password',
703 password: 'super'.repeat(61)
706 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
709 it('Should fail with an non authenticated user', async function () {
714 await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 })
717 it('Should fail when updating root role', async function () {
719 role: UserRole.MODERATOR
722 await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
725 it('Should fail with invalid admin flags', async function () {
726 const fields = { adminFlags: 'toto' }
728 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
731 it('Should fail to update an admin with a moderator', async function () {
736 await makePutBodyRequest({
738 path: path + moderatorId,
739 token: moderatorAccessToken,
741 statusCodeExpected: 403
745 it('Should succeed to update a user with a moderator', async function () {
750 await makePutBodyRequest({
753 token: moderatorAccessToken,
755 statusCodeExpected: 204
759 it('Should succeed with the correct params', async function () {
761 email: 'email@example.com',
767 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 })
771 describe('When getting my information', function () {
772 it('Should fail with a non authenticated user', async function () {
773 await getMyUserInformation(server.url, 'fake_token', 401)
776 it('Should success with the correct parameters', async function () {
777 await getMyUserInformation(server.url, userAccessToken)
781 describe('When getting my video rating', function () {
782 it('Should fail with a non authenticated user', async function () {
783 await getMyUserVideoRating(server.url, 'fake_token', videoId, 401)
786 it('Should fail with an incorrect video uuid', async function () {
787 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400)
790 it('Should fail with an unknown video', async function () {
791 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
794 it('Should succeed with the correct parameters', async function () {
795 await getMyUserVideoRating(server.url, server.accessToken, videoId)
799 describe('When retrieving my global ratings', function () {
800 const path = '/api/v1/accounts/user1/ratings'
802 it('Should fail with a bad start pagination', async function () {
803 await checkBadStartPagination(server.url, path, userAccessToken)
806 it('Should fail with a bad count pagination', async function () {
807 await checkBadCountPagination(server.url, path, userAccessToken)
810 it('Should fail with an incorrect sort', async function () {
811 await checkBadSortPagination(server.url, path, userAccessToken)
814 it('Should fail with a unauthenticated user', async function () {
815 await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 })
818 it('Should fail with a another user', async function () {
819 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 })
822 it('Should fail with a bad type', async function () {
823 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 })
826 it('Should succeed with the correct params', async function () {
827 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 })
831 describe('When blocking/unblocking/removing user', function () {
832 it('Should fail with an incorrect id', async function () {
833 await removeUser(server.url, 'blabla', server.accessToken, 400)
834 await blockUser(server.url, 'blabla', server.accessToken, 400)
835 await unblockUser(server.url, 'blabla', server.accessToken, 400)
838 it('Should fail with the root user', async function () {
839 await removeUser(server.url, rootId, server.accessToken, 400)
840 await blockUser(server.url, rootId, server.accessToken, 400)
841 await unblockUser(server.url, rootId, server.accessToken, 400)
844 it('Should return 404 with a non existing id', async function () {
845 await removeUser(server.url, 4545454, server.accessToken, 404)
846 await blockUser(server.url, 4545454, server.accessToken, 404)
847 await unblockUser(server.url, 4545454, server.accessToken, 404)
850 it('Should fail with a non admin user', async function () {
851 await removeUser(server.url, userId, userAccessToken, 403)
852 await blockUser(server.url, userId, userAccessToken, 403)
853 await unblockUser(server.url, userId, userAccessToken, 403)
856 it('Should fail on a moderator with a moderator', async function () {
857 await removeUser(server.url, moderatorId, moderatorAccessToken, 403)
858 await blockUser(server.url, moderatorId, moderatorAccessToken, 403)
859 await unblockUser(server.url, moderatorId, moderatorAccessToken, 403)
862 it('Should succeed on a user with a moderator', async function () {
863 await blockUser(server.url, userId, moderatorAccessToken)
864 await unblockUser(server.url, userId, moderatorAccessToken)
868 describe('When deleting our account', function () {
869 it('Should fail with with the root account', async function () {
870 await deleteMe(server.url, server.accessToken, 400)
874 describe('When registering a new user', function () {
875 const registrationPath = path + '/register'
876 const baseCorrectParams = {
878 displayName: 'super user',
879 email: 'test3@example.com',
880 password: 'my super password'
883 it('Should fail with a too small username', async function () {
884 const fields = immutableAssign(baseCorrectParams, { username: '' })
886 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
889 it('Should fail with a too long username', async function () {
890 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
892 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
895 it('Should fail with an incorrect username', async function () {
896 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
898 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
901 it('Should fail with a missing email', async function () {
902 const fields = omit(baseCorrectParams, 'email')
904 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
907 it('Should fail with an invalid email', async function () {
908 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
910 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
913 it('Should fail with a too small password', async function () {
914 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
916 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
919 it('Should fail with a too long password', async function () {
920 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
922 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
925 it('Should fail if we register a user with the same username', async function () {
926 const fields = immutableAssign(baseCorrectParams, { username: 'root' })
928 await makePostBodyRequest({
930 path: registrationPath,
931 token: server.accessToken,
933 statusCodeExpected: 409
937 it('Should fail with a "peertube" username', async function () {
938 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
940 await makePostBodyRequest({
942 path: registrationPath,
943 token: server.accessToken,
945 statusCodeExpected: 409
949 it('Should fail if we register a user with the same email', async function () {
950 const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' })
952 await makePostBodyRequest({
954 path: registrationPath,
955 token: server.accessToken,
957 statusCodeExpected: 409
961 it('Should fail with a bad display name', async function () {
962 const fields = immutableAssign(baseCorrectParams, { displayName: 'a'.repeat(150) })
964 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
967 it('Should fail with a bad channel name', async function () {
968 const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } })
970 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
973 it('Should fail with a bad channel display name', async function () {
974 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } })
976 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
979 it('Should fail with a channel name that is the same as username', async function () {
980 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
981 const fields = immutableAssign(baseCorrectParams, source)
983 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
986 it('Should fail with an existing channel', async function () {
987 const videoChannelAttributesArg = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
988 await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg)
990 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } })
992 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields, statusCodeExpected: 409 })
995 it('Should succeed with the correct params', async function () {
996 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } })
998 await makePostBodyRequest({
1000 path: registrationPath,
1001 token: server.accessToken,
1003 statusCodeExpected: 204
1007 it('Should fail on a server with registration disabled', async function () {
1010 email: 'test4@example.com',
1011 password: 'my super password 4'
1014 await makePostBodyRequest({
1015 url: serverWithRegistrationDisabled.url,
1016 path: registrationPath,
1017 token: serverWithRegistrationDisabled.accessToken,
1019 statusCodeExpected: 403
1024 describe('When registering multiple users on a server with users limit', function () {
1025 it('Should fail when after 3 registrations', async function () {
1026 await registerUser(server.url, 'user42', 'super password', 403)
1030 describe('When having a video quota', function () {
1031 it('Should fail with a user having too many videos', async function () {
1035 accessToken: server.accessToken,
1039 await uploadVideo(server.url, server.accessToken, {}, 403)
1042 it('Should fail with a registered user having too many videos', async function () {
1047 password: 'my super password'
1049 userAccessToken = await userLogin(server, user)
1051 const videoAttributes = { fixture: 'video_short2.webm' }
1052 await uploadVideo(server.url, userAccessToken, videoAttributes)
1053 await uploadVideo(server.url, userAccessToken, videoAttributes)
1054 await uploadVideo(server.url, userAccessToken, videoAttributes)
1055 await uploadVideo(server.url, userAccessToken, videoAttributes)
1056 await uploadVideo(server.url, userAccessToken, videoAttributes)
1057 await uploadVideo(server.url, userAccessToken, videoAttributes, 403)
1060 it('Should fail to import with HTTP/Torrent/magnet', async function () {
1061 this.timeout(120000)
1063 const baseAttributes = {
1065 privacy: VideoPrivacy.PUBLIC
1067 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getGoodVideoUrl() }))
1068 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() }))
1069 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' as any }))
1071 await waitJobs([ server ])
1073 const res = await getMyVideoImports(server.url, server.accessToken)
1075 expect(res.body.total).to.equal(3)
1076 const videoImports: VideoImport[] = res.body.data
1077 expect(videoImports).to.have.lengthOf(3)
1079 for (const videoImport of videoImports) {
1080 expect(videoImport.state.id).to.equal(VideoImportState.FAILED)
1081 expect(videoImport.error).not.to.be.undefined
1082 expect(videoImport.error).to.contain('user video quota is exceeded')
1087 describe('When having a daily video quota', function () {
1088 it('Should fail with a user having too many videos', async function () {
1092 accessToken: server.accessToken,
1096 await uploadVideo(server.url, server.accessToken, {}, 403)
1100 describe('When having an absolute and daily video quota', function () {
1101 it('Should fail if exceeding total quota', async function () {
1105 accessToken: server.accessToken,
1107 videoQuotaDaily: 1024 * 1024 * 1024
1110 await uploadVideo(server.url, server.accessToken, {}, 403)
1113 it('Should fail if exceeding daily quota', async function () {
1117 accessToken: server.accessToken,
1118 videoQuota: 1024 * 1024 * 1024,
1122 await uploadVideo(server.url, server.accessToken, {}, 403)
1126 describe('When asking a password reset', function () {
1127 const path = '/api/v1/users/ask-reset-password'
1129 it('Should fail with a missing email', async function () {
1132 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1135 it('Should fail with an invalid email', async function () {
1136 const fields = { email: 'hello' }
1138 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1141 it('Should success with the correct params', async function () {
1142 const fields = { email: 'admin@example.com' }
1144 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
1148 describe('When asking for an account verification email', function () {
1149 const path = '/api/v1/users/ask-send-verify-email'
1151 it('Should fail with a missing email', async function () {
1154 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1157 it('Should fail with an invalid email', async function () {
1158 const fields = { email: 'hello' }
1160 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1163 it('Should succeed with the correct params', async function () {
1164 const fields = { email: 'admin@example.com' }
1166 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
1170 after(async function () {
1171 MockSmtpServer.Instance.kill()
1173 await cleanupTests([ server, serverWithRegistrationDisabled ])