2021-05-10 04:13:41 -05:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import { expect } from 'chai'
|
2021-12-17 04:58:15 -06:00
|
|
|
import { FIXTURE_URLS } from '@server/tests/shared'
|
2021-07-16 03:42:24 -05:00
|
|
|
import { randomInt } from '@shared/core-utils'
|
2021-12-17 04:58:15 -06:00
|
|
|
import { HttpStatusCode, VideoImportState, VideoPrivacy } from '@shared/models'
|
2021-05-10 04:13:41 -05:00
|
|
|
import {
|
|
|
|
cleanupTests,
|
2021-07-16 02:47:51 -05:00
|
|
|
createSingleServer,
|
|
|
|
PeerTubeServer,
|
2021-05-10 04:13:41 -05:00
|
|
|
setAccessTokensToServers,
|
|
|
|
setDefaultVideoChannel,
|
2021-07-15 03:02:54 -05:00
|
|
|
VideosCommand,
|
2021-05-10 04:13:41 -05:00
|
|
|
waitJobs
|
2021-12-17 02:29:23 -06:00
|
|
|
} from '@shared/server-commands'
|
2021-05-10 04:13:41 -05:00
|
|
|
|
|
|
|
describe('Test upload quota', function () {
|
2021-07-16 02:47:51 -05:00
|
|
|
let server: PeerTubeServer
|
2021-05-10 04:13:41 -05:00
|
|
|
let rootId: number
|
2021-07-15 03:02:54 -05:00
|
|
|
let command: VideosCommand
|
2021-05-10 04:13:41 -05:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2021-07-16 02:47:51 -05:00
|
|
|
server = await createSingleServer(1)
|
2021-05-10 04:13:41 -05:00
|
|
|
await setAccessTokensToServers([ server ])
|
|
|
|
await setDefaultVideoChannel([ server ])
|
|
|
|
|
2021-07-16 02:04:35 -05:00
|
|
|
const user = await server.users.getMyInfo()
|
2021-07-13 07:23:01 -05:00
|
|
|
rootId = user.id
|
2021-05-10 04:13:41 -05:00
|
|
|
|
2021-07-16 02:04:35 -05:00
|
|
|
await server.users.update({ userId: rootId, videoQuota: 42 })
|
2021-07-15 03:02:54 -05:00
|
|
|
|
2021-07-16 02:04:35 -05:00
|
|
|
command = server.videos
|
2021-05-10 04:13:41 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('When having a video quota', function () {
|
|
|
|
|
|
|
|
it('Should fail with a registered user having too many videos with legacy upload', async function () {
|
2023-05-19 07:05:14 -05:00
|
|
|
this.timeout(120000)
|
2021-05-10 04:13:41 -05:00
|
|
|
|
|
|
|
const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
|
2023-01-19 02:28:29 -06:00
|
|
|
await server.registrations.register(user)
|
2021-07-16 02:04:35 -05:00
|
|
|
const userToken = await server.login.getAccessToken(user)
|
2021-05-10 04:13:41 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
const attributes = { fixture: 'video_short2.webm' }
|
2021-05-10 04:13:41 -05:00
|
|
|
for (let i = 0; i < 5; i++) {
|
2021-07-15 03:02:54 -05:00
|
|
|
await command.upload({ token: userToken, attributes })
|
2021-05-10 04:13:41 -05:00
|
|
|
}
|
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
|
2021-05-10 04:13:41 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail with a registered user having too many videos with resumable upload', async function () {
|
2023-05-22 10:04:39 -05:00
|
|
|
this.timeout(120000)
|
2021-05-10 04:13:41 -05:00
|
|
|
|
|
|
|
const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
|
2023-01-19 02:28:29 -06:00
|
|
|
await server.registrations.register(user)
|
2021-07-16 02:04:35 -05:00
|
|
|
const userToken = await server.login.getAccessToken(user)
|
2021-05-10 04:13:41 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
const attributes = { fixture: 'video_short2.webm' }
|
2021-05-10 04:13:41 -05:00
|
|
|
for (let i = 0; i < 5; i++) {
|
2021-07-15 03:02:54 -05:00
|
|
|
await command.upload({ token: userToken, attributes })
|
2021-05-10 04:13:41 -05:00
|
|
|
}
|
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
|
2021-05-10 04:13:41 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail to import with HTTP/Torrent/magnet', async function () {
|
2022-08-10 02:53:39 -05:00
|
|
|
this.timeout(120_000)
|
2021-05-10 04:13:41 -05:00
|
|
|
|
|
|
|
const baseAttributes = {
|
2021-07-16 02:04:35 -05:00
|
|
|
channelId: server.store.channel.id,
|
2021-05-10 04:13:41 -05:00
|
|
|
privacy: VideoPrivacy.PUBLIC
|
|
|
|
}
|
2021-07-16 03:19:16 -05:00
|
|
|
await server.imports.importVideo({ attributes: { ...baseAttributes, targetUrl: FIXTURE_URLS.goodVideo } })
|
|
|
|
await server.imports.importVideo({ attributes: { ...baseAttributes, magnetUri: FIXTURE_URLS.magnet } })
|
2021-07-16 02:04:35 -05:00
|
|
|
await server.imports.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } })
|
2021-05-10 04:13:41 -05:00
|
|
|
|
|
|
|
await waitJobs([ server ])
|
|
|
|
|
2021-07-16 02:04:35 -05:00
|
|
|
const { total, data: videoImports } = await server.imports.getMyVideoImports()
|
2021-07-08 09:49:51 -05:00
|
|
|
expect(total).to.equal(3)
|
2021-05-10 04:13:41 -05:00
|
|
|
|
|
|
|
expect(videoImports).to.have.lengthOf(3)
|
|
|
|
|
|
|
|
for (const videoImport of videoImports) {
|
|
|
|
expect(videoImport.state.id).to.equal(VideoImportState.FAILED)
|
|
|
|
expect(videoImport.error).not.to.be.undefined
|
|
|
|
expect(videoImport.error).to.contain('user video quota is exceeded')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When having a daily video quota', function () {
|
|
|
|
|
|
|
|
it('Should fail with a user having too many videos daily', async function () {
|
2021-07-16 02:04:35 -05:00
|
|
|
await server.users.update({ userId: rootId, videoQuotaDaily: 42 })
|
2021-05-10 04:13:41 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
|
|
|
|
await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
|
2021-05-10 04:13:41 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When having an absolute and daily video quota', function () {
|
|
|
|
it('Should fail if exceeding total quota', async function () {
|
2021-07-16 02:04:35 -05:00
|
|
|
await server.users.update({
|
2021-05-10 04:13:41 -05:00
|
|
|
userId: rootId,
|
|
|
|
videoQuota: 42,
|
|
|
|
videoQuotaDaily: 1024 * 1024 * 1024
|
|
|
|
})
|
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
|
|
|
|
await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
|
2021-05-10 04:13:41 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail if exceeding daily quota', async function () {
|
2021-07-16 02:04:35 -05:00
|
|
|
await server.users.update({
|
2021-05-10 04:13:41 -05:00
|
|
|
userId: rootId,
|
|
|
|
videoQuota: 1024 * 1024 * 1024,
|
|
|
|
videoQuotaDaily: 42
|
|
|
|
})
|
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
|
|
|
|
await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
|
2021-05-10 04:13:41 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await cleanupTests([ server ])
|
|
|
|
})
|
|
|
|
})
|