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