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
59 // ---------------------------------------------------------------
61 before(async function () {
64 const emails: object[] = []
65 emailPort = await MockSmtpServer.Instance.collectEmails(emails)
67 overrideConfig = { signup: { limit: 8 } }
70 const res = await Promise.all([
71 flushAndRunServer(1, overrideConfig),
76 serverWithRegistrationDisabled = res[1]
78 await setAccessTokensToServers([ server ])
84 password: 'my super password'
87 const videoQuota = 42000000
90 accessToken: server.accessToken,
91 username: user.username,
92 password: user.password,
93 videoQuota: videoQuota
95 userAccessToken = await userLogin(server, user)
100 username: 'moderator1',
101 password: 'super password'
106 accessToken: server.accessToken,
107 username: moderator.username,
108 password: moderator.password,
109 role: UserRole.MODERATOR
112 moderatorAccessToken = await userLogin(server, moderator)
117 username: 'moderator2',
118 password: 'super password'
123 accessToken: server.accessToken,
124 username: moderator.username,
125 password: moderator.password,
126 role: UserRole.MODERATOR
131 const res = await uploadVideo(server.url, server.accessToken, {})
132 videoId = res.body.video.id
136 const res = await getUsersList(server.url, server.accessToken)
137 const users: User[] = res.body.data
139 userId = users.find(u => u.username === 'user1').id
140 rootId = users.find(u => u.username === 'root').id
141 moderatorId = users.find(u => u.username === 'moderator2').id
145 describe('When listing users', function () {
146 it('Should fail with a bad start pagination', async function () {
147 await checkBadStartPagination(server.url, path, server.accessToken)
150 it('Should fail with a bad count pagination', async function () {
151 await checkBadCountPagination(server.url, path, server.accessToken)
154 it('Should fail with an incorrect sort', async function () {
155 await checkBadSortPagination(server.url, path, server.accessToken)
158 it('Should fail with a non authenticated user', async function () {
159 await makeGetRequest({
162 statusCodeExpected: 401
166 it('Should fail with a non admin user', async function () {
167 await makeGetRequest({
170 token: userAccessToken,
171 statusCodeExpected: 403
176 describe('When adding a new user', function () {
177 const baseCorrectParams = {
179 email: 'test@example.com',
180 password: 'my super password',
184 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
187 it('Should fail with a too small username', async function () {
188 const fields = immutableAssign(baseCorrectParams, { username: '' })
190 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
193 it('Should fail with a too long username', async function () {
194 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
196 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
199 it('Should fail with a not lowercase username', async function () {
200 const fields = immutableAssign(baseCorrectParams, { username: 'Toto' })
202 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
205 it('Should fail with an incorrect username', async function () {
206 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
208 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
211 it('Should fail with a missing email', async function () {
212 const fields = omit(baseCorrectParams, 'email')
214 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
217 it('Should fail with an invalid email', async function () {
218 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
220 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
223 it('Should fail with a too small password', async function () {
224 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
226 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
229 it('Should fail with a too long password', async function () {
230 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
232 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
235 it('Should fail with empty password and no smtp configured', async function () {
236 const fields = immutableAssign(baseCorrectParams, { password: '' })
238 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
241 it('Should succeed with no password on a server with smtp enabled', async function () {
244 killallServers([ server ])
246 const config = immutableAssign(overrideConfig, {
248 hostname: 'localhost',
252 await reRunServer(server, config)
254 const fields = immutableAssign(baseCorrectParams, {
256 username: 'create_password',
257 email: 'create_password@example.com'
260 await makePostBodyRequest({
263 token: server.accessToken,
265 statusCodeExpected: 200
269 it('Should fail with invalid admin flags', async function () {
270 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' })
272 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
275 it('Should fail with an non authenticated user', async function () {
276 await makePostBodyRequest({
279 token: 'super token',
280 fields: baseCorrectParams,
281 statusCodeExpected: 401
285 it('Should fail if we add a user with the same username', async function () {
286 const fields = immutableAssign(baseCorrectParams, { username: 'user1' })
288 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
291 it('Should fail if we add a user with the same email', async function () {
292 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' })
294 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
297 it('Should fail without a videoQuota', async function () {
298 const fields = omit(baseCorrectParams, 'videoQuota')
300 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
303 it('Should fail without a videoQuotaDaily', async function () {
304 const fields = omit(baseCorrectParams, 'videoQuotaDaily')
306 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
309 it('Should fail with an invalid videoQuota', async function () {
310 const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 })
312 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
315 it('Should fail with an invalid videoQuotaDaily', async function () {
316 const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 })
318 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
321 it('Should fail without a user role', async function () {
322 const fields = omit(baseCorrectParams, 'role')
324 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
327 it('Should fail with an invalid user role', async function () {
328 const fields = immutableAssign(baseCorrectParams, { role: 88989 })
330 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
333 it('Should fail with a "peertube" username', async function () {
334 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
336 await makePostBodyRequest({
339 token: server.accessToken,
341 statusCodeExpected: 409
345 it('Should fail to create a moderator or an admin with a moderator', async function () {
346 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
347 const fields = immutableAssign(baseCorrectParams, { role })
349 await makePostBodyRequest({
352 token: moderatorAccessToken,
354 statusCodeExpected: 403
359 it('Should succeed to create a user with a moderator', async function () {
360 const fields = immutableAssign(baseCorrectParams, { username: 'a4656', email: 'a4656@example.com', role: UserRole.USER })
362 await makePostBodyRequest({
365 token: moderatorAccessToken,
367 statusCodeExpected: 200
371 it('Should succeed with the correct params', async function () {
372 await makePostBodyRequest({
375 token: server.accessToken,
376 fields: baseCorrectParams,
377 statusCodeExpected: 200
381 it('Should fail with a non admin user', async function () {
384 password: 'my super password'
386 userAccessToken = await userLogin(server, user)
390 email: 'test@example.com',
391 password: 'my super password',
394 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
398 describe('When updating my account', function () {
399 it('Should fail with an invalid email attribute', async function () {
404 await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields })
407 it('Should fail with a too small password', async function () {
409 currentPassword: 'my super password',
413 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
416 it('Should fail with a too long password', async function () {
418 currentPassword: 'my super password',
419 password: 'super'.repeat(61)
422 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
425 it('Should fail without the current password', async function () {
427 currentPassword: 'my super password',
428 password: 'super'.repeat(61)
431 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
434 it('Should fail with an invalid current password', async function () {
436 currentPassword: 'my super password fail',
437 password: 'super'.repeat(61)
440 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 401 })
443 it('Should fail with an invalid NSFW policy attribute', async function () {
448 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
451 it('Should fail with an invalid autoPlayVideo attribute', async function () {
456 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
459 it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
461 autoPlayNextVideo: -1
464 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
467 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
469 videosHistoryEnabled: -1
472 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
475 it('Should fail with an non authenticated user', async function () {
477 currentPassword: 'my super password',
478 password: 'my super password'
481 await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 })
484 it('Should fail with a too long description', async function () {
486 description: 'super'.repeat(201)
489 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
492 it('Should fail with an invalid videoLanguages attribute', async function () {
495 videoLanguages: 'toto'
498 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
503 for (let i = 0; i < 1000; i++) {
508 videoLanguages: languages
511 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
515 it('Should fail with an invalid theme', async function () {
516 const fields = { theme: 'invalid' }
517 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
520 it('Should fail with an unknown theme', async function () {
521 const fields = { theme: 'peertube-theme-unknown' }
522 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
525 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
527 noInstanceConfigWarningModal: -1
530 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
533 it('Should fail with an invalid noWelcomeModal attribute', async function () {
538 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
541 it('Should succeed to change password with the correct params', async function () {
543 currentPassword: 'my super password',
544 password: 'my super password',
546 autoPlayVideo: false,
547 email: 'super_email@example.com',
549 noInstanceConfigWarningModal: true,
553 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
556 it('Should succeed without password change with the correct params', async function () {
562 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
566 describe('When updating my avatar', function () {
567 it('Should fail without an incorrect input file', async function () {
570 avatarfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
572 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
575 it('Should fail with a big file', async function () {
578 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
580 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
583 it('Should fail with an unauthenticated user', async function () {
586 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
588 await makeUploadRequest({
590 path: path + '/me/avatar/pick',
593 statusCodeExpected: 401
597 it('Should succeed with the correct params', async function () {
600 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
602 await makeUploadRequest({
604 path: path + '/me/avatar/pick',
605 token: server.accessToken,
608 statusCodeExpected: 200
613 describe('When getting a user', function () {
615 it('Should fail with an non authenticated user', async function () {
616 await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 })
619 it('Should fail with a non admin user', async function () {
620 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 })
623 it('Should succeed with the correct params', async function () {
624 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 })
628 describe('When updating a user', function () {
630 it('Should fail with an invalid email attribute', async function () {
635 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
638 it('Should fail with an invalid emailVerified attribute', async function () {
643 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
646 it('Should fail with an invalid videoQuota attribute', async function () {
651 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
654 it('Should fail with an invalid user role attribute', async function () {
659 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
662 it('Should fail with a too small password', async function () {
664 currentPassword: 'my super password',
668 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
671 it('Should fail with a too long password', async function () {
673 currentPassword: 'my super password',
674 password: 'super'.repeat(61)
677 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
680 it('Should fail with an non authenticated user', async function () {
685 await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 })
688 it('Should fail when updating root role', async function () {
690 role: UserRole.MODERATOR
693 await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
696 it('Should fail with invalid admin flags', async function () {
697 const fields = { adminFlags: 'toto' }
699 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
702 it('Should fail to update an admin with a moderator', async function () {
707 await makePutBodyRequest({
709 path: path + moderatorId,
710 token: moderatorAccessToken,
712 statusCodeExpected: 403
716 it('Should succeed to update a user with a moderator', async function () {
721 await makePutBodyRequest({
724 token: moderatorAccessToken,
726 statusCodeExpected: 204
730 it('Should succeed with the correct params', async function () {
732 email: 'email@example.com',
738 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 })
742 describe('When getting my information', function () {
743 it('Should fail with a non authenticated user', async function () {
744 await getMyUserInformation(server.url, 'fake_token', 401)
747 it('Should success with the correct parameters', async function () {
748 await getMyUserInformation(server.url, userAccessToken)
752 describe('When getting my video rating', function () {
753 it('Should fail with a non authenticated user', async function () {
754 await getMyUserVideoRating(server.url, 'fake_token', videoId, 401)
757 it('Should fail with an incorrect video uuid', async function () {
758 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400)
761 it('Should fail with an unknown video', async function () {
762 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
765 it('Should succeed with the correct parameters', async function () {
766 await getMyUserVideoRating(server.url, server.accessToken, videoId)
770 describe('When retrieving my global ratings', function () {
771 const path = '/api/v1/accounts/user1/ratings'
773 it('Should fail with a bad start pagination', async function () {
774 await checkBadStartPagination(server.url, path, userAccessToken)
777 it('Should fail with a bad count pagination', async function () {
778 await checkBadCountPagination(server.url, path, userAccessToken)
781 it('Should fail with an incorrect sort', async function () {
782 await checkBadSortPagination(server.url, path, userAccessToken)
785 it('Should fail with a unauthenticated user', async function () {
786 await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 })
789 it('Should fail with a another user', async function () {
790 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 })
793 it('Should fail with a bad type', async function () {
794 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 })
797 it('Should succeed with the correct params', async function () {
798 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 })
802 describe('When blocking/unblocking/removing user', function () {
803 it('Should fail with an incorrect id', async function () {
804 await removeUser(server.url, 'blabla', server.accessToken, 400)
805 await blockUser(server.url, 'blabla', server.accessToken, 400)
806 await unblockUser(server.url, 'blabla', server.accessToken, 400)
809 it('Should fail with the root user', async function () {
810 await removeUser(server.url, rootId, server.accessToken, 400)
811 await blockUser(server.url, rootId, server.accessToken, 400)
812 await unblockUser(server.url, rootId, server.accessToken, 400)
815 it('Should return 404 with a non existing id', async function () {
816 await removeUser(server.url, 4545454, server.accessToken, 404)
817 await blockUser(server.url, 4545454, server.accessToken, 404)
818 await unblockUser(server.url, 4545454, server.accessToken, 404)
821 it('Should fail with a non admin user', async function () {
822 await removeUser(server.url, userId, userAccessToken, 403)
823 await blockUser(server.url, userId, userAccessToken, 403)
824 await unblockUser(server.url, userId, userAccessToken, 403)
827 it('Should fail on a moderator with a moderator', async function () {
828 await removeUser(server.url, moderatorId, moderatorAccessToken, 403)
829 await blockUser(server.url, moderatorId, moderatorAccessToken, 403)
830 await unblockUser(server.url, moderatorId, moderatorAccessToken, 403)
833 it('Should succeed on a user with a moderator', async function () {
834 await blockUser(server.url, userId, moderatorAccessToken)
835 await unblockUser(server.url, userId, moderatorAccessToken)
839 describe('When deleting our account', function () {
840 it('Should fail with with the root account', async function () {
841 await deleteMe(server.url, server.accessToken, 400)
845 describe('When registering a new user', function () {
846 const registrationPath = path + '/register'
847 const baseCorrectParams = {
849 displayName: 'super user',
850 email: 'test3@example.com',
851 password: 'my super password'
854 it('Should fail with a too small username', async function () {
855 const fields = immutableAssign(baseCorrectParams, { username: '' })
857 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
860 it('Should fail with a too long username', async function () {
861 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
863 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
866 it('Should fail with an incorrect username', async function () {
867 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
869 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
872 it('Should fail with a missing email', async function () {
873 const fields = omit(baseCorrectParams, 'email')
875 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
878 it('Should fail with an invalid email', async function () {
879 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
881 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
884 it('Should fail with a too small password', async function () {
885 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
887 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
890 it('Should fail with a too long password', async function () {
891 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
893 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
896 it('Should fail if we register a user with the same username', async function () {
897 const fields = immutableAssign(baseCorrectParams, { username: 'root' })
899 await makePostBodyRequest({
901 path: registrationPath,
902 token: server.accessToken,
904 statusCodeExpected: 409
908 it('Should fail with a "peertube" username', async function () {
909 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
911 await makePostBodyRequest({
913 path: registrationPath,
914 token: server.accessToken,
916 statusCodeExpected: 409
920 it('Should fail if we register a user with the same email', async function () {
921 const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' })
923 await makePostBodyRequest({
925 path: registrationPath,
926 token: server.accessToken,
928 statusCodeExpected: 409
932 it('Should fail with a bad display name', async function () {
933 const fields = immutableAssign(baseCorrectParams, { displayName: 'a'.repeat(150) })
935 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
938 it('Should fail with a bad channel name', async function () {
939 const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } })
941 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
944 it('Should fail with a bad channel display name', async function () {
945 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } })
947 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
950 it('Should fail with a channel name that is the same as username', async function () {
951 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
952 const fields = immutableAssign(baseCorrectParams, source)
954 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
957 it('Should fail with an existing channel', async function () {
958 const videoChannelAttributesArg = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
959 await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg)
961 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } })
963 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields, statusCodeExpected: 409 })
966 it('Should succeed with the correct params', async function () {
967 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } })
969 await makePostBodyRequest({
971 path: registrationPath,
972 token: server.accessToken,
974 statusCodeExpected: 204
978 it('Should fail on a server with registration disabled', async function () {
981 email: 'test4@example.com',
982 password: 'my super password 4'
985 await makePostBodyRequest({
986 url: serverWithRegistrationDisabled.url,
987 path: registrationPath,
988 token: serverWithRegistrationDisabled.accessToken,
990 statusCodeExpected: 403
995 describe('When registering multiple users on a server with users limit', function () {
996 it('Should fail when after 3 registrations', async function () {
997 await registerUser(server.url, 'user42', 'super password', 403)
1001 describe('When having a video quota', function () {
1002 it('Should fail with a user having too many videos', async function () {
1006 accessToken: server.accessToken,
1010 await uploadVideo(server.url, server.accessToken, {}, 403)
1013 it('Should fail with a registered user having too many videos', async function () {
1018 password: 'my super password'
1020 userAccessToken = await userLogin(server, user)
1022 const videoAttributes = { fixture: 'video_short2.webm' }
1023 await uploadVideo(server.url, userAccessToken, videoAttributes)
1024 await uploadVideo(server.url, userAccessToken, videoAttributes)
1025 await uploadVideo(server.url, userAccessToken, videoAttributes)
1026 await uploadVideo(server.url, userAccessToken, videoAttributes)
1027 await uploadVideo(server.url, userAccessToken, videoAttributes)
1028 await uploadVideo(server.url, userAccessToken, videoAttributes, 403)
1031 it('Should fail to import with HTTP/Torrent/magnet', async function () {
1032 this.timeout(120000)
1034 const baseAttributes = {
1036 privacy: VideoPrivacy.PUBLIC
1038 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }))
1039 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() }))
1040 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' as any }))
1042 await waitJobs([ server ])
1044 const res = await getMyVideoImports(server.url, server.accessToken)
1046 expect(res.body.total).to.equal(3)
1047 const videoImports: VideoImport[] = res.body.data
1048 expect(videoImports).to.have.lengthOf(3)
1050 for (const videoImport of videoImports) {
1051 expect(videoImport.state.id).to.equal(VideoImportState.FAILED)
1052 expect(videoImport.error).not.to.be.undefined
1053 expect(videoImport.error).to.contain('user video quota is exceeded')
1058 describe('When having a daily video quota', function () {
1059 it('Should fail with a user having too many videos', async function () {
1063 accessToken: server.accessToken,
1067 await uploadVideo(server.url, server.accessToken, {}, 403)
1071 describe('When having an absolute and daily video quota', function () {
1072 it('Should fail if exceeding total quota', async function () {
1076 accessToken: server.accessToken,
1078 videoQuotaDaily: 1024 * 1024 * 1024
1081 await uploadVideo(server.url, server.accessToken, {}, 403)
1084 it('Should fail if exceeding daily quota', async function () {
1088 accessToken: server.accessToken,
1089 videoQuota: 1024 * 1024 * 1024,
1093 await uploadVideo(server.url, server.accessToken, {}, 403)
1097 describe('When asking a password reset', function () {
1098 const path = '/api/v1/users/ask-reset-password'
1100 it('Should fail with a missing email', async function () {
1103 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1106 it('Should fail with an invalid email', async function () {
1107 const fields = { email: 'hello' }
1109 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1112 it('Should success with the correct params', async function () {
1113 const fields = { email: 'admin@example.com' }
1115 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
1119 describe('When asking for an account verification email', function () {
1120 const path = '/api/v1/users/ask-send-verify-email'
1122 it('Should fail with a missing email', async function () {
1125 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1128 it('Should fail with an invalid email', async function () {
1129 const fields = { email: 'hello' }
1131 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1134 it('Should succeed with the correct params', async function () {
1135 const fields = { email: 'admin@example.com' }
1137 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
1141 after(async function () {
1142 MockSmtpServer.Instance.kill()
1144 await cleanupTests([ server, serverWithRegistrationDisabled ])