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