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