]>
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' | |
5 | import { HttpStatusCode, randomInt } from '@shared/core-utils' | |
6910f20f | 6 | import { MyUser, VideoImportState, VideoPrivacy } from '@shared/models' |
f6d6e7f8 | 7 | import { |
8 | cleanupTests, | |
9 | flushAndRunServer, | |
10 | getMyUserInformation, | |
6910f20f | 11 | ImportsCommand, |
f6d6e7f8 | 12 | registerUser, |
13 | ServerInfo, | |
14 | setAccessTokensToServers, | |
15 | setDefaultVideoChannel, | |
16 | updateUser, | |
17 | uploadVideo, | |
18 | userLogin, | |
19 | waitJobs | |
20 | } from '../../../../shared/extra-utils' | |
21 | ||
22 | describe('Test upload quota', function () { | |
23 | let server: ServerInfo | |
24 | let rootId: number | |
25 | ||
26 | // --------------------------------------------------------------- | |
27 | ||
28 | before(async function () { | |
29 | this.timeout(30000) | |
30 | ||
31 | server = await flushAndRunServer(1) | |
32 | await setAccessTokensToServers([ server ]) | |
33 | await setDefaultVideoChannel([ server ]) | |
34 | ||
35 | const res = await getMyUserInformation(server.url, server.accessToken) | |
36 | rootId = (res.body as MyUser).id | |
37 | ||
38 | await updateUser({ | |
39 | url: server.url, | |
40 | userId: rootId, | |
41 | accessToken: server.accessToken, | |
42 | videoQuota: 42 | |
43 | }) | |
44 | }) | |
45 | ||
46 | describe('When having a video quota', function () { | |
47 | ||
48 | it('Should fail with a registered user having too many videos with legacy upload', async function () { | |
49 | this.timeout(30000) | |
50 | ||
51 | const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } | |
52 | await registerUser(server.url, user.username, user.password) | |
53 | const userAccessToken = await userLogin(server, user) | |
54 | ||
55 | const videoAttributes = { fixture: 'video_short2.webm' } | |
56 | for (let i = 0; i < 5; i++) { | |
57 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
58 | } | |
59 | ||
60 | await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') | |
61 | }) | |
62 | ||
63 | it('Should fail with a registered user having too many videos with resumable upload', async function () { | |
64 | this.timeout(30000) | |
65 | ||
66 | const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } | |
67 | await registerUser(server.url, user.username, user.password) | |
68 | const userAccessToken = await userLogin(server, user) | |
69 | ||
70 | const videoAttributes = { fixture: 'video_short2.webm' } | |
71 | for (let i = 0; i < 5; i++) { | |
72 | await uploadVideo(server.url, userAccessToken, videoAttributes) | |
73 | } | |
74 | ||
75 | await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') | |
76 | }) | |
77 | ||
78 | it('Should fail to import with HTTP/Torrent/magnet', async function () { | |
79 | this.timeout(120000) | |
80 | ||
81 | const baseAttributes = { | |
82 | channelId: server.videoChannel.id, | |
83 | privacy: VideoPrivacy.PUBLIC | |
84 | } | |
6910f20f C |
85 | await server.importsCommand.importVideo({ attributes: { ...baseAttributes, targetUrl: ImportsCommand.getGoodVideoUrl() } }) |
86 | await server.importsCommand.importVideo({ attributes: { ...baseAttributes, magnetUri: ImportsCommand.getMagnetURI() } }) | |
87 | await server.importsCommand.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } }) | |
f6d6e7f8 | 88 | |
89 | await waitJobs([ server ]) | |
90 | ||
6910f20f C |
91 | const { total, data: videoImports } = await server.importsCommand.getMyVideoImports() |
92 | expect(total).to.equal(3) | |
f6d6e7f8 | 93 | |
f6d6e7f8 | 94 | expect(videoImports).to.have.lengthOf(3) |
95 | ||
96 | for (const videoImport of videoImports) { | |
97 | expect(videoImport.state.id).to.equal(VideoImportState.FAILED) | |
98 | expect(videoImport.error).not.to.be.undefined | |
99 | expect(videoImport.error).to.contain('user video quota is exceeded') | |
100 | } | |
101 | }) | |
102 | }) | |
103 | ||
104 | describe('When having a daily video quota', function () { | |
105 | ||
106 | it('Should fail with a user having too many videos daily', async function () { | |
107 | await updateUser({ | |
108 | url: server.url, | |
109 | userId: rootId, | |
110 | accessToken: server.accessToken, | |
111 | videoQuotaDaily: 42 | |
112 | }) | |
113 | ||
114 | await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') | |
115 | await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') | |
116 | }) | |
117 | }) | |
118 | ||
119 | describe('When having an absolute and daily video quota', function () { | |
120 | it('Should fail if exceeding total quota', async function () { | |
121 | await updateUser({ | |
122 | url: server.url, | |
123 | userId: rootId, | |
124 | accessToken: server.accessToken, | |
125 | videoQuota: 42, | |
126 | videoQuotaDaily: 1024 * 1024 * 1024 | |
127 | }) | |
128 | ||
129 | await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') | |
130 | await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') | |
131 | }) | |
132 | ||
133 | it('Should fail if exceeding daily quota', async function () { | |
134 | await updateUser({ | |
135 | url: server.url, | |
136 | userId: rootId, | |
137 | accessToken: server.accessToken, | |
138 | videoQuota: 1024 * 1024 * 1024, | |
139 | videoQuotaDaily: 42 | |
140 | }) | |
141 | ||
142 | await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') | |
143 | await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') | |
144 | }) | |
145 | }) | |
146 | ||
147 | after(async function () { | |
148 | await cleanupTests([ server ]) | |
149 | }) | |
150 | }) |