1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { FIXTURE_URLS } from '@server/tests/shared'
6 import { randomInt } from '@shared/core-utils'
7 import { HttpStatusCode, VideoImportState, VideoPrivacy } from '@shared/models'
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
16 } from '@shared/server-commands'
18 describe('Test upload quota', function () {
19 let server: PeerTubeServer
21 let command: VideosCommand
23 // ---------------------------------------------------------------
25 before(async function () {
28 server = await createSingleServer(1)
29 await setAccessTokensToServers([ server ])
30 await setDefaultVideoChannel([ server ])
32 const user = await server.users.getMyInfo()
35 await server.users.update({ userId: rootId, videoQuota: 42 })
37 command = server.videos
40 describe('When having a video quota', function () {
42 it('Should fail with a registered user having too many videos with legacy upload', async function () {
45 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
46 await server.users.register(user)
47 const userToken = await server.login.getAccessToken(user)
49 const attributes = { fixture: 'video_short2.webm' }
50 for (let i = 0; i < 5; i++) {
51 await command.upload({ token: userToken, attributes })
54 await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
57 it('Should fail with a registered user having too many videos with resumable upload', async function () {
60 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
61 await server.users.register(user)
62 const userToken = await server.login.getAccessToken(user)
64 const attributes = { fixture: 'video_short2.webm' }
65 for (let i = 0; i < 5; i++) {
66 await command.upload({ token: userToken, attributes })
69 await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
72 it('Should fail to import with HTTP/Torrent/magnet', async function () {
75 const baseAttributes = {
76 channelId: server.store.channel.id,
77 privacy: VideoPrivacy.PUBLIC
79 await server.imports.importVideo({ attributes: { ...baseAttributes, targetUrl: FIXTURE_URLS.goodVideo } })
80 await server.imports.importVideo({ attributes: { ...baseAttributes, magnetUri: FIXTURE_URLS.magnet } })
81 await server.imports.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } })
83 await waitJobs([ server ])
85 const { total, data: videoImports } = await server.imports.getMyVideoImports()
86 expect(total).to.equal(3)
88 expect(videoImports).to.have.lengthOf(3)
90 for (const videoImport of videoImports) {
91 expect(videoImport.state.id).to.equal(VideoImportState.FAILED)
92 expect(videoImport.error).not.to.be.undefined
93 expect(videoImport.error).to.contain('user video quota is exceeded')
98 describe('When having a daily video quota', function () {
100 it('Should fail with a user having too many videos daily', async function () {
101 await server.users.update({ userId: rootId, videoQuotaDaily: 42 })
103 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
104 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
108 describe('When having an absolute and daily video quota', function () {
109 it('Should fail if exceeding total quota', async function () {
110 await server.users.update({
113 videoQuotaDaily: 1024 * 1024 * 1024
116 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
117 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
120 it('Should fail if exceeding daily quota', async function () {
121 await server.users.update({
123 videoQuota: 1024 * 1024 * 1024,
127 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
128 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
132 after(async function () {
133 await cleanupTests([ server ])