]>
Commit | Line | Data |
---|---|---|
f6d6e7f8 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
f6d6e7f8 | 3 | import { expect } from 'chai' |
c55e3d72 | 4 | import { FIXTURE_URLS } from '@server/tests/shared' |
c0e8b12e | 5 | import { randomInt } from '@shared/core-utils' |
c55e3d72 | 6 | import { HttpStatusCode, VideoImportState, VideoPrivacy } from '@shared/models' |
f6d6e7f8 | 7 | import { |
8 | cleanupTests, | |
254d3579 | 9 | createSingleServer, |
254d3579 | 10 | PeerTubeServer, |
f6d6e7f8 | 11 | setAccessTokensToServers, |
12 | setDefaultVideoChannel, | |
d23dd9fb | 13 | VideosCommand, |
f6d6e7f8 | 14 | waitJobs |
bf54587a | 15 | } from '@shared/server-commands' |
f6d6e7f8 | 16 | |
17 | describe('Test upload quota', function () { | |
254d3579 | 18 | let server: PeerTubeServer |
f6d6e7f8 | 19 | let rootId: number |
d23dd9fb | 20 | let command: VideosCommand |
f6d6e7f8 | 21 | |
22 | // --------------------------------------------------------------- | |
23 | ||
24 | before(async function () { | |
25 | this.timeout(30000) | |
26 | ||
254d3579 | 27 | server = await createSingleServer(1) |
f6d6e7f8 | 28 | await setAccessTokensToServers([ server ]) |
29 | await setDefaultVideoChannel([ server ]) | |
30 | ||
89d241a7 | 31 | const user = await server.users.getMyInfo() |
7926c5f9 | 32 | rootId = user.id |
f6d6e7f8 | 33 | |
89d241a7 | 34 | await server.users.update({ userId: rootId, videoQuota: 42 }) |
d23dd9fb | 35 | |
89d241a7 | 36 | command = server.videos |
f6d6e7f8 | 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(30000) | |
43 | ||
44 | const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } | |
b379759f | 45 | await server.registrations.register(user) |
89d241a7 | 46 | const userToken = await server.login.getAccessToken(user) |
f6d6e7f8 | 47 | |
d23dd9fb | 48 | const attributes = { fixture: 'video_short2.webm' } |
f6d6e7f8 | 49 | for (let i = 0; i < 5; i++) { |
d23dd9fb | 50 | await command.upload({ token: userToken, attributes }) |
f6d6e7f8 | 51 | } |
52 | ||
d23dd9fb | 53 | await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) |
f6d6e7f8 | 54 | }) |
55 | ||
56 | it('Should fail with a registered user having too many videos with resumable upload', async function () { | |
57 | this.timeout(30000) | |
58 | ||
59 | const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } | |
b379759f | 60 | await server.registrations.register(user) |
89d241a7 | 61 | const userToken = await server.login.getAccessToken(user) |
f6d6e7f8 | 62 | |
d23dd9fb | 63 | const attributes = { fixture: 'video_short2.webm' } |
f6d6e7f8 | 64 | for (let i = 0; i < 5; i++) { |
d23dd9fb | 65 | await command.upload({ token: userToken, attributes }) |
f6d6e7f8 | 66 | } |
67 | ||
d23dd9fb | 68 | await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) |
f6d6e7f8 | 69 | }) |
70 | ||
71 | it('Should fail to import with HTTP/Torrent/magnet', async function () { | |
2a491182 | 72 | this.timeout(120_000) |
f6d6e7f8 | 73 | |
74 | const baseAttributes = { | |
89d241a7 | 75 | channelId: server.store.channel.id, |
f6d6e7f8 | 76 | privacy: VideoPrivacy.PUBLIC |
77 | } | |
59bbcced C |
78 | await server.imports.importVideo({ attributes: { ...baseAttributes, targetUrl: FIXTURE_URLS.goodVideo } }) |
79 | await server.imports.importVideo({ attributes: { ...baseAttributes, magnetUri: FIXTURE_URLS.magnet } }) | |
89d241a7 | 80 | await server.imports.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } }) |
f6d6e7f8 | 81 | |
82 | await waitJobs([ server ]) | |
83 | ||
89d241a7 | 84 | const { total, data: videoImports } = await server.imports.getMyVideoImports() |
6910f20f | 85 | expect(total).to.equal(3) |
f6d6e7f8 | 86 | |
f6d6e7f8 | 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 () { | |
89d241a7 | 100 | await server.users.update({ userId: rootId, videoQuotaDaily: 42 }) |
f6d6e7f8 | 101 | |
d23dd9fb C |
102 | await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) |
103 | await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) | |
f6d6e7f8 | 104 | }) |
105 | }) | |
106 | ||
107 | describe('When having an absolute and daily video quota', function () { | |
108 | it('Should fail if exceeding total quota', async function () { | |
89d241a7 | 109 | await server.users.update({ |
f6d6e7f8 | 110 | userId: rootId, |
f6d6e7f8 | 111 | videoQuota: 42, |
112 | videoQuotaDaily: 1024 * 1024 * 1024 | |
113 | }) | |
114 | ||
d23dd9fb C |
115 | await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) |
116 | await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) | |
f6d6e7f8 | 117 | }) |
118 | ||
119 | it('Should fail if exceeding daily quota', async function () { | |
89d241a7 | 120 | await server.users.update({ |
f6d6e7f8 | 121 | userId: rootId, |
f6d6e7f8 | 122 | videoQuota: 1024 * 1024 * 1024, |
123 | videoQuotaDaily: 42 | |
124 | }) | |
125 | ||
d23dd9fb C |
126 | await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) |
127 | await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) | |
f6d6e7f8 | 128 | }) |
129 | }) | |
130 | ||
131 | after(async function () { | |
132 | await cleanupTests([ server ]) | |
133 | }) | |
134 | }) |