diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/config.ts | 20 | ||||
-rw-r--r-- | server/tests/api/server/config.ts | 16 | ||||
-rw-r--r-- | server/tests/utils/server/config.ts | 22 |
3 files changed, 50 insertions, 8 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index e4cb02820..89163edb3 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts | |||
@@ -1,19 +1,22 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { omit } from 'lodash' | ||
2 | import { ServerConfig, UserRight } from '../../../shared' | 3 | import { ServerConfig, UserRight } from '../../../shared' |
4 | import { About } from '../../../shared/models/config/about.model' | ||
3 | import { CustomConfig } from '../../../shared/models/config/custom-config.model' | 5 | import { CustomConfig } from '../../../shared/models/config/custom-config.model' |
4 | import { unlinkPromise, writeFilePromise } from '../../helpers/core-utils' | 6 | import { unlinkPromise, writeFilePromise } from '../../helpers/core-utils' |
5 | import { isSignupAllowed } from '../../helpers/utils' | 7 | import { isSignupAllowed } from '../../helpers/utils' |
6 | import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers' | 8 | import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers' |
7 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' | 9 | import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' |
8 | import { customConfigUpdateValidator } from '../../middlewares/validators/config' | 10 | import { customConfigUpdateValidator } from '../../middlewares/validators/config' |
9 | import { omit } from 'lodash' | ||
10 | 11 | ||
11 | const packageJSON = require('../../../../package.json') | 12 | const packageJSON = require('../../../../package.json') |
12 | const configRouter = express.Router() | 13 | const configRouter = express.Router() |
13 | 14 | ||
15 | configRouter.get('/about', getAbout) | ||
14 | configRouter.get('/', | 16 | configRouter.get('/', |
15 | asyncMiddleware(getConfig) | 17 | asyncMiddleware(getConfig) |
16 | ) | 18 | ) |
19 | |||
17 | configRouter.get('/custom', | 20 | configRouter.get('/custom', |
18 | authenticate, | 21 | authenticate, |
19 | ensureUserHasRight(UserRight.MANAGE_CONFIGURATION), | 22 | ensureUserHasRight(UserRight.MANAGE_CONFIGURATION), |
@@ -39,6 +42,9 @@ async function getConfig (req: express.Request, res: express.Response, next: exp | |||
39 | .map(r => parseInt(r, 10)) | 42 | .map(r => parseInt(r, 10)) |
40 | 43 | ||
41 | const json: ServerConfig = { | 44 | const json: ServerConfig = { |
45 | instance: { | ||
46 | name: CONFIG.INSTANCE.NAME | ||
47 | }, | ||
42 | serverVersion: packageJSON.version, | 48 | serverVersion: packageJSON.version, |
43 | signup: { | 49 | signup: { |
44 | allowed | 50 | allowed |
@@ -64,6 +70,18 @@ async function getConfig (req: express.Request, res: express.Response, next: exp | |||
64 | return res.json(json) | 70 | return res.json(json) |
65 | } | 71 | } |
66 | 72 | ||
73 | function getAbout (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
74 | const about: About = { | ||
75 | instance: { | ||
76 | name: CONFIG.INSTANCE.NAME, | ||
77 | description: CONFIG.INSTANCE.DESCRIPTION, | ||
78 | terms: CONFIG.INSTANCE.TERMS | ||
79 | } | ||
80 | } | ||
81 | |||
82 | return res.json(about).end() | ||
83 | } | ||
84 | |||
67 | async function getCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { | 85 | async function getCustomConfig (req: express.Request, res: express.Response, next: express.NextFunction) { |
68 | const data = customConfig() | 86 | const data = customConfig() |
69 | 87 | ||
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index f83e21e82..35a5c430b 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts | |||
@@ -2,7 +2,8 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { deleteCustomConfig, killallServers, reRunServer } from '../../utils' | 5 | import { About } from '../../../../shared/models/config/about.model' |
6 | import { deleteCustomConfig, getAbout, killallServers, reRunServer } from '../../utils' | ||
6 | const expect = chai.expect | 7 | const expect = chai.expect |
7 | 8 | ||
8 | import { | 9 | import { |
@@ -108,6 +109,7 @@ describe('Test config', function () { | |||
108 | expect(data.instance.name).to.equal('PeerTube updated') | 109 | expect(data.instance.name).to.equal('PeerTube updated') |
109 | expect(data.instance.description).to.equal('my super description') | 110 | expect(data.instance.description).to.equal('my super description') |
110 | expect(data.instance.terms).to.equal('my super terms') | 111 | expect(data.instance.terms).to.equal('my super terms') |
112 | expect(data.cache.previews.size).to.equal(2) | ||
111 | expect(data.signup.enabled).to.be.false | 113 | expect(data.signup.enabled).to.be.false |
112 | expect(data.signup.limit).to.equal(5) | 114 | expect(data.signup.limit).to.equal(5) |
113 | expect(data.admin.email).to.equal('superadmin1@example.com') | 115 | expect(data.admin.email).to.equal('superadmin1@example.com') |
@@ -131,6 +133,9 @@ describe('Test config', function () { | |||
131 | const res = await getCustomConfig(server.url, server.accessToken) | 133 | const res = await getCustomConfig(server.url, server.accessToken) |
132 | const data = res.body | 134 | const data = res.body |
133 | 135 | ||
136 | expect(data.instance.name).to.equal('PeerTube updated') | ||
137 | expect(data.instance.description).to.equal('my super description') | ||
138 | expect(data.instance.terms).to.equal('my super terms') | ||
134 | expect(data.cache.previews.size).to.equal(2) | 139 | expect(data.cache.previews.size).to.equal(2) |
135 | expect(data.signup.enabled).to.be.false | 140 | expect(data.signup.enabled).to.be.false |
136 | expect(data.signup.limit).to.equal(5) | 141 | expect(data.signup.limit).to.equal(5) |
@@ -145,6 +150,15 @@ describe('Test config', function () { | |||
145 | expect(data.transcoding.resolutions['1080p']).to.be.false | 150 | expect(data.transcoding.resolutions['1080p']).to.be.false |
146 | }) | 151 | }) |
147 | 152 | ||
153 | it('Should fetch the about information', async function () { | ||
154 | const res = await getAbout(server.url) | ||
155 | const data: About = res.body | ||
156 | |||
157 | expect(data.instance.name).to.equal('PeerTube updated') | ||
158 | expect(data.instance.description).to.equal('my super description') | ||
159 | expect(data.instance.terms).to.equal('my super terms') | ||
160 | }) | ||
161 | |||
148 | it('Should remove the custom configuration', async function () { | 162 | it('Should remove the custom configuration', async function () { |
149 | this.timeout(10000) | 163 | this.timeout(10000) |
150 | 164 | ||
diff --git a/server/tests/utils/server/config.ts b/server/tests/utils/server/config.ts index b6905757a..e5411117a 100644 --- a/server/tests/utils/server/config.ts +++ b/server/tests/utils/server/config.ts | |||
@@ -1,15 +1,24 @@ | |||
1 | import * as request from 'supertest' | ||
2 | import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../' | 1 | import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../' |
3 | import { CustomConfig } from '../../../../shared/models/config/custom-config.model' | 2 | import { CustomConfig } from '../../../../shared/models/config/custom-config.model' |
4 | 3 | ||
5 | function getConfig (url: string) { | 4 | function getConfig (url: string) { |
6 | const path = '/api/v1/config' | 5 | const path = '/api/v1/config' |
7 | 6 | ||
8 | return request(url) | 7 | return makeGetRequest({ |
9 | .get(path) | 8 | url, |
10 | .set('Accept', 'application/json') | 9 | path, |
11 | .expect(200) | 10 | statusCodeExpected: 200 |
12 | .expect('Content-Type', /json/) | 11 | }) |
12 | } | ||
13 | |||
14 | function getAbout (url: string) { | ||
15 | const path = '/api/v1/config/about' | ||
16 | |||
17 | return makeGetRequest({ | ||
18 | url, | ||
19 | path, | ||
20 | statusCodeExpected: 200 | ||
21 | }) | ||
13 | } | 22 | } |
14 | 23 | ||
15 | function getCustomConfig (url: string, token: string, statusCodeExpected = 200) { | 24 | function getCustomConfig (url: string, token: string, statusCodeExpected = 200) { |
@@ -52,5 +61,6 @@ export { | |||
52 | getConfig, | 61 | getConfig, |
53 | getCustomConfig, | 62 | getCustomConfig, |
54 | updateCustomConfig, | 63 | updateCustomConfig, |
64 | getAbout, | ||
55 | deleteCustomConfig | 65 | deleteCustomConfig |
56 | } | 66 | } |