aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-17 10:32:03 +0100
committerChocobozzz <me@florianbigard.com>2018-01-17 10:41:27 +0100
commitfd206f0b2d7e5c8e00e2817266d90ec54f79e1da (patch)
tree86b096cf2abd7eb49b892de1c9be855f45a41a9c /server/tests/api
parent9581cabc596acb18c0ad86bcf3a07c2b45e8e47e (diff)
downloadPeerTube-fd206f0b2d7e5c8e00e2817266d90ec54f79e1da.tar.gz
PeerTube-fd206f0b2d7e5c8e00e2817266d90ec54f79e1da.tar.zst
PeerTube-fd206f0b2d7e5c8e00e2817266d90ec54f79e1da.zip
Add ability to update some configuration keys
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/config.ts152
-rw-r--r--server/tests/api/server/config.ts112
-rw-r--r--server/tests/api/videos/single-server.ts3
3 files changed, 265 insertions, 2 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
new file mode 100644
index 000000000..59a0c3049
--- /dev/null
+++ b/server/tests/api/check-params/config.ts
@@ -0,0 +1,152 @@
1/* tslint:disable:no-unused-expression */
2
3import { omit } from 'lodash'
4import 'mocha'
5import { CustomConfig } from '../../../../shared/models/config/custom-config.model'
6
7import {
8 createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo,
9 setAccessTokensToServers, userLogin
10} from '../../utils'
11
12describe('Test config API validators', function () {
13 const path = '/api/v1/config/custom'
14 let server: ServerInfo
15 let userAccessToken: string
16 const updateParams: CustomConfig = {
17 cache: {
18 previews: {
19 size: 2
20 }
21 },
22 signup: {
23 enabled: false,
24 limit: 5
25 },
26 admin: {
27 email: 'superadmin1@example.com'
28 },
29 user: {
30 videoQuota: 5242881
31 },
32 transcoding: {
33 enabled: true,
34 threads: 1,
35 resolutions: {
36 '240p': false,
37 '360p': true,
38 '480p': true,
39 '720p': false,
40 '1080p': false
41 }
42 }
43 }
44
45 // ---------------------------------------------------------------
46
47 before(async function () {
48 this.timeout(20000)
49
50 await flushTests()
51 server = await runServer(1)
52
53 await setAccessTokensToServers([ server ])
54
55 const user = {
56 username: 'user1',
57 password: 'password'
58 }
59 await createUser(server.url, server.accessToken, user.username, user.password)
60 userAccessToken = await userLogin(server, user)
61 })
62
63 describe('When getting the configuration', function () {
64 it('Should fail without token', async function () {
65 await makeGetRequest({
66 url: server.url,
67 path,
68 statusCodeExpected: 401
69 })
70 })
71
72 it('Should fail if the user is not an administrator', async function () {
73 await makeGetRequest({
74 url: server.url,
75 path,
76 token: userAccessToken,
77 statusCodeExpected: 403
78 })
79 })
80 })
81
82 describe('When updating the configuration', function () {
83 it('Should fail without token', async function () {
84 await makePutBodyRequest({
85 url: server.url,
86 path,
87 fields: updateParams,
88 statusCodeExpected: 401
89 })
90 })
91
92 it('Should fail if the user is not an administrator', async function () {
93 await makePutBodyRequest({
94 url: server.url,
95 path,
96 fields: updateParams,
97 token: userAccessToken,
98 statusCodeExpected: 403
99 })
100 })
101
102 it('Should fail if it misses a key', async function () {
103 const newUpdateParams = omit(updateParams, 'admin.email')
104
105 await makePutBodyRequest({
106 url: server.url,
107 path,
108 fields: newUpdateParams,
109 token: server.accessToken,
110 statusCodeExpected: 400
111 })
112 })
113
114 it('Should success with the correct parameters', async function () {
115 await makePutBodyRequest({
116 url: server.url,
117 path,
118 fields: updateParams,
119 token: server.accessToken,
120 statusCodeExpected: 200
121 })
122 })
123 })
124
125 describe('When deleting the configuration', function () {
126 it('Should fail without token', async function () {
127 await makeDeleteRequest({
128 url: server.url,
129 path,
130 statusCodeExpected: 401
131 })
132 })
133
134 it('Should fail if the user is not an administrator', async function () {
135 await makeDeleteRequest({
136 url: server.url,
137 path,
138 token: userAccessToken,
139 statusCodeExpected: 403
140 })
141 })
142 })
143
144 after(async function () {
145 killallServers([ server ])
146
147 // Keep the logs if the test failed
148 if (this['ok']) {
149 await flushTests()
150 }
151 })
152})
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index e8846c8db..8c1389e7f 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -2,13 +2,14 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { deleteCustomConfig, killallServers, reRunServer } from '../../utils'
5const expect = chai.expect 6const expect = chai.expect
6 7
7import { 8import {
8 getConfig, 9 getConfig,
9 flushTests, 10 flushTests,
10 runServer, 11 runServer,
11 registerUser 12 registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig
12} from '../../utils/index' 13} from '../../utils/index'
13 14
14describe('Test config', function () { 15describe('Test config', function () {
@@ -19,6 +20,7 @@ describe('Test config', function () {
19 20
20 await flushTests() 21 await flushTests()
21 server = await runServer(1) 22 server = await runServer(1)
23 await setAccessTokensToServers([ server ])
22 }) 24 })
23 25
24 it('Should have a correct config on a server with registration enabled', async function () { 26 it('Should have a correct config on a server with registration enabled', async function () {
@@ -43,6 +45,114 @@ describe('Test config', function () {
43 expect(data.signup.allowed).to.be.false 45 expect(data.signup.allowed).to.be.false
44 }) 46 })
45 47
48 it('Should get the customized configuration', async function () {
49 const res = await getCustomConfig(server.url, server.accessToken)
50 const data = res.body
51
52 expect(data.cache.previews.size).to.equal(1)
53 expect(data.signup.enabled).to.be.true
54 expect(data.signup.limit).to.equal(4)
55 expect(data.admin.email).to.equal('admin1@example.com')
56 expect(data.user.videoQuota).to.equal(5242880)
57 expect(data.transcoding.enabled).to.be.false
58 expect(data.transcoding.threads).to.equal(2)
59 expect(data.transcoding.resolutions['240p']).to.be.true
60 expect(data.transcoding.resolutions['360p']).to.be.true
61 expect(data.transcoding.resolutions['480p']).to.be.true
62 expect(data.transcoding.resolutions['720p']).to.be.true
63 expect(data.transcoding.resolutions['1080p']).to.be.true
64 })
65
66 it('Should update the customized configuration', async function () {
67 const newCustomConfig = {
68 cache: {
69 previews: {
70 size: 2
71 }
72 },
73 signup: {
74 enabled: false,
75 limit: 5
76 },
77 admin: {
78 email: 'superadmin1@example.com'
79 },
80 user: {
81 videoQuota: 5242881
82 },
83 transcoding: {
84 enabled: true,
85 threads: 1,
86 resolutions: {
87 '240p': false,
88 '360p': true,
89 '480p': true,
90 '720p': false,
91 '1080p': false
92 }
93 }
94 }
95 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
96
97 const res = await getCustomConfig(server.url, server.accessToken)
98 const data = res.body
99
100 expect(data.cache.previews.size).to.equal(2)
101 expect(data.signup.enabled).to.be.false
102 expect(data.signup.limit).to.equal(5)
103 expect(data.admin.email).to.equal('superadmin1@example.com')
104 expect(data.user.videoQuota).to.equal(5242881)
105 expect(data.transcoding.enabled).to.be.true
106 expect(data.transcoding.threads).to.equal(1)
107 expect(data.transcoding.resolutions['240p']).to.be.false
108 expect(data.transcoding.resolutions['360p']).to.be.true
109 expect(data.transcoding.resolutions['480p']).to.be.true
110 expect(data.transcoding.resolutions['720p']).to.be.false
111 expect(data.transcoding.resolutions['1080p']).to.be.false
112 })
113
114 it('Should have the configuration updated after a restart', async function () {
115 killallServers([ server ])
116
117 await reRunServer(server)
118
119 const res = await getCustomConfig(server.url, server.accessToken)
120 const data = res.body
121
122 expect(data.cache.previews.size).to.equal(2)
123 expect(data.signup.enabled).to.be.false
124 expect(data.signup.limit).to.equal(5)
125 expect(data.admin.email).to.equal('superadmin1@example.com')
126 expect(data.user.videoQuota).to.equal(5242881)
127 expect(data.transcoding.enabled).to.be.true
128 expect(data.transcoding.threads).to.equal(1)
129 expect(data.transcoding.resolutions['240p']).to.be.false
130 expect(data.transcoding.resolutions['360p']).to.be.true
131 expect(data.transcoding.resolutions['480p']).to.be.true
132 expect(data.transcoding.resolutions['720p']).to.be.false
133 expect(data.transcoding.resolutions['1080p']).to.be.false
134 })
135
136 it('Should remove the custom configuration', async function () {
137 await deleteCustomConfig(server.url, server.accessToken)
138
139 const res = await getCustomConfig(server.url, server.accessToken)
140 const data = res.body
141
142 expect(data.cache.previews.size).to.equal(1)
143 expect(data.signup.enabled).to.be.true
144 expect(data.signup.limit).to.equal(4)
145 expect(data.admin.email).to.equal('admin1@example.com')
146 expect(data.user.videoQuota).to.equal(5242880)
147 expect(data.transcoding.enabled).to.be.false
148 expect(data.transcoding.threads).to.equal(2)
149 expect(data.transcoding.resolutions['240p']).to.be.true
150 expect(data.transcoding.resolutions['360p']).to.be.true
151 expect(data.transcoding.resolutions['480p']).to.be.true
152 expect(data.transcoding.resolutions['720p']).to.be.true
153 expect(data.transcoding.resolutions['1080p']).to.be.true
154 })
155
46 after(async function () { 156 after(async function () {
47 process.kill(-server.app.pid) 157 process.kill(-server.app.pid)
48 158
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts
index 0a0c95750..ca20f39a0 100644
--- a/server/tests/api/videos/single-server.ts
+++ b/server/tests/api/videos/single-server.ts
@@ -5,9 +5,10 @@ import { keyBy } from 'lodash'
5import 'mocha' 5import 'mocha'
6import { join } from 'path' 6import { join } from 'path'
7import { VideoPrivacy } from '../../../../shared/models/videos' 7import { VideoPrivacy } from '../../../../shared/models/videos'
8import { readdirPromise } from '../../../helpers/core-utils'
8import { 9import {
9 completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences, getVideoPrivacies, 10 completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences, getVideoPrivacies,
10 getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, readdirPromise, removeVideo, runServer, searchVideo, 11 getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, removeVideo, runServer, searchVideo,
11 searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testVideoImage, updateVideo, uploadVideo, viewVideo 12 searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testVideoImage, updateVideo, uploadVideo, viewVideo
12} from '../../utils' 13} from '../../utils'
13 14