1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { FIXTURE_URLS } from '@server/tests/shared'
5 import { randomInt } from '@shared/core-utils'
6 import { HttpStatusCode, VideoImportState, VideoPrivacy } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
15 } from '@shared/server-commands'
17 describe('Test upload quota', function () {
18 let server: PeerTubeServer
20 let command: VideosCommand
22 // ---------------------------------------------------------------
24 before(async function () {
27 server = await createSingleServer(1)
28 await setAccessTokensToServers([ server ])
29 await setDefaultVideoChannel([ server ])
31 const user = await server.users.getMyInfo()
34 await server.users.update({ userId: rootId, videoQuota: 42 })
36 command = server.videos
39 describe('When having a video quota', function () {
41 it('Should fail with a registered user having too many videos with legacy upload', async function () {
44 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
45 await server.registrations.register(user)
46 const userToken = await server.login.getAccessToken(user)
48 const attributes = { fixture: 'video_short2.webm' }
49 for (let i = 0; i < 5; i++) {
50 await command.upload({ token: userToken, attributes })
53 await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
56 it('Should fail with a registered user having too many videos with resumable upload', async function () {
59 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
60 await server.registrations.register(user)
61 const userToken = await server.login.getAccessToken(user)
63 const attributes = { fixture: 'video_short2.webm' }
64 for (let i = 0; i < 5; i++) {
65 await command.upload({ token: userToken, attributes })
68 await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
71 it('Should fail to import with HTTP/Torrent/magnet', async function () {
74 const baseAttributes = {
75 channelId: server.store.channel.id,
76 privacy: VideoPrivacy.PUBLIC
78 await server.imports.importVideo({ attributes: { ...baseAttributes, targetUrl: FIXTURE_URLS.goodVideo } })
79 await server.imports.importVideo({ attributes: { ...baseAttributes, magnetUri: FIXTURE_URLS.magnet } })
80 await server.imports.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } })
82 await waitJobs([ server ])
84 const { total, data: videoImports } = await server.imports.getMyVideoImports()
85 expect(total).to.equal(3)
87 expect(videoImports).to.have.lengthOf(3)
89 for (const videoImport of videoImports) {
90 expect(videoImport.state.id).to.equal(VideoImportState.FAILED)
91 expect(videoImport.error).not.to.be.undefined
92 expect(videoImport.error).to.contain('user video quota is exceeded')
97 describe('When having a daily video quota', function () {
99 it('Should fail with a user having too many videos daily', async function () {
100 await server.users.update({ userId: rootId, videoQuotaDaily: 42 })
102 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
103 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
107 describe('When having an absolute and daily video quota', function () {
108 it('Should fail if exceeding total quota', async function () {
109 await server.users.update({
112 videoQuotaDaily: 1024 * 1024 * 1024
115 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
116 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
119 it('Should fail if exceeding daily quota', async function () {
120 await server.users.update({
122 videoQuota: 1024 * 1024 * 1024,
126 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
127 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
131 after(async function () {
132 await cleanupTests([ server ])