aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
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
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')
-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
-rw-r--r--server/tests/utils/miscs/miscs.ts23
-rw-r--r--server/tests/utils/requests/requests.ts2
-rw-r--r--server/tests/utils/server/config.ts41
-rw-r--r--server/tests/utils/videos/videos.ts5
7 files changed, 309 insertions, 29 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
diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts
index 2c51d1f0a..2aac37791 100644
--- a/server/tests/utils/miscs/miscs.ts
+++ b/server/tests/utils/miscs/miscs.ts
@@ -1,5 +1,4 @@
1import * as WebTorrent from 'webtorrent' 1import * as WebTorrent from 'webtorrent'
2import { readFile, readdir } from 'fs'
3 2
4let webtorrent = new WebTorrent() 3let webtorrent = new WebTorrent()
5 4
@@ -7,26 +6,6 @@ function immutableAssign <T, U> (target: T, source: U) {
7 return Object.assign<{}, T, U>({}, target, source) 6 return Object.assign<{}, T, U>({}, target, source)
8} 7}
9 8
10function readFilePromise (path: string) {
11 return new Promise<Buffer>((res, rej) => {
12 readFile(path, (err, data) => {
13 if (err) return rej(err)
14
15 return res(data)
16 })
17 })
18}
19
20function readdirPromise (path: string) {
21 return new Promise<string[]>((res, rej) => {
22 readdir(path, (err, files) => {
23 if (err) return rej(err)
24
25 return res(files)
26 })
27 })
28}
29
30 // Default interval -> 5 minutes 9 // Default interval -> 5 minutes
31function dateIsValid (dateString: string, interval = 300000) { 10function dateIsValid (dateString: string, interval = 300000) {
32 const dateToCheck = new Date(dateString) 11 const dateToCheck = new Date(dateString)
@@ -48,8 +27,6 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) {
48// --------------------------------------------------------------------------- 27// ---------------------------------------------------------------------------
49 28
50export { 29export {
51 readFilePromise,
52 readdirPromise,
53 dateIsValid, 30 dateIsValid,
54 wait, 31 wait,
55 webtorrentAdd, 32 webtorrentAdd,
diff --git a/server/tests/utils/requests/requests.ts b/server/tests/utils/requests/requests.ts
index eb02cf9e6..840072430 100644
--- a/server/tests/utils/requests/requests.ts
+++ b/server/tests/utils/requests/requests.ts
@@ -99,7 +99,7 @@ function makePostBodyRequest (options: {
99function makePutBodyRequest (options: { 99function makePutBodyRequest (options: {
100 url: string, 100 url: string,
101 path: string, 101 path: string,
102 token: string, 102 token?: string,
103 fields: { [ fieldName: string ]: any }, 103 fields: { [ fieldName: string ]: any },
104 statusCodeExpected?: number 104 statusCodeExpected?: number
105}) { 105}) {
diff --git a/server/tests/utils/server/config.ts b/server/tests/utils/server/config.ts
index d09c19c60..b6905757a 100644
--- a/server/tests/utils/server/config.ts
+++ b/server/tests/utils/server/config.ts
@@ -1,4 +1,6 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../'
3import { CustomConfig } from '../../../../shared/models/config/custom-config.model'
2 4
3function getConfig (url: string) { 5function getConfig (url: string) {
4 const path = '/api/v1/config' 6 const path = '/api/v1/config'
@@ -10,8 +12,45 @@ function getConfig (url: string) {
10 .expect('Content-Type', /json/) 12 .expect('Content-Type', /json/)
11} 13}
12 14
15function getCustomConfig (url: string, token: string, statusCodeExpected = 200) {
16 const path = '/api/v1/config/custom'
17
18 return makeGetRequest({
19 url,
20 token,
21 path,
22 statusCodeExpected
23 })
24}
25
26function updateCustomConfig (url: string, token: string, newCustomConfig: CustomConfig, statusCodeExpected = 200) {
27 const path = '/api/v1/config/custom'
28
29 return makePutBodyRequest({
30 url,
31 token,
32 path,
33 fields: newCustomConfig,
34 statusCodeExpected
35 })
36}
37
38function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) {
39 const path = '/api/v1/config/custom'
40
41 return makeDeleteRequest({
42 url,
43 token,
44 path,
45 statusCodeExpected
46 })
47}
48
13// --------------------------------------------------------------------------- 49// ---------------------------------------------------------------------------
14 50
15export { 51export {
16 getConfig 52 getConfig,
53 getCustomConfig,
54 updateCustomConfig,
55 deleteCustomConfig
17} 56}
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts
index dc1327215..095d4e29d 100644
--- a/server/tests/utils/videos/videos.ts
+++ b/server/tests/utils/videos/videos.ts
@@ -5,8 +5,9 @@ import { readFile } from 'fs'
5import * as parseTorrent from 'parse-torrent' 5import * as parseTorrent from 'parse-torrent'
6import { extname, isAbsolute, join } from 'path' 6import { extname, isAbsolute, join } from 'path'
7import * as request from 'supertest' 7import * as request from 'supertest'
8import { getMyUserInformation, makeGetRequest, readFilePromise, ServerInfo } from '../' 8import { getMyUserInformation, makeGetRequest, ServerInfo } from '../'
9import { VideoPrivacy } from '../../../../shared/models/videos' 9import { VideoPrivacy } from '../../../../shared/models/videos'
10import { readFileBufferPromise } from '../../../helpers/core-utils'
10import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' 11import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers'
11import { dateIsValid, webtorrentAdd } from '../index' 12import { dateIsValid, webtorrentAdd } from '../index'
12 13
@@ -210,7 +211,7 @@ async function testVideoImage (url: string, imageName: string, imagePath: string
210 .get(imagePath) 211 .get(imagePath)
211 .expect(200) 212 .expect(200)
212 213
213 const data = await readFilePromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension)) 214 const data = await readFileBufferPromise(join(__dirname, '..', '..', 'api', 'fixtures', imageName + extension))
214 215
215 return data.equals(res.body) 216 return data.equals(res.body)
216 } else { 217 } else {