aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorFelix Ableitner <me@nutomic.com>2018-08-28 02:01:35 -0500
committerChocobozzz <me@florianbigard.com>2018-08-28 09:01:35 +0200
commitbee0abffff73804d816b90c7fd599e0a51c09d61 (patch)
treefae6d58637f9c63a3800090277f8e130b43442dd /server/tests/api
parentc907c2fa3fd7c0a741117a0204d0ebca675124bd (diff)
downloadPeerTube-bee0abffff73804d816b90c7fd599e0a51c09d61.tar.gz
PeerTube-bee0abffff73804d816b90c7fd599e0a51c09d61.tar.zst
PeerTube-bee0abffff73804d816b90c7fd599e0a51c09d61.zip
Implement daily upload limit (#956)
* Implement daily upload limit (ref #652) * remove duplicate code * review fixes * fix tests? * whitespace fixes, finish leftover todo * fix tests * added some new tests * use different config value for tests * remove todo
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/config.ts3
-rw-r--r--server/tests/api/check-params/users.ts56
-rw-r--r--server/tests/api/server/config.ts5
3 files changed, 60 insertions, 4 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index b26dfa252..ecfb76d47 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -48,7 +48,8 @@ describe('Test config API validators', function () {
48 email: 'superadmin1@example.com' 48 email: 'superadmin1@example.com'
49 }, 49 },
50 user: { 50 user: {
51 videoQuota: 5242881 51 videoQuota: 5242881,
52 videoQuotaDaily: 318742
52 }, 53 },
53 transcoding: { 54 transcoding: {
54 enabled: true, 55 enabled: true,
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index b3fb61f6c..8b2ed1b04 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -94,6 +94,7 @@ describe('Test users API validators', function () {
94 email: 'test@example.com', 94 email: 'test@example.com',
95 password: 'my super password', 95 password: 'my super password',
96 videoQuota: -1, 96 videoQuota: -1,
97 videoQuotaDaily: -1,
97 role: UserRole.USER 98 role: UserRole.USER
98 } 99 }
99 100
@@ -173,12 +174,24 @@ describe('Test users API validators', function () {
173 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 174 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
174 }) 175 })
175 176
177 it('Should fail without a videoQuotaDaily', async function () {
178 const fields = omit(baseCorrectParams, 'videoQuotaDaily')
179
180 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
181 })
182
176 it('Should fail with an invalid videoQuota', async function () { 183 it('Should fail with an invalid videoQuota', async function () {
177 const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 }) 184 const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 })
178 185
179 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 186 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
180 }) 187 })
181 188
189 it('Should fail with an invalid videoQuotaDaily', async function () {
190 const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 })
191
192 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
193 })
194
182 it('Should fail without a user role', async function () { 195 it('Should fail without a user role', async function () {
183 const fields = omit(baseCorrectParams, 'role') 196 const fields = omit(baseCorrectParams, 'role')
184 197
@@ -607,7 +620,7 @@ describe('Test users API validators', function () {
607 }) 620 })
608 621
609 describe('When having a video quota', function () { 622 describe('When having a video quota', function () {
610 it('Should fail with a user having too many video', async function () { 623 it('Should fail with a user having too many videos', async function () {
611 await updateUser({ 624 await updateUser({
612 url: server.url, 625 url: server.url,
613 userId: rootId, 626 userId: rootId,
@@ -618,7 +631,7 @@ describe('Test users API validators', function () {
618 await uploadVideo(server.url, server.accessToken, {}, 403) 631 await uploadVideo(server.url, server.accessToken, {}, 403)
619 }) 632 })
620 633
621 it('Should fail with a registered user having too many video', async function () { 634 it('Should fail with a registered user having too many videos', async function () {
622 this.timeout(30000) 635 this.timeout(30000)
623 636
624 const user = { 637 const user = {
@@ -663,6 +676,45 @@ describe('Test users API validators', function () {
663 }) 676 })
664 }) 677 })
665 678
679 describe('When having a daily video quota', function () {
680 it('Should fail with a user having too many videos', async function () {
681 await updateUser({
682 url: server.url,
683 userId: rootId,
684 accessToken: server.accessToken,
685 videoQuotaDaily: 42
686 })
687
688 await uploadVideo(server.url, server.accessToken, {}, 403)
689 })
690 })
691
692 describe('When having an absolute and daily video quota', function () {
693 it('Should fail if exceeding total quota', async function () {
694 await updateUser({
695 url: server.url,
696 userId: rootId,
697 accessToken: server.accessToken,
698 videoQuota: 42,
699 videoQuotaDaily: 1024 * 1024 * 1024
700 })
701
702 await uploadVideo(server.url, server.accessToken, {}, 403)
703 })
704
705 it('Should fail if exceeding daily quota', async function () {
706 await updateUser({
707 url: server.url,
708 userId: rootId,
709 accessToken: server.accessToken,
710 videoQuota: 1024 * 1024 * 1024,
711 videoQuotaDaily: 42
712 })
713
714 await uploadVideo(server.url, server.accessToken, {}, 403)
715 })
716 })
717
666 describe('When asking a password reset', function () { 718 describe('When asking a password reset', function () {
667 const path = '/api/v1/users/ask-reset-password' 719 const path = '/api/v1/users/ask-reset-password'
668 720
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index f9805b6ea..8a5f27c34 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -37,6 +37,7 @@ function checkInitialConfig (data: CustomConfig) {
37 expect(data.signup.limit).to.equal(4) 37 expect(data.signup.limit).to.equal(4)
38 expect(data.admin.email).to.equal('admin1@example.com') 38 expect(data.admin.email).to.equal('admin1@example.com')
39 expect(data.user.videoQuota).to.equal(5242880) 39 expect(data.user.videoQuota).to.equal(5242880)
40 expect(data.user.videoQuotaDaily).to.equal(318742)
40 expect(data.transcoding.enabled).to.be.false 41 expect(data.transcoding.enabled).to.be.false
41 expect(data.transcoding.threads).to.equal(2) 42 expect(data.transcoding.threads).to.equal(2)
42 expect(data.transcoding.resolutions['240p']).to.be.true 43 expect(data.transcoding.resolutions['240p']).to.be.true
@@ -65,6 +66,7 @@ function checkUpdatedConfig (data: CustomConfig) {
65 expect(data.signup.limit).to.equal(5) 66 expect(data.signup.limit).to.equal(5)
66 expect(data.admin.email).to.equal('superadmin1@example.com') 67 expect(data.admin.email).to.equal('superadmin1@example.com')
67 expect(data.user.videoQuota).to.equal(5242881) 68 expect(data.user.videoQuota).to.equal(5242881)
69 expect(data.user.videoQuotaDaily).to.equal(318742)
68 expect(data.transcoding.enabled).to.be.true 70 expect(data.transcoding.enabled).to.be.true
69 expect(data.transcoding.threads).to.equal(1) 71 expect(data.transcoding.threads).to.equal(1)
70 expect(data.transcoding.resolutions['240p']).to.be.false 72 expect(data.transcoding.resolutions['240p']).to.be.false
@@ -152,7 +154,8 @@ describe('Test config', function () {
152 email: 'superadmin1@example.com' 154 email: 'superadmin1@example.com'
153 }, 155 },
154 user: { 156 user: {
155 videoQuota: 5242881 157 videoQuota: 5242881,
158 videoQuotaDaily: 318742
156 }, 159 },
157 transcoding: { 160 transcoding: {
158 enabled: true, 161 enabled: true,