1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { omit } from 'lodash'
6 import { join } from 'path'
7 import { User, UserRole, VideoImport, VideoImportState } from '../../../../shared'
28 setAccessTokensToServers,
33 } from '../../../../shared/extra-utils'
34 import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
36 checkBadCountPagination,
37 checkBadSortPagination,
38 checkBadStartPagination
39 } from '../../../../shared/extra-utils/requests/check-api-params'
40 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
41 import { getMagnetURI, getMyVideoImports, getGoodVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
42 import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
43 import { VideoPrivacy } from '../../../../shared/models/videos'
45 describe('Test users API validators', function () {
46 const path = '/api/v1/users/'
49 let moderatorId: number
51 let server: ServerInfo
52 let serverWithRegistrationDisabled: ServerInfo
53 let userAccessToken = ''
54 let moderatorAccessToken = ''
56 let overrideConfig: Object
58 // ---------------------------------------------------------------
60 before(async function () {
63 const emails: object[] = []
64 emailPort = await MockSmtpServer.Instance.collectEmails(emails)
66 overrideConfig = { signup: { limit: 8 } }
69 const res = await Promise.all([
70 flushAndRunServer(1, overrideConfig),
75 serverWithRegistrationDisabled = res[1]
77 await setAccessTokensToServers([ server ])
83 password: 'my super password'
86 const videoQuota = 42000000
89 accessToken: server.accessToken,
90 username: user.username,
91 password: user.password,
92 videoQuota: videoQuota
94 userAccessToken = await userLogin(server, user)
99 username: 'moderator1',
100 password: 'super password'
105 accessToken: server.accessToken,
106 username: moderator.username,
107 password: moderator.password,
108 role: UserRole.MODERATOR
111 moderatorAccessToken = await userLogin(server, moderator)
116 username: 'moderator2',
117 password: 'super password'
122 accessToken: server.accessToken,
123 username: moderator.username,
124 password: moderator.password,
125 role: UserRole.MODERATOR
130 const res = await uploadVideo(server.url, server.accessToken, {})
131 videoId = res.body.video.id
135 const res = await getUsersList(server.url, server.accessToken)
136 const users: User[] = res.body.data
138 userId = users.find(u => u.username === 'user1').id
139 rootId = users.find(u => u.username === 'root').id
140 moderatorId = users.find(u => u.username === 'moderator2').id
144 describe('When listing users', function () {
145 it('Should fail with a bad start pagination', async function () {
146 await checkBadStartPagination(server.url, path, server.accessToken)
149 it('Should fail with a bad count pagination', async function () {
150 await checkBadCountPagination(server.url, path, server.accessToken)
153 it('Should fail with an incorrect sort', async function () {
154 await checkBadSortPagination(server.url, path, server.accessToken)
157 it('Should fail with a bad blocked/banned user filter', async function () {
158 await makeGetRequest({
164 token: server.accessToken,
165 statusCodeExpected: 400
169 it('Should fail with a non authenticated user', async function () {
170 await makeGetRequest({
173 statusCodeExpected: 401
177 it('Should fail with a non admin user', async function () {
178 await makeGetRequest({
181 token: userAccessToken,
182 statusCodeExpected: 403
187 describe('When adding a new user', function () {
188 const baseCorrectParams = {
190 email: 'test@example.com',
191 password: 'my super password',
195 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
198 it('Should fail with a too small username', async function () {
199 const fields = immutableAssign(baseCorrectParams, { username: '' })
201 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
204 it('Should fail with a too long username', async function () {
205 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
207 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
210 it('Should fail with a not lowercase username', async function () {
211 const fields = immutableAssign(baseCorrectParams, { username: 'Toto' })
213 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
216 it('Should fail with an incorrect username', async function () {
217 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
219 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
222 it('Should fail with a missing email', async function () {
223 const fields = omit(baseCorrectParams, 'email')
225 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
228 it('Should fail with an invalid email', async function () {
229 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
231 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
234 it('Should fail with a too small password', async function () {
235 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
237 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
240 it('Should fail with a too long password', async function () {
241 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
243 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
246 it('Should fail with empty password and no smtp configured', async function () {
247 const fields = immutableAssign(baseCorrectParams, { password: '' })
249 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
252 it('Should succeed with no password on a server with smtp enabled', async function () {
255 killallServers([ server ])
257 const config = immutableAssign(overrideConfig, {
259 hostname: 'localhost',
263 await reRunServer(server, config)
265 const fields = immutableAssign(baseCorrectParams, {
267 username: 'create_password',
268 email: 'create_password@example.com'
271 await makePostBodyRequest({
274 token: server.accessToken,
276 statusCodeExpected: 200
280 it('Should fail with invalid admin flags', async function () {
281 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' })
283 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
286 it('Should fail with an non authenticated user', async function () {
287 await makePostBodyRequest({
290 token: 'super token',
291 fields: baseCorrectParams,
292 statusCodeExpected: 401
296 it('Should fail if we add a user with the same username', async function () {
297 const fields = immutableAssign(baseCorrectParams, { username: 'user1' })
299 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
302 it('Should fail if we add a user with the same email', async function () {
303 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' })
305 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
308 it('Should fail without a videoQuota', async function () {
309 const fields = omit(baseCorrectParams, 'videoQuota')
311 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
314 it('Should fail without a videoQuotaDaily', async function () {
315 const fields = omit(baseCorrectParams, 'videoQuotaDaily')
317 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
320 it('Should fail with an invalid videoQuota', async function () {
321 const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 })
323 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
326 it('Should fail with an invalid videoQuotaDaily', async function () {
327 const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 })
329 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
332 it('Should fail without a user role', async function () {
333 const fields = omit(baseCorrectParams, 'role')
335 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
338 it('Should fail with an invalid user role', async function () {
339 const fields = immutableAssign(baseCorrectParams, { role: 88989 })
341 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
344 it('Should fail with a "peertube" username', async function () {
345 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
347 await makePostBodyRequest({
350 token: server.accessToken,
352 statusCodeExpected: 409
356 it('Should fail to create a moderator or an admin with a moderator', async function () {
357 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
358 const fields = immutableAssign(baseCorrectParams, { role })
360 await makePostBodyRequest({
363 token: moderatorAccessToken,
365 statusCodeExpected: 403
370 it('Should succeed to create a user with a moderator', async function () {
371 const fields = immutableAssign(baseCorrectParams, { username: 'a4656', email: 'a4656@example.com', role: UserRole.USER })
373 await makePostBodyRequest({
376 token: moderatorAccessToken,
378 statusCodeExpected: 200
382 it('Should succeed with the correct params', async function () {
383 await makePostBodyRequest({
386 token: server.accessToken,
387 fields: baseCorrectParams,
388 statusCodeExpected: 200
392 it('Should fail with a non admin user', async function () {
395 password: 'my super password'
397 userAccessToken = await userLogin(server, user)
401 email: 'test@example.com',
402 password: 'my super password',
405 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
409 describe('When updating my account', function () {
410 it('Should fail with an invalid email attribute', async function () {
415 await makePutBodyRequest({ url: server.url, path: path + 'me', token: server.accessToken, fields })
418 it('Should fail with a too small password', async function () {
420 currentPassword: 'my super password',
424 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
427 it('Should fail with a too long password', async function () {
429 currentPassword: 'my super password',
430 password: 'super'.repeat(61)
433 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
436 it('Should fail without the current password', async function () {
438 currentPassword: 'my super password',
439 password: 'super'.repeat(61)
442 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
445 it('Should fail with an invalid current password', async function () {
447 currentPassword: 'my super password fail',
448 password: 'super'.repeat(61)
451 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 401 })
454 it('Should fail with an invalid NSFW policy attribute', async function () {
459 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
462 it('Should fail with an invalid autoPlayVideo attribute', async function () {
467 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
470 it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
472 autoPlayNextVideo: -1
475 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
478 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
480 videosHistoryEnabled: -1
483 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
486 it('Should fail with an non authenticated user', async function () {
488 currentPassword: 'my super password',
489 password: 'my super password'
492 await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 })
495 it('Should fail with a too long description', async function () {
497 description: 'super'.repeat(201)
500 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
503 it('Should fail with an invalid videoLanguages attribute', async function () {
506 videoLanguages: 'toto'
509 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
514 for (let i = 0; i < 1000; i++) {
519 videoLanguages: languages
522 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
526 it('Should fail with an invalid theme', async function () {
527 const fields = { theme: 'invalid' }
528 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
531 it('Should fail with an unknown theme', async function () {
532 const fields = { theme: 'peertube-theme-unknown' }
533 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
536 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
538 noInstanceConfigWarningModal: -1
541 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
544 it('Should fail with an invalid noWelcomeModal attribute', async function () {
549 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
552 it('Should succeed to change password with the correct params', async function () {
554 currentPassword: 'my super password',
555 password: 'my super password',
557 autoPlayVideo: false,
558 email: 'super_email@example.com',
560 noInstanceConfigWarningModal: true,
564 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
567 it('Should succeed without password change with the correct params', async function () {
573 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
577 describe('When updating my avatar', function () {
578 it('Should fail without an incorrect input file', async function () {
581 avatarfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
583 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
586 it('Should fail with a big file', async function () {
589 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
591 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
594 it('Should fail with an unauthenticated user', async function () {
597 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
599 await makeUploadRequest({
601 path: path + '/me/avatar/pick',
604 statusCodeExpected: 401
608 it('Should succeed with the correct params', async function () {
611 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
613 await makeUploadRequest({
615 path: path + '/me/avatar/pick',
616 token: server.accessToken,
619 statusCodeExpected: 200
624 describe('When getting a user', function () {
626 it('Should fail with an non authenticated user', async function () {
627 await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 })
630 it('Should fail with a non admin user', async function () {
631 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 })
634 it('Should succeed with the correct params', async function () {
635 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 })
639 describe('When updating a user', function () {
641 it('Should fail with an invalid email attribute', async function () {
646 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
649 it('Should fail with an invalid emailVerified attribute', async function () {
654 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
657 it('Should fail with an invalid videoQuota attribute', async function () {
662 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
665 it('Should fail with an invalid user role attribute', async function () {
670 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
673 it('Should fail with a too small password', async function () {
675 currentPassword: 'my super password',
679 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
682 it('Should fail with a too long password', async function () {
684 currentPassword: 'my super password',
685 password: 'super'.repeat(61)
688 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
691 it('Should fail with an non authenticated user', async function () {
696 await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 })
699 it('Should fail when updating root role', async function () {
701 role: UserRole.MODERATOR
704 await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
707 it('Should fail with invalid admin flags', async function () {
708 const fields = { adminFlags: 'toto' }
710 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
713 it('Should fail to update an admin with a moderator', async function () {
718 await makePutBodyRequest({
720 path: path + moderatorId,
721 token: moderatorAccessToken,
723 statusCodeExpected: 403
727 it('Should succeed to update a user with a moderator', async function () {
732 await makePutBodyRequest({
735 token: moderatorAccessToken,
737 statusCodeExpected: 204
741 it('Should succeed with the correct params', async function () {
743 email: 'email@example.com',
749 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 })
753 describe('When getting my information', function () {
754 it('Should fail with a non authenticated user', async function () {
755 await getMyUserInformation(server.url, 'fake_token', 401)
758 it('Should success with the correct parameters', async function () {
759 await getMyUserInformation(server.url, userAccessToken)
763 describe('When getting my video rating', function () {
764 it('Should fail with a non authenticated user', async function () {
765 await getMyUserVideoRating(server.url, 'fake_token', videoId, 401)
768 it('Should fail with an incorrect video uuid', async function () {
769 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400)
772 it('Should fail with an unknown video', async function () {
773 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
776 it('Should succeed with the correct parameters', async function () {
777 await getMyUserVideoRating(server.url, server.accessToken, videoId)
781 describe('When retrieving my global ratings', function () {
782 const path = '/api/v1/accounts/user1/ratings'
784 it('Should fail with a bad start pagination', async function () {
785 await checkBadStartPagination(server.url, path, userAccessToken)
788 it('Should fail with a bad count pagination', async function () {
789 await checkBadCountPagination(server.url, path, userAccessToken)
792 it('Should fail with an incorrect sort', async function () {
793 await checkBadSortPagination(server.url, path, userAccessToken)
796 it('Should fail with a unauthenticated user', async function () {
797 await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 })
800 it('Should fail with a another user', async function () {
801 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 })
804 it('Should fail with a bad type', async function () {
805 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 })
808 it('Should succeed with the correct params', async function () {
809 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 })
813 describe('When blocking/unblocking/removing user', function () {
814 it('Should fail with an incorrect id', async function () {
815 await removeUser(server.url, 'blabla', server.accessToken, 400)
816 await blockUser(server.url, 'blabla', server.accessToken, 400)
817 await unblockUser(server.url, 'blabla', server.accessToken, 400)
820 it('Should fail with the root user', async function () {
821 await removeUser(server.url, rootId, server.accessToken, 400)
822 await blockUser(server.url, rootId, server.accessToken, 400)
823 await unblockUser(server.url, rootId, server.accessToken, 400)
826 it('Should return 404 with a non existing id', async function () {
827 await removeUser(server.url, 4545454, server.accessToken, 404)
828 await blockUser(server.url, 4545454, server.accessToken, 404)
829 await unblockUser(server.url, 4545454, server.accessToken, 404)
832 it('Should fail with a non admin user', async function () {
833 await removeUser(server.url, userId, userAccessToken, 403)
834 await blockUser(server.url, userId, userAccessToken, 403)
835 await unblockUser(server.url, userId, userAccessToken, 403)
838 it('Should fail on a moderator with a moderator', async function () {
839 await removeUser(server.url, moderatorId, moderatorAccessToken, 403)
840 await blockUser(server.url, moderatorId, moderatorAccessToken, 403)
841 await unblockUser(server.url, moderatorId, moderatorAccessToken, 403)
844 it('Should succeed on a user with a moderator', async function () {
845 await blockUser(server.url, userId, moderatorAccessToken)
846 await unblockUser(server.url, userId, moderatorAccessToken)
850 describe('When deleting our account', function () {
851 it('Should fail with with the root account', async function () {
852 await deleteMe(server.url, server.accessToken, 400)
856 describe('When registering a new user', function () {
857 const registrationPath = path + '/register'
858 const baseCorrectParams = {
860 displayName: 'super user',
861 email: 'test3@example.com',
862 password: 'my super password'
865 it('Should fail with a too small username', async function () {
866 const fields = immutableAssign(baseCorrectParams, { username: '' })
868 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
871 it('Should fail with a too long username', async function () {
872 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) })
874 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
877 it('Should fail with an incorrect username', async function () {
878 const fields = immutableAssign(baseCorrectParams, { username: 'my username' })
880 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
883 it('Should fail with a missing email', async function () {
884 const fields = omit(baseCorrectParams, 'email')
886 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
889 it('Should fail with an invalid email', async function () {
890 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' })
892 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
895 it('Should fail with a too small password', async function () {
896 const fields = immutableAssign(baseCorrectParams, { password: 'bla' })
898 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
901 it('Should fail with a too long password', async function () {
902 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) })
904 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
907 it('Should fail if we register a user with the same username', async function () {
908 const fields = immutableAssign(baseCorrectParams, { username: 'root' })
910 await makePostBodyRequest({
912 path: registrationPath,
913 token: server.accessToken,
915 statusCodeExpected: 409
919 it('Should fail with a "peertube" username', async function () {
920 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' })
922 await makePostBodyRequest({
924 path: registrationPath,
925 token: server.accessToken,
927 statusCodeExpected: 409
931 it('Should fail if we register a user with the same email', async function () {
932 const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' })
934 await makePostBodyRequest({
936 path: registrationPath,
937 token: server.accessToken,
939 statusCodeExpected: 409
943 it('Should fail with a bad display name', async function () {
944 const fields = immutableAssign(baseCorrectParams, { displayName: 'a'.repeat(150) })
946 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
949 it('Should fail with a bad channel name', async function () {
950 const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } })
952 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
955 it('Should fail with a bad channel display name', async function () {
956 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } })
958 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
961 it('Should fail with a channel name that is the same as username', async function () {
962 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
963 const fields = immutableAssign(baseCorrectParams, source)
965 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
968 it('Should fail with an existing channel', async function () {
969 const videoChannelAttributesArg = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
970 await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg)
972 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } })
974 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields, statusCodeExpected: 409 })
977 it('Should succeed with the correct params', async function () {
978 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } })
980 await makePostBodyRequest({
982 path: registrationPath,
983 token: server.accessToken,
985 statusCodeExpected: 204
989 it('Should fail on a server with registration disabled', async function () {
992 email: 'test4@example.com',
993 password: 'my super password 4'
996 await makePostBodyRequest({
997 url: serverWithRegistrationDisabled.url,
998 path: registrationPath,
999 token: serverWithRegistrationDisabled.accessToken,
1001 statusCodeExpected: 403
1006 describe('When registering multiple users on a server with users limit', function () {
1007 it('Should fail when after 3 registrations', async function () {
1008 await registerUser(server.url, 'user42', 'super password', 403)
1012 describe('When having a video quota', function () {
1013 it('Should fail with a user having too many videos', async function () {
1017 accessToken: server.accessToken,
1021 await uploadVideo(server.url, server.accessToken, {}, 403)
1024 it('Should fail with a registered user having too many videos', async function () {
1029 password: 'my super password'
1031 userAccessToken = await userLogin(server, user)
1033 const videoAttributes = { fixture: 'video_short2.webm' }
1034 await uploadVideo(server.url, userAccessToken, videoAttributes)
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, 403)
1042 it('Should fail to import with HTTP/Torrent/magnet', async function () {
1043 this.timeout(120000)
1045 const baseAttributes = {
1047 privacy: VideoPrivacy.PUBLIC
1049 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getGoodVideoUrl() }))
1050 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() }))
1051 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' as any }))
1053 await waitJobs([ server ])
1055 const res = await getMyVideoImports(server.url, server.accessToken)
1057 expect(res.body.total).to.equal(3)
1058 const videoImports: VideoImport[] = res.body.data
1059 expect(videoImports).to.have.lengthOf(3)
1061 for (const videoImport of videoImports) {
1062 expect(videoImport.state.id).to.equal(VideoImportState.FAILED)
1063 expect(videoImport.error).not.to.be.undefined
1064 expect(videoImport.error).to.contain('user video quota is exceeded')
1069 describe('When having a daily video quota', function () {
1070 it('Should fail with a user having too many videos', async function () {
1074 accessToken: server.accessToken,
1078 await uploadVideo(server.url, server.accessToken, {}, 403)
1082 describe('When having an absolute and daily video quota', function () {
1083 it('Should fail if exceeding total quota', async function () {
1087 accessToken: server.accessToken,
1089 videoQuotaDaily: 1024 * 1024 * 1024
1092 await uploadVideo(server.url, server.accessToken, {}, 403)
1095 it('Should fail if exceeding daily quota', async function () {
1099 accessToken: server.accessToken,
1100 videoQuota: 1024 * 1024 * 1024,
1104 await uploadVideo(server.url, server.accessToken, {}, 403)
1108 describe('When asking a password reset', function () {
1109 const path = '/api/v1/users/ask-reset-password'
1111 it('Should fail with a missing email', async function () {
1114 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1117 it('Should fail with an invalid email', async function () {
1118 const fields = { email: 'hello' }
1120 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1123 it('Should success with the correct params', async function () {
1124 const fields = { email: 'admin@example.com' }
1126 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
1130 describe('When asking for an account verification email', function () {
1131 const path = '/api/v1/users/ask-send-verify-email'
1133 it('Should fail with a missing email', async function () {
1136 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1139 it('Should fail with an invalid email', async function () {
1140 const fields = { email: 'hello' }
1142 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
1145 it('Should succeed with the correct params', async function () {
1146 const fields = { email: 'admin@example.com' }
1148 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
1152 after(async function () {
1153 MockSmtpServer.Instance.kill()
1155 await cleanupTests([ server, serverWithRegistrationDisabled ])