diff options
Diffstat (limited to 'packages/tests/src/api/check-params/upload-quota.ts')
-rw-r--r-- | packages/tests/src/api/check-params/upload-quota.ts | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/packages/tests/src/api/check-params/upload-quota.ts b/packages/tests/src/api/check-params/upload-quota.ts new file mode 100644 index 000000000..a77792822 --- /dev/null +++ b/packages/tests/src/api/check-params/upload-quota.ts | |||
@@ -0,0 +1,134 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { FIXTURE_URLS } from '@tests/shared/tests.js' | ||
5 | import { randomInt } from '@peertube/peertube-core-utils' | ||
6 | import { HttpStatusCode, VideoImportState, VideoPrivacy } from '@peertube/peertube-models' | ||
7 | import { | ||
8 | cleanupTests, | ||
9 | createSingleServer, | ||
10 | PeerTubeServer, | ||
11 | setAccessTokensToServers, | ||
12 | setDefaultVideoChannel, | ||
13 | VideosCommand, | ||
14 | waitJobs | ||
15 | } from '@peertube/peertube-server-commands' | ||
16 | |||
17 | describe('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 | }) | ||