aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/upload-quota.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/upload-quota.ts')
-rw-r--r--server/tests/api/check-params/upload-quota.ts97
1 files changed, 40 insertions, 57 deletions
diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts
index d0fbec415..322e93d0d 100644
--- a/server/tests/api/check-params/upload-quota.ts
+++ b/server/tests/api/check-params/upload-quota.ts
@@ -2,46 +2,39 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode, randomInt } from '@shared/core-utils' 5import { randomInt } from '@shared/core-utils'
6import { getGoodVideoUrl, getMagnetURI, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports'
7import { MyUser, VideoImport, VideoImportState, VideoPrivacy } from '@shared/models'
8import { 6import {
9 cleanupTests, 7 cleanupTests,
10 flushAndRunServer, 8 createSingleServer,
11 getMyUserInformation, 9 FIXTURE_URLS,
12 immutableAssign, 10 PeerTubeServer,
13 registerUser,
14 ServerInfo,
15 setAccessTokensToServers, 11 setAccessTokensToServers,
16 setDefaultVideoChannel, 12 setDefaultVideoChannel,
17 updateUser, 13 VideosCommand,
18 uploadVideo,
19 userLogin,
20 waitJobs 14 waitJobs
21} from '../../../../shared/extra-utils' 15} from '@shared/extra-utils'
16import { HttpStatusCode, VideoImportState, VideoPrivacy } from '@shared/models'
22 17
23describe('Test upload quota', function () { 18describe('Test upload quota', function () {
24 let server: ServerInfo 19 let server: PeerTubeServer
25 let rootId: number 20 let rootId: number
21 let command: VideosCommand
26 22
27 // --------------------------------------------------------------- 23 // ---------------------------------------------------------------
28 24
29 before(async function () { 25 before(async function () {
30 this.timeout(30000) 26 this.timeout(30000)
31 27
32 server = await flushAndRunServer(1) 28 server = await createSingleServer(1)
33 await setAccessTokensToServers([ server ]) 29 await setAccessTokensToServers([ server ])
34 await setDefaultVideoChannel([ server ]) 30 await setDefaultVideoChannel([ server ])
35 31
36 const res = await getMyUserInformation(server.url, server.accessToken) 32 const user = await server.users.getMyInfo()
37 rootId = (res.body as MyUser).id 33 rootId = user.id
38 34
39 await updateUser({ 35 await server.users.update({ userId: rootId, videoQuota: 42 })
40 url: server.url, 36
41 userId: rootId, 37 command = server.videos
42 accessToken: server.accessToken,
43 videoQuota: 42
44 })
45 }) 38 })
46 39
47 describe('When having a video quota', function () { 40 describe('When having a video quota', function () {
@@ -50,49 +43,48 @@ describe('Test upload quota', function () {
50 this.timeout(30000) 43 this.timeout(30000)
51 44
52 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } 45 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
53 await registerUser(server.url, user.username, user.password) 46 await server.users.register(user)
54 const userAccessToken = await userLogin(server, user) 47 const userToken = await server.login.getAccessToken(user)
55 48
56 const videoAttributes = { fixture: 'video_short2.webm' } 49 const attributes = { fixture: 'video_short2.webm' }
57 for (let i = 0; i < 5; i++) { 50 for (let i = 0; i < 5; i++) {
58 await uploadVideo(server.url, userAccessToken, videoAttributes) 51 await command.upload({ token: userToken, attributes })
59 } 52 }
60 53
61 await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') 54 await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
62 }) 55 })
63 56
64 it('Should fail with a registered user having too many videos with resumable upload', async function () { 57 it('Should fail with a registered user having too many videos with resumable upload', async function () {
65 this.timeout(30000) 58 this.timeout(30000)
66 59
67 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } 60 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
68 await registerUser(server.url, user.username, user.password) 61 await server.users.register(user)
69 const userAccessToken = await userLogin(server, user) 62 const userToken = await server.login.getAccessToken(user)
70 63
71 const videoAttributes = { fixture: 'video_short2.webm' } 64 const attributes = { fixture: 'video_short2.webm' }
72 for (let i = 0; i < 5; i++) { 65 for (let i = 0; i < 5; i++) {
73 await uploadVideo(server.url, userAccessToken, videoAttributes) 66 await command.upload({ token: userToken, attributes })
74 } 67 }
75 68
76 await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') 69 await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
77 }) 70 })
78 71
79 it('Should fail to import with HTTP/Torrent/magnet', async function () { 72 it('Should fail to import with HTTP/Torrent/magnet', async function () {
80 this.timeout(120000) 73 this.timeout(120000)
81 74
82 const baseAttributes = { 75 const baseAttributes = {
83 channelId: server.videoChannel.id, 76 channelId: server.store.channel.id,
84 privacy: VideoPrivacy.PUBLIC 77 privacy: VideoPrivacy.PUBLIC
85 } 78 }
86 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getGoodVideoUrl() })) 79 await server.imports.importVideo({ attributes: { ...baseAttributes, targetUrl: FIXTURE_URLS.goodVideo } })
87 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() })) 80 await server.imports.importVideo({ attributes: { ...baseAttributes, magnetUri: FIXTURE_URLS.magnet } })
88 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' as any })) 81 await server.imports.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } })
89 82
90 await waitJobs([ server ]) 83 await waitJobs([ server ])
91 84
92 const res = await getMyVideoImports(server.url, server.accessToken) 85 const { total, data: videoImports } = await server.imports.getMyVideoImports()
86 expect(total).to.equal(3)
93 87
94 expect(res.body.total).to.equal(3)
95 const videoImports: VideoImport[] = res.body.data
96 expect(videoImports).to.have.lengthOf(3) 88 expect(videoImports).to.have.lengthOf(3)
97 89
98 for (const videoImport of videoImports) { 90 for (const videoImport of videoImports) {
@@ -106,43 +98,34 @@ describe('Test upload quota', function () {
106 describe('When having a daily video quota', function () { 98 describe('When having a daily video quota', function () {
107 99
108 it('Should fail with a user having too many videos daily', async function () { 100 it('Should fail with a user having too many videos daily', async function () {
109 await updateUser({ 101 await server.users.update({ userId: rootId, videoQuotaDaily: 42 })
110 url: server.url,
111 userId: rootId,
112 accessToken: server.accessToken,
113 videoQuotaDaily: 42
114 })
115 102
116 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') 103 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
117 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') 104 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
118 }) 105 })
119 }) 106 })
120 107
121 describe('When having an absolute and daily video quota', function () { 108 describe('When having an absolute and daily video quota', function () {
122 it('Should fail if exceeding total quota', async function () { 109 it('Should fail if exceeding total quota', async function () {
123 await updateUser({ 110 await server.users.update({
124 url: server.url,
125 userId: rootId, 111 userId: rootId,
126 accessToken: server.accessToken,
127 videoQuota: 42, 112 videoQuota: 42,
128 videoQuotaDaily: 1024 * 1024 * 1024 113 videoQuotaDaily: 1024 * 1024 * 1024
129 }) 114 })
130 115
131 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') 116 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
132 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') 117 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
133 }) 118 })
134 119
135 it('Should fail if exceeding daily quota', async function () { 120 it('Should fail if exceeding daily quota', async function () {
136 await updateUser({ 121 await server.users.update({
137 url: server.url,
138 userId: rootId, 122 userId: rootId,
139 accessToken: server.accessToken,
140 videoQuota: 1024 * 1024 * 1024, 123 videoQuota: 1024 * 1024 * 1024,
141 videoQuotaDaily: 42 124 videoQuotaDaily: 42
142 }) 125 })
143 126
144 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') 127 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
145 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') 128 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
146 }) 129 })
147 }) 130 })
148 131