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 bad blocked/banned user filter', async function () {
159 await makeGetRequest({
165 token: server.accessToken,
166 statusCodeExpected: 400
170 it('Should fail with a non authenticated user', async function () {
171 await makeGetRequest({
174 statusCodeExpected: 401
178 it('Should fail with a non admin user', async function () {
179 await makeGetRequest({
182 token: userAccessToken,
183 statusCodeExpected: 403
188 describe('When adding a new user', function () {
189 const baseCorrectParams = {
191 email: 'test@example.com',
192 password: 'my super password',
196 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
199 it('Should fail with a too small username', async function () {
200 const fields = immutableAssign(baseCorrectParams, { username: '' })
202 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
205 it('Should fail with a too long username', async function () {
206 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
208 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
211 it('Should fail with a not lowercase username', async function () {
212 const fields = immutableAssign(baseCorrectParams, { username: 'Toto' })
214 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
217 it('Should fail with an incorrect username', async function () {
218 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
220 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
223 it('Should fail with a missing email', async function () {
224 const fields = omit(baseCorrectParams, 'email')
226 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
229 it('Should fail with an invalid email', async function () {
230 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
232 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
235 it('Should fail with a too small password', async function () {
236 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
238 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
241 it('Should fail with a too long password', async function () {
242 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
244 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
247 it('Should fail with empty password and no smtp configured', async function () {
248 const fields = immutableAssign(baseCorrectParams, { password: '' })
250 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
253 it('Should succeed with no password on a server with smtp enabled', async function () {
256 killallServers([ server ])
258 const config = immutableAssign(overrideConfig, {
260 hostname: 'localhost',
264 await reRunServer(server, config)
266 const fields = immutableAssign(baseCorrectParams, {
268 username: 'create_password',
269 email: 'create_password@example.com'
272 await makePostBodyRequest({
275 token: server.accessToken,
277 statusCodeExpected: 200
281 it('Should fail with invalid admin flags', async function () {
282 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' })
284 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
287 it('Should fail with an non authenticated user', async function () {
288 await makePostBodyRequest({
291 token: 'super token',
292 fields: baseCorrectParams,
293 statusCodeExpected: 401
297 it('Should fail if we add a user with the same username', async function () {
298 const fields = immutableAssign(baseCorrectParams, { username: 'user1' })
300 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
303 it('Should fail if we add a user with the same email', async function () {
304 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' })
306 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
309 it('Should fail without a videoQuota', async function () {
310 const fields = omit(baseCorrectParams, 'videoQuota')
312 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
315 it('Should fail without a videoQuotaDaily', async function () {
316 const fields = omit(baseCorrectParams, 'videoQuotaDaily')
318 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
321 it('Should fail with an invalid videoQuota', async function () {
322 const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 })
324 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
327 it('Should fail with an invalid videoQuotaDaily', async function () {
328 const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 })
330 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
333 it('Should fail without a user role', async function () {
334 const fields = omit(baseCorrectParams, 'role')
336 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
339 it('Should fail with an invalid user role', async function () {
340 const fields = immutableAssign(baseCorrectParams, { role: 88989 })
342 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
345 it('Should fail with a "peertube" username', async function () {
346 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
348 await makePostBodyRequest({
351 token: server.accessToken,
353 statusCodeExpected: 409
357 it('Should fail to create a moderator or an admin with a moderator', async function () {
358 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
359 const fields = immutableAssign(baseCorrectParams, { role })
361 await makePostBodyRequest({
364 token: moderatorAccessToken,
366 statusCodeExpected: 403
371 it('Should succeed to create a user with a moderator', async function () {
372 const fields = immutableAssign(baseCorrectParams, { username: 'a4656', email: 'a4656@example.com', role: UserRole.USER })
374 await makePostBodyRequest({
377 token: moderatorAccessToken,
379 statusCodeExpected: 200
383 it('Should succeed with the correct params', async function () {
384 await makePostBodyRequest({
387 token: server.accessToken,
388 fields: baseCorrectParams,
389 statusCodeExpected: 200
393 it('Should fail with a non admin user', async function () {
396 password: 'my super password'
398 userAccessToken = await userLogin(server, user)
402 email: 'test@example.com',
403 password: 'my super password',
406 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
410 describe('When updating my account', function () {
411 it('Should fail with an invalid email attribute', async function () {
416 await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields })
419 it('Should fail with a too small password', async function () {
421 currentPassword: 'my super password',
425 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
428 it('Should fail with a too long password', async function () {
430 currentPassword: 'my super password',
431 password: 'super'.repeat(61)
434 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
437 it('Should fail without the current password', async function () {
439 currentPassword: 'my super password',
440 password: 'super'.repeat(61)
443 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
446 it('Should fail with an invalid current password', async function () {
448 currentPassword: 'my super password fail',
449 password: 'super'.repeat(61)
452 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 401 })
455 it('Should fail with an invalid NSFW policy attribute', async function () {
460 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
463 it('Should fail with an invalid autoPlayVideo attribute', async function () {
468 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
471 it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
473 autoPlayNextVideo: -1
476 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
479 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
481 videosHistoryEnabled: -1
484 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
487 it('Should fail with an non authenticated user', async function () {
489 currentPassword: 'my super password',
490 password: 'my super password'
493 await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 })
496 it('Should fail with a too long description', async function () {
498 description: 'super'.repeat(201)
501 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
504 it('Should fail with an invalid videoLanguages attribute', async function () {
507 videoLanguages: 'toto'
510 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
515 for (let i = 0; i < 1000; i++) {
520 videoLanguages: languages
523 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
527 it('Should fail with an invalid theme', async function () {
528 const fields = { theme: 'invalid' }
529 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
532 it('Should fail with an unknown theme', async function () {
533 const fields = { theme: 'peertube-theme-unknown' }
534 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
537 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
539 noInstanceConfigWarningModal: -1
542 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
545 it('Should fail with an invalid noWelcomeModal attribute', async function () {
550 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
553 it('Should succeed to change password with the correct params', async function () {
555 currentPassword: 'my super password',
556 password: 'my super password',
558 autoPlayVideo: false,
559 email: 'super_email@example.com',
561 noInstanceConfigWarningModal: true,
565 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
568 it('Should succeed without password change with the correct params', async function () {
574 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
578 describe('When updating my avatar', function () {
579 it('Should fail without an incorrect input file', async function () {
582 avatarfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
584 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
587 it('Should fail with a big file', async function () {
590 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
592 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
595 it('Should fail with an unauthenticated user', async function () {
598 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
600 await makeUploadRequest({
602 path: path + '/me/avatar/pick',
605 statusCodeExpected: 401
609 it('Should succeed with the correct params', async function () {
612 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
614 await makeUploadRequest({
616 path: path + '/me/avatar/pick',
617 token: server.accessToken,
620 statusCodeExpected: 200
625 describe('When getting a user', function () {
627 it('Should fail with an non authenticated user', async function () {
628 await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 })
631 it('Should fail with a non admin user', async function () {
632 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 })
635 it('Should succeed with the correct params', async function () {
636 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 })
640 describe('When updating a user', function () {
642 it('Should fail with an invalid email attribute', async function () {
647 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
650 it('Should fail with an invalid emailVerified attribute', async function () {
655 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
658 it('Should fail with an invalid videoQuota attribute', async function () {
663 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
666 it('Should fail with an invalid user role attribute', async function () {
671 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
674 it('Should fail with a too small password', async function () {
676 currentPassword: 'my super password',
680 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
683 it('Should fail with a too long password', async function () {
685 currentPassword: 'my super password',
686 password: 'super'.repeat(61)
689 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
692 it('Should fail with an non authenticated user', async function () {
697 await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 })
700 it('Should fail when updating root role', async function () {
702 role: UserRole.MODERATOR
705 await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
708 it('Should fail with invalid admin flags', async function () {
709 const fields = { adminFlags: 'toto' }
711 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
714 it('Should fail to update an admin with a moderator', async function () {
719 await makePutBodyRequest({
721 path: path + moderatorId,
722 token: moderatorAccessToken,
724 statusCodeExpected: 403
728 it('Should succeed to update a user with a moderator', async function () {
733 await makePutBodyRequest({
736 token: moderatorAccessToken,
738 statusCodeExpected: 204
742 it('Should succeed with the correct params', async function () {
744 email: 'email@example.com',
750 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 })
754 describe('When getting my information', function () {
755 it('Should fail with a non authenticated user', async function () {
756 await getMyUserInformation(server.url, 'fake_token', 401)
759 it('Should success with the correct parameters', async function () {
760 await getMyUserInformation(server.url, userAccessToken)
764 describe('When getting my video rating', function () {
765 it('Should fail with a non authenticated user', async function () {
766 await getMyUserVideoRating(server.url, 'fake_token', videoId, 401)
769 it('Should fail with an incorrect video uuid', async function () {
770 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400)
773 it('Should fail with an unknown video', async function () {
774 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
777 it('Should succeed with the correct parameters', async function () {
778 await getMyUserVideoRating(server.url, server.accessToken, videoId)
782 describe('When retrieving my global ratings', function () {
783 const path = '/api/v1/accounts/user1/ratings'
785 it('Should fail with a bad start pagination', async function () {
786 await checkBadStartPagination(server.url, path, userAccessToken)
789 it('Should fail with a bad count pagination', async function () {
790 await checkBadCountPagination(server.url, path, userAccessToken)
793 it('Should fail with an incorrect sort', async function () {
794 await checkBadSortPagination(server.url, path, userAccessToken)
797 it('Should fail with a unauthenticated user', async function () {
798 await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 })
801 it('Should fail with a another user', async function () {
802 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 })
805 it('Should fail with a bad type', async function () {
806 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 })
809 it('Should succeed with the correct params', async function () {
810 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 })
814 describe('When blocking/unblocking/removing user', function () {
815 it('Should fail with an incorrect id', async function () {
816 await removeUser(server.url, 'blabla', server.accessToken, 400)
817 await blockUser(server.url, 'blabla', server.accessToken, 400)
818 await unblockUser(server.url, 'blabla', server.accessToken, 400)
821 it('Should fail with the root user', async function () {
822 await removeUser(server.url, rootId, server.accessToken, 400)
823 await blockUser(server.url, rootId, server.accessToken, 400)
824 await unblockUser(server.url, rootId, server.accessToken, 400)
827 it('Should return 404 with a non existing id', async function () {
828 await removeUser(server.url, 4545454, server.accessToken, 404)
829 await blockUser(server.url, 4545454, server.accessToken, 404)
830 await unblockUser(server.url, 4545454, server.accessToken, 404)
833 it('Should fail with a non admin user', async function () {
834 await removeUser(server.url, userId, userAccessToken, 403)
835 await blockUser(server.url, userId, userAccessToken, 403)
836 await unblockUser(server.url, userId, userAccessToken, 403)
839 it('Should fail on a moderator with a moderator', async function () {
840 await removeUser(server.url, moderatorId, moderatorAccessToken, 403)
841 await blockUser(server.url, moderatorId, moderatorAccessToken, 403)
842 await unblockUser(server.url, moderatorId, moderatorAccessToken, 403)
845 it('Should succeed on a user with a moderator', async function () {
846 await blockUser(server.url, userId, moderatorAccessToken)
847 await unblockUser(server.url, userId, moderatorAccessToken)
851 describe('When deleting our account', function () {
852 it('Should fail with with the root account', async function () {
853 await deleteMe(server.url, server.accessToken, 400)
857 describe('When registering a new user', function () {
858 const registrationPath = path + '/register'
859 const baseCorrectParams = {
861 displayName: 'super user',
862 email: 'test3@example.com',
863 password: 'my super password'
866 it('Should fail with a too small username', async function () {
867 const fields = immutableAssign(baseCorrectParams, { username: '' })
869 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
872 it('Should fail with a too long username', async function () {
873 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
875 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
878 it('Should fail with an incorrect username', async function () {
879 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
881 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
884 it('Should fail with a missing email', async function () {
885 const fields = omit(baseCorrectParams, 'email')
887 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
890 it('Should fail with an invalid email', async function () {
891 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
893 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
896 it('Should fail with a too small password', async function () {
897 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
899 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
902 it('Should fail with a too long password', async function () {
903 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
905 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
908 it('Should fail if we register a user with the same username', async function () {
909 const fields = immutableAssign(baseCorrectParams, { username: 'root' })
911 await makePostBodyRequest({
913 path: registrationPath,
914 token: server.accessToken,
916 statusCodeExpected: 409
920 it('Should fail with a "peertube" username', async function () {
921 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
923 await makePostBodyRequest({
925 path: registrationPath,
926 token: server.accessToken,
928 statusCodeExpected: 409
932 it('Should fail if we register a user with the same email', async function () {
933 const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' })
935 await makePostBodyRequest({
937 path: registrationPath,
938 token: server.accessToken,
940 statusCodeExpected: 409
944 it('Should fail with a bad display name', async function () {
945 const fields = immutableAssign(baseCorrectParams, { displayName: 'a'.repeat(150) })
947 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
950 it('Should fail with a bad channel name', async function () {
951 const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } })
953 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
956 it('Should fail with a bad channel display name', async function () {
957 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } })
959 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
962 it('Should fail with a channel name that is the same as username', async function () {
963 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
964 const fields = immutableAssign(baseCorrectParams, source)
966 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
969 it('Should fail with an existing channel', async function () {
970 const videoChannelAttributesArg = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
971 await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg)
973 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } })
975 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields, statusCodeExpected: 409 })
978 it('Should succeed with the correct params', async function () {
979 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } })
981 await makePostBodyRequest({
983 path: registrationPath,
984 token: server.accessToken,
986 statusCodeExpected: 204
990 it('Should fail on a server with registration disabled', async function () {
993 email: 'test4@example.com',
994 password: 'my super password 4'
997 await makePostBodyRequest({
998 url: serverWithRegistrationDisabled.url,
999 path: registrationPath,
1000 token: serverWithRegistrationDisabled.accessToken,
1002 statusCodeExpected: 403
1007 describe('When registering multiple users on a server with users limit', function () {
1008 it('Should fail when after 3 registrations', async function () {
1009 await registerUser(server.url, 'user42', 'super password', 403)
1013 describe('When having a video quota', function () {
1014 it('Should fail with a user having too many videos', async function () {
1018 accessToken: server.accessToken,
1022 await uploadVideo(server.url, server.accessToken, {}, 403)
1025 it('Should fail with a registered user having too many videos', async function () {
1030 password: 'my super password'
1032 userAccessToken = await userLogin(server, user)
1034 const videoAttributes = { fixture: 'video_short2.webm' }
1035 await uploadVideo(server.url, userAccessToken, videoAttributes)
1036 await uploadVideo(server.url, userAccessToken, videoAttributes)
1037 await uploadVideo(server.url, userAccessToken, videoAttributes)
1038 await uploadVideo(server.url, userAccessToken, videoAttributes)
1039 await uploadVideo(server.url, userAccessToken, videoAttributes)
1040 await uploadVideo(server.url, userAccessToken, videoAttributes, 403)
1043 it('Should fail to import with HTTP/Torrent/magnet', async function () {
1044 this.timeout(120000)
1046 const baseAttributes = {
1048 privacy: VideoPrivacy.PUBLIC
1050 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() }))
1051 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() }))
1052 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' as any }))
1054 await waitJobs([ server ])
1056 const res = await getMyVideoImports(server.url, server.accessToken)
1058 expect(res.body.total).to.equal(3)
1059 const videoImports: VideoImport[] = res.body.data
1060 expect(videoImports).to.have.lengthOf(3)
1062 for (const videoImport of videoImports) {
1063 expect(videoImport.state.id).to.equal(VideoImportState.FAILED)
1064 expect(videoImport.error).not.to.be.undefined
1065 expect(videoImport.error).to.contain('user video quota is exceeded')
1070 describe('When having a daily video quota', function () {
1071 it('Should fail with a user having too many videos', async function () {
1075 accessToken: server.accessToken,
1079 await uploadVideo(server.url, server.accessToken, {}, 403)
1083 describe('When having an absolute and daily video quota', function () {
1084 it('Should fail if exceeding total quota', async function () {
1088 accessToken: server.accessToken,
1090 videoQuotaDaily: 1024 * 1024 * 1024
1093 await uploadVideo(server.url, server.accessToken, {}, 403)
1096 it('Should fail if exceeding daily quota', async function () {
1100 accessToken: server.accessToken,
1101 videoQuota: 1024 * 1024 * 1024,
1105 await uploadVideo(server.url, server.accessToken, {}, 403)
1109 describe('When asking a password reset', function () {
1110 const path = '/api/v1/users/ask-reset-password'
1112 it('Should fail with a missing email', async function () {
1115 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1118 it('Should fail with an invalid email', async function () {
1119 const fields = { email: 'hello' }
1121 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1124 it('Should success with the correct params', async function () {
1125 const fields = { email: 'admin@example.com' }
1127 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
1131 describe('When asking for an account verification email', function () {
1132 const path = '/api/v1/users/ask-send-verify-email'
1134 it('Should fail with a missing email', async function () {
1137 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1140 it('Should fail with an invalid email', async function () {
1141 const fields = { email: 'hello' }
1143 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1146 it('Should succeed with the correct params', async function () {
1147 const fields = { email: 'admin@example.com' }
1149 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
1153 after(async function () {
1154 MockSmtpServer.Instance.kill()
1156 await cleanupTests([ server, serverWithRegistrationDisabled ])