]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/tests/api/check-params/upload-quota.ts
Update server dependencies
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / upload-quota.ts
... / ...
CommitLineData
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { FIXTURE_URLS } from '@server/tests/shared'
5import { randomInt } from '@shared/core-utils'
6import { HttpStatusCode, VideoImportState, VideoPrivacy } from '@shared/models'
7import {
8 cleanupTests,
9 createSingleServer,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
13 VideosCommand,
14 waitJobs
15} from '@shared/server-commands'
16
17describe('Test upload quota', function () {
18 let server: PeerTubeServer
19 let rootId: number
20 let command: VideosCommand
21
22 // ---------------------------------------------------------------
23
24 before(async function () {
25 this.timeout(30000)
26
27 server = await createSingleServer(1)
28 await setAccessTokensToServers([ server ])
29 await setDefaultVideoChannel([ server ])
30
31 const user = await server.users.getMyInfo()
32 rootId = user.id
33
34 await server.users.update({ userId: rootId, videoQuota: 42 })
35
36 command = server.videos
37 })
38
39 describe('When having a video quota', function () {
40
41 it('Should fail with a registered user having too many videos with legacy upload', async function () {
42 this.timeout(120000)
43
44 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
45 await server.registrations.register(user)
46 const userToken = await server.login.getAccessToken(user)
47
48 const attributes = { fixture: 'video_short2.webm' }
49 for (let i = 0; i < 5; i++) {
50 await command.upload({ token: userToken, attributes })
51 }
52
53 await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
54 })
55
56 it('Should fail with a registered user having too many videos with resumable upload', async function () {
57 this.timeout(120000)
58
59 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
60 await server.registrations.register(user)
61 const userToken = await server.login.getAccessToken(user)
62
63 const attributes = { fixture: 'video_short2.webm' }
64 for (let i = 0; i < 5; i++) {
65 await command.upload({ token: userToken, attributes })
66 }
67
68 await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
69 })
70
71 it('Should fail to import with HTTP/Torrent/magnet', async function () {
72 this.timeout(120_000)
73
74 const baseAttributes = {
75 channelId: server.store.channel.id,
76 privacy: VideoPrivacy.PUBLIC
77 }
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 } })
81
82 await waitJobs([ server ])
83
84 const { total, data: videoImports } = await server.imports.getMyVideoImports()
85 expect(total).to.equal(3)
86
87 expect(videoImports).to.have.lengthOf(3)
88
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')
93 }
94 })
95 })
96
97 describe('When having a daily video quota', function () {
98
99 it('Should fail with a user having too many videos daily', async function () {
100 await server.users.update({ userId: rootId, videoQuotaDaily: 42 })
101
102 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
103 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
104 })
105 })
106
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({
110 userId: rootId,
111 videoQuota: 42,
112 videoQuotaDaily: 1024 * 1024 * 1024
113 })
114
115 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
116 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
117 })
118
119 it('Should fail if exceeding daily quota', async function () {
120 await server.users.update({
121 userId: rootId,
122 videoQuota: 1024 * 1024 * 1024,
123 videoQuotaDaily: 42
124 })
125
126 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
127 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
128 })
129 })
130
131 after(async function () {
132 await cleanupTests([ server ])
133 })
134})