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