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