1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { omit } from 'lodash'
5 import { join } from 'path'
6 import { User, UserRole, VideoImport, VideoImportState } from '../../../../shared'
28 setAccessTokensToServers,
33 } from '../../../../shared/extra-utils'
35 checkBadCountPagination,
36 checkBadSortPagination,
37 checkBadStartPagination
38 } from '../../../../shared/extra-utils/requests/check-api-params'
39 import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
40 import { VideoPrivacy } from '../../../../shared/models/videos'
41 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
42 import { expect } from 'chai'
43 import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
44 import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
46 describe('Test users API validators', function () {
47 const path = '/api/v1/users/'
50 let moderatorId: number
52 let server: ServerInfo
53 let serverWithRegistrationDisabled: ServerInfo
54 let userAccessToken = ''
55 let moderatorAccessToken = ''
57 let overrideConfig: Object
58 // eslint-disable-next-line @typescript-eslint/no-unused-vars
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 getMyUserInformation(server.url, server.accessToken)
134 channelId = res.body.videoChannels[0].id
138 const res = await uploadVideo(server.url, server.accessToken, {})
139 videoId = res.body.video.id
143 const res = await getUsersList(server.url, server.accessToken)
144 const users: User[] = res.body.data
146 userId = users.find(u => u.username === 'user1').id
147 rootId = users.find(u => u.username === 'root').id
148 moderatorId = users.find(u => u.username === 'moderator2').id
152 describe('When listing users', function () {
153 it('Should fail with a bad start pagination', async function () {
154 await checkBadStartPagination(server.url, path, server.accessToken)
157 it('Should fail with a bad count pagination', async function () {
158 await checkBadCountPagination(server.url, path, server.accessToken)
161 it('Should fail with an incorrect sort', async function () {
162 await checkBadSortPagination(server.url, path, server.accessToken)
165 it('Should fail with a non authenticated user', async function () {
166 await makeGetRequest({
169 statusCodeExpected: 401
173 it('Should fail with a non admin user', async function () {
174 await makeGetRequest({
177 token: userAccessToken,
178 statusCodeExpected: 403
183 describe('When adding a new user', function () {
184 const baseCorrectParams = {
186 email: 'test@example.com',
187 password: 'my super password',
191 adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST
194 it('Should fail with a too small username', async function () {
195 const fields = immutableAssign(baseCorrectParams, { username: '' })
197 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
200 it('Should fail with a too long username', async function () {
201 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
203 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
206 it('Should fail with a not lowercase username', async function () {
207 const fields = immutableAssign(baseCorrectParams, { username: 'Toto' })
209 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
212 it('Should fail with an incorrect username', async function () {
213 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
215 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
218 it('Should fail with a missing email', async function () {
219 const fields = omit(baseCorrectParams, 'email')
221 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
224 it('Should fail with an invalid email', async function () {
225 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
227 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
230 it('Should fail with a too small password', async function () {
231 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
233 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
236 it('Should fail with a too long password', async function () {
237 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
239 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
242 it('Should fail with empty password and no smtp configured', async function () {
243 const fields = immutableAssign(baseCorrectParams, { password: '' })
245 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
248 it('Should succeed with no password on a server with smtp enabled', async function () {
251 killallServers([ server ])
253 const config = immutableAssign(overrideConfig, {
255 hostname: 'localhost',
259 await reRunServer(server, config)
261 const fields = immutableAssign(baseCorrectParams, {
263 username: 'create_password',
264 email: 'create_password@example.com'
267 await makePostBodyRequest({
270 token: server.accessToken,
272 statusCodeExpected: 200
276 it('Should fail with invalid admin flags', async function () {
277 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' })
279 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
282 it('Should fail with an non authenticated user', async function () {
283 await makePostBodyRequest({
286 token: 'super token',
287 fields: baseCorrectParams,
288 statusCodeExpected: 401
292 it('Should fail if we add a user with the same username', async function () {
293 const fields = immutableAssign(baseCorrectParams, { username: 'user1' })
295 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
298 it('Should fail if we add a user with the same email', async function () {
299 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' })
301 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
304 it('Should fail without a videoQuota', async function () {
305 const fields = omit(baseCorrectParams, 'videoQuota')
307 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
310 it('Should fail without a videoQuotaDaily', async function () {
311 const fields = omit(baseCorrectParams, 'videoQuotaDaily')
313 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
316 it('Should fail with an invalid videoQuota', async function () {
317 const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 })
319 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
322 it('Should fail with an invalid videoQuotaDaily', async function () {
323 const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 })
325 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
328 it('Should fail without a user role', async function () {
329 const fields = omit(baseCorrectParams, 'role')
331 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
334 it('Should fail with an invalid user role', async function () {
335 const fields = immutableAssign(baseCorrectParams, { role: 88989 })
337 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
340 it('Should fail with a "peertube" username', async function () {
341 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
343 await makePostBodyRequest({
346 token: server.accessToken,
348 statusCodeExpected: 409
352 it('Should fail to create a moderator or an admin with a moderator', async function () {
353 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
354 const fields = immutableAssign(baseCorrectParams, { role })
356 await makePostBodyRequest({
359 token: moderatorAccessToken,
361 statusCodeExpected: 403
366 it('Should succeed to create a user with a moderator', async function () {
367 const fields = immutableAssign(baseCorrectParams, { username: 'a4656', email: 'a4656@example.com', role: UserRole.USER })
369 await makePostBodyRequest({
372 token: moderatorAccessToken,
374 statusCodeExpected: 200
378 it('Should succeed with the correct params', async function () {
379 await makePostBodyRequest({
382 token: server.accessToken,
383 fields: baseCorrectParams,
384 statusCodeExpected: 200
388 it('Should fail with a non admin user', async function () {
391 password: 'my super password'
393 userAccessToken = await userLogin(server, user)
397 email: 'test@example.com',
398 password: 'my super password',
401 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
405 describe('When updating my account', function () {
406 it('Should fail with an invalid email attribute', async function () {
411 await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields })
414 it('Should fail with a too small password', async function () {
416 currentPassword: 'my super password',
420 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
423 it('Should fail with a too long password', async function () {
425 currentPassword: 'my super password',
426 password: 'super'.repeat(61)
429 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
432 it('Should fail without the current password', async function () {
434 currentPassword: 'my super password',
435 password: 'super'.repeat(61)
438 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
441 it('Should fail with an invalid current password', async function () {
443 currentPassword: 'my super password fail',
444 password: 'super'.repeat(61)
447 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 401 })
450 it('Should fail with an invalid NSFW policy attribute', async function () {
455 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
458 it('Should fail with an invalid autoPlayVideo attribute', async function () {
463 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
466 it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
468 autoPlayNextVideo: -1
471 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
474 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
476 videosHistoryEnabled: -1
479 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
482 it('Should fail with an non authenticated user', async function () {
484 currentPassword: 'my super password',
485 password: 'my super password'
488 await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 })
491 it('Should fail with a too long description', async function () {
493 description: 'super'.repeat(201)
496 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
499 it('Should fail with an invalid videoLanguages attribute', async function () {
502 videoLanguages: 'toto'
505 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
510 for (let i = 0; i < 1000; i++) {
515 videoLanguages: languages
518 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
522 it('Should fail with an invalid theme', async function () {
523 const fields = { theme: 'invalid' }
524 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
527 it('Should fail with an unknown theme', async function () {
528 const fields = { theme: 'peertube-theme-unknown' }
529 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
532 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
534 noInstanceConfigWarningModal: -1
537 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
540 it('Should fail with an invalid noWelcomeModal attribute', async function () {
545 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
548 it('Should succeed to change password with the correct params', async function () {
550 currentPassword: 'my super password',
551 password: 'my super password',
553 autoPlayVideo: false,
554 email: 'super_email@example.com',
556 noInstanceConfigWarningModal: true,
560 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
563 it('Should succeed without password change with the correct params', async function () {
569 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
573 describe('When updating my avatar', function () {
574 it('Should fail without an incorrect input file', async function () {
577 avatarfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
579 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
582 it('Should fail with a big file', async function () {
585 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
587 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
590 it('Should fail with an unauthenticated user', async function () {
593 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
595 await makeUploadRequest({
597 path: path + '/me/avatar/pick',
600 statusCodeExpected: 401
604 it('Should succeed with the correct params', async function () {
607 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
609 await makeUploadRequest({
611 path: path + '/me/avatar/pick',
612 token: server.accessToken,
615 statusCodeExpected: 200
620 describe('When getting a user', function () {
622 it('Should fail with an non authenticated user', async function () {
623 await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 })
626 it('Should fail with a non admin user', async function () {
627 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 })
630 it('Should succeed with the correct params', async function () {
631 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 })
635 describe('When updating a user', function () {
637 it('Should fail with an invalid email attribute', async function () {
642 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
645 it('Should fail with an invalid emailVerified attribute', async function () {
650 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
653 it('Should fail with an invalid videoQuota attribute', async function () {
658 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
661 it('Should fail with an invalid user role attribute', async function () {
666 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
669 it('Should fail with a too small password', async function () {
671 currentPassword: 'my super password',
675 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
678 it('Should fail with a too long password', async function () {
680 currentPassword: 'my super password',
681 password: 'super'.repeat(61)
684 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
687 it('Should fail with an non authenticated user', async function () {
692 await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 })
695 it('Should fail when updating root role', async function () {
697 role: UserRole.MODERATOR
700 await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
703 it('Should fail with invalid admin flags', async function () {
704 const fields = { adminFlags: 'toto' }
706 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
709 it('Should fail to update an admin with a moderator', async function () {
714 await makePutBodyRequest({
716 path: path + moderatorId,
717 token: moderatorAccessToken,
719 statusCodeExpected: 403
723 it('Should succeed to update a user with a moderator', async function () {
728 await makePutBodyRequest({
731 token: moderatorAccessToken,
733 statusCodeExpected: 204
737 it('Should succeed with the correct params', async function () {
739 email: 'email@example.com',
745 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 })
749 describe('When getting my information', function () {
750 it('Should fail with a non authenticated user', async function () {
751 await getMyUserInformation(server.url, 'fake_token', 401)
754 it('Should success with the correct parameters', async function () {
755 await getMyUserInformation(server.url, userAccessToken)
759 describe('When getting my video rating', function () {
760 it('Should fail with a non authenticated user', async function () {
761 await getMyUserVideoRating(server.url, 'fake_token', videoId, 401)
764 it('Should fail with an incorrect video uuid', async function () {
765 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400)
768 it('Should fail with an unknown video', async function () {
769 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
772 it('Should succeed with the correct parameters', async function () {
773 await getMyUserVideoRating(server.url, server.accessToken, videoId)
777 describe('When retrieving my global ratings', function () {
778 const path = '/api/v1/accounts/user1/ratings'
780 it('Should fail with a bad start pagination', async function () {
781 await checkBadStartPagination(server.url, path, userAccessToken)
784 it('Should fail with a bad count pagination', async function () {
785 await checkBadCountPagination(server.url, path, userAccessToken)
788 it('Should fail with an incorrect sort', async function () {
789 await checkBadSortPagination(server.url, path, userAccessToken)
792 it('Should fail with a unauthenticated user', async function () {
793 await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 })
796 it('Should fail with a another user', async function () {
797 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 })
800 it('Should fail with a bad type', async function () {
801 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 })
804 it('Should succeed with the correct params', async function () {
805 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 })
809 describe('When blocking/unblocking/removing user', function () {
810 it('Should fail with an incorrect id', async function () {
811 await removeUser(server.url, 'blabla', server.accessToken, 400)
812 await blockUser(server.url, 'blabla', server.accessToken, 400)
813 await unblockUser(server.url, 'blabla', server.accessToken, 400)
816 it('Should fail with the root user', async function () {
817 await removeUser(server.url, rootId, server.accessToken, 400)
818 await blockUser(server.url, rootId, server.accessToken, 400)
819 await unblockUser(server.url, rootId, server.accessToken, 400)
822 it('Should return 404 with a non existing id', async function () {
823 await removeUser(server.url, 4545454, server.accessToken, 404)
824 await blockUser(server.url, 4545454, server.accessToken, 404)
825 await unblockUser(server.url, 4545454, server.accessToken, 404)
828 it('Should fail with a non admin user', async function () {
829 await removeUser(server.url, userId, userAccessToken, 403)
830 await blockUser(server.url, userId, userAccessToken, 403)
831 await unblockUser(server.url, userId, userAccessToken, 403)
834 it('Should fail on a moderator with a moderator', async function () {
835 await removeUser(server.url, moderatorId, moderatorAccessToken, 403)
836 await blockUser(server.url, moderatorId, moderatorAccessToken, 403)
837 await unblockUser(server.url, moderatorId, moderatorAccessToken, 403)
840 it('Should succeed on a user with a moderator', async function () {
841 await blockUser(server.url, userId, moderatorAccessToken)
842 await unblockUser(server.url, userId, moderatorAccessToken)
846 describe('When deleting our account', function () {
847 it('Should fail with with the root account', async function () {
848 await deleteMe(server.url, server.accessToken, 400)
852 describe('When registering a new user', function () {
853 const registrationPath = path + '/register'
854 const baseCorrectParams = {
856 displayName: 'super user',
857 email: 'test3@example.com',
858 password: 'my super password'
861 it('Should fail with a too small username', async function () {
862 const fields = immutableAssign(baseCorrectParams, { username: '' })
864 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
867 it('Should fail with a too long username', async function () {
868 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
870 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
873 it('Should fail with an incorrect username', async function () {
874 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
876 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
879 it('Should fail with a missing email', async function () {
880 const fields = omit(baseCorrectParams, 'email')
882 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
885 it('Should fail with an invalid email', async function () {
886 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
888 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
891 it('Should fail with a too small password', async function () {
892 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
894 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
897 it('Should fail with a too long password', async function () {
898 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
900 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
903 it('Should fail if we register a user with the same username', async function () {
904 const fields = immutableAssign(baseCorrectParams, { username: 'root' })
906 await makePostBodyRequest({
908 path: registrationPath,
909 token: server.accessToken,
911 statusCodeExpected: 409
915 it('Should fail with a "peertube" username', async function () {
916 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
918 await makePostBodyRequest({
920 path: registrationPath,
921 token: server.accessToken,
923 statusCodeExpected: 409
927 it('Should fail if we register a user with the same email', async function () {
928 const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' })
930 await makePostBodyRequest({
932 path: registrationPath,
933 token: server.accessToken,
935 statusCodeExpected: 409
939 it('Should fail with a bad display name', async function () {
940 const fields = immutableAssign(baseCorrectParams, { displayName: 'a'.repeat(150) })
942 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
945 it('Should fail with a bad channel name', async function () {
946 const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } })
948 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
951 it('Should fail with a bad channel display name', async function () {
952 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } })
954 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
957 it('Should fail with a channel name that is the same as username', async function () {
958 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
959 const fields = immutableAssign(baseCorrectParams, source)
961 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
964 it('Should fail with an existing channel', async function () {
965 const videoChannelAttributesArg = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
966 await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg)
968 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } })
970 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields, statusCodeExpected: 409 })
973 it('Should succeed with the correct params', async function () {
974 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } })
976 await makePostBodyRequest({
978 path: registrationPath,
979 token: server.accessToken,
981 statusCodeExpected: 204
985 it('Should fail on a server with registration disabled', async function () {
988 email: 'test4@example.com',
989 password: 'my super password 4'
992 await makePostBodyRequest({
993 url: serverWithRegistrationDisabled.url,
994 path: registrationPath,
995 token: serverWithRegistrationDisabled.accessToken,
997 statusCodeExpected: 403
1002 describe('When registering multiple users on a server with users limit', function () {
1003 it('Should fail when after 3 registrations', async function () {
1004 await registerUser(server.url, 'user42', 'super password', 403)
1008 describe('When having a video quota', function () {
1009 it('Should fail with a user having too many videos', async function () {
1013 accessToken: server.accessToken,
1017 await uploadVideo(server.url, server.accessToken, {}, 403)
1020 it('Should fail with a registered user having too many videos', async function () {
1025 password: 'my super password'
1027 userAccessToken = await userLogin(server, user)
1029 const videoAttributes = { fixture: 'video_short2.webm' }
1030 await uploadVideo(server.url, userAccessToken, videoAttributes)
1031 await uploadVideo(server.url, userAccessToken, videoAttributes)
1032 await uploadVideo(server.url, userAccessToken, videoAttributes)
1033 await uploadVideo(server.url, userAccessToken, videoAttributes)
1034 await uploadVideo(server.url, userAccessToken, videoAttributes)
1035 await uploadVideo(server.url, userAccessToken, videoAttributes, 403)
1038 it('Should fail to import with HTTP/Torrent/magnet', async function () {
1039 this.timeout(120000)
1041 const baseAttributes = {
1043 privacy: VideoPrivacy.PUBLIC
1045 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }))
1046 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() }))
1047 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' }))
1049 await waitJobs([ server ])
1051 const res = await getMyVideoImports(server.url, server.accessToken)
1053 expect(res.body.total).to.equal(3)
1054 const videoImports: VideoImport[] = res.body.data
1055 expect(videoImports).to.have.lengthOf(3)
1057 for (const videoImport of videoImports) {
1058 expect(videoImport.state.id).to.equal(VideoImportState.FAILED)
1059 expect(videoImport.error).not.to.be.undefined
1060 expect(videoImport.error).to.contain('user video quota is exceeded')
1065 describe('When having a daily video quota', function () {
1066 it('Should fail with a user having too many videos', async function () {
1070 accessToken: server.accessToken,
1074 await uploadVideo(server.url, server.accessToken, {}, 403)
1078 describe('When having an absolute and daily video quota', function () {
1079 it('Should fail if exceeding total quota', async function () {
1083 accessToken: server.accessToken,
1085 videoQuotaDaily: 1024 * 1024 * 1024
1088 await uploadVideo(server.url, server.accessToken, {}, 403)
1091 it('Should fail if exceeding daily quota', async function () {
1095 accessToken: server.accessToken,
1096 videoQuota: 1024 * 1024 * 1024,
1100 await uploadVideo(server.url, server.accessToken, {}, 403)
1104 describe('When asking a password reset', function () {
1105 const path = '/api/v1/users/ask-reset-password'
1107 it('Should fail with a missing email', async function () {
1110 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1113 it('Should fail with an invalid email', async function () {
1114 const fields = { email: 'hello' }
1116 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1119 it('Should success with the correct params', async function () {
1120 const fields = { email: 'admin@example.com' }
1122 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
1126 describe('When asking for an account verification email', function () {
1127 const path = '/api/v1/users/ask-send-verify-email'
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 succeed 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 after(async function () {
1149 MockSmtpServer.Instance.kill()
1151 await cleanupTests([ server, serverWithRegistrationDisabled ])