From fd206f0b2d7e5c8e00e2817266d90ec54f79e1da Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 17 Jan 2018 10:32:03 +0100 Subject: Add ability to update some configuration keys --- server/tests/api/check-params/config.ts | 152 +++++++++++++++++++++++++++++++ server/tests/api/server/config.ts | 112 ++++++++++++++++++++++- server/tests/api/videos/single-server.ts | 3 +- 3 files changed, 265 insertions(+), 2 deletions(-) create mode 100644 server/tests/api/check-params/config.ts (limited to 'server/tests/api') 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 @@ +/* tslint:disable:no-unused-expression */ + +import { omit } from 'lodash' +import 'mocha' +import { CustomConfig } from '../../../../shared/models/config/custom-config.model' + +import { + createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo, + setAccessTokensToServers, userLogin +} from '../../utils' + +describe('Test config API validators', function () { + const path = '/api/v1/config/custom' + let server: ServerInfo + let userAccessToken: string + const updateParams: CustomConfig = { + cache: { + previews: { + size: 2 + } + }, + signup: { + enabled: false, + limit: 5 + }, + admin: { + email: 'superadmin1@example.com' + }, + user: { + videoQuota: 5242881 + }, + transcoding: { + enabled: true, + threads: 1, + resolutions: { + '240p': false, + '360p': true, + '480p': true, + '720p': false, + '1080p': false + } + } + } + + // --------------------------------------------------------------- + + before(async function () { + this.timeout(20000) + + await flushTests() + server = await runServer(1) + + await setAccessTokensToServers([ server ]) + + const user = { + username: 'user1', + password: 'password' + } + await createUser(server.url, server.accessToken, user.username, user.password) + userAccessToken = await userLogin(server, user) + }) + + describe('When getting the configuration', function () { + it('Should fail without token', async function () { + await makeGetRequest({ + url: server.url, + path, + statusCodeExpected: 401 + }) + }) + + it('Should fail if the user is not an administrator', async function () { + await makeGetRequest({ + url: server.url, + path, + token: userAccessToken, + statusCodeExpected: 403 + }) + }) + }) + + describe('When updating the configuration', function () { + it('Should fail without token', async function () { + await makePutBodyRequest({ + url: server.url, + path, + fields: updateParams, + statusCodeExpected: 401 + }) + }) + + it('Should fail if the user is not an administrator', async function () { + await makePutBodyRequest({ + url: server.url, + path, + fields: updateParams, + token: userAccessToken, + statusCodeExpected: 403 + }) + }) + + it('Should fail if it misses a key', async function () { + const newUpdateParams = omit(updateParams, 'admin.email') + + await makePutBodyRequest({ + url: server.url, + path, + fields: newUpdateParams, + token: server.accessToken, + statusCodeExpected: 400 + }) + }) + + it('Should success with the correct parameters', async function () { + await makePutBodyRequest({ + url: server.url, + path, + fields: updateParams, + token: server.accessToken, + statusCodeExpected: 200 + }) + }) + }) + + describe('When deleting the configuration', function () { + it('Should fail without token', async function () { + await makeDeleteRequest({ + url: server.url, + path, + statusCodeExpected: 401 + }) + }) + + it('Should fail if the user is not an administrator', async function () { + await makeDeleteRequest({ + url: server.url, + path, + token: userAccessToken, + statusCodeExpected: 403 + }) + }) + }) + + after(async function () { + killallServers([ server ]) + + // Keep the logs if the test failed + if (this['ok']) { + await flushTests() + } + }) +}) 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 @@ import 'mocha' import * as chai from 'chai' +import { deleteCustomConfig, killallServers, reRunServer } from '../../utils' const expect = chai.expect import { getConfig, flushTests, runServer, - registerUser + registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig } from '../../utils/index' describe('Test config', function () { @@ -19,6 +20,7 @@ describe('Test config', function () { await flushTests() server = await runServer(1) + await setAccessTokensToServers([ server ]) }) it('Should have a correct config on a server with registration enabled', async function () { @@ -43,6 +45,114 @@ describe('Test config', function () { expect(data.signup.allowed).to.be.false }) + it('Should get the customized configuration', async function () { + const res = await getCustomConfig(server.url, server.accessToken) + const data = res.body + + expect(data.cache.previews.size).to.equal(1) + expect(data.signup.enabled).to.be.true + expect(data.signup.limit).to.equal(4) + expect(data.admin.email).to.equal('admin1@example.com') + expect(data.user.videoQuota).to.equal(5242880) + expect(data.transcoding.enabled).to.be.false + expect(data.transcoding.threads).to.equal(2) + expect(data.transcoding.resolutions['240p']).to.be.true + expect(data.transcoding.resolutions['360p']).to.be.true + expect(data.transcoding.resolutions['480p']).to.be.true + expect(data.transcoding.resolutions['720p']).to.be.true + expect(data.transcoding.resolutions['1080p']).to.be.true + }) + + it('Should update the customized configuration', async function () { + const newCustomConfig = { + cache: { + previews: { + size: 2 + } + }, + signup: { + enabled: false, + limit: 5 + }, + admin: { + email: 'superadmin1@example.com' + }, + user: { + videoQuota: 5242881 + }, + transcoding: { + enabled: true, + threads: 1, + resolutions: { + '240p': false, + '360p': true, + '480p': true, + '720p': false, + '1080p': false + } + } + } + await updateCustomConfig(server.url, server.accessToken, newCustomConfig) + + const res = await getCustomConfig(server.url, server.accessToken) + const data = res.body + + expect(data.cache.previews.size).to.equal(2) + expect(data.signup.enabled).to.be.false + expect(data.signup.limit).to.equal(5) + expect(data.admin.email).to.equal('superadmin1@example.com') + expect(data.user.videoQuota).to.equal(5242881) + expect(data.transcoding.enabled).to.be.true + expect(data.transcoding.threads).to.equal(1) + expect(data.transcoding.resolutions['240p']).to.be.false + expect(data.transcoding.resolutions['360p']).to.be.true + expect(data.transcoding.resolutions['480p']).to.be.true + expect(data.transcoding.resolutions['720p']).to.be.false + expect(data.transcoding.resolutions['1080p']).to.be.false + }) + + it('Should have the configuration updated after a restart', async function () { + killallServers([ server ]) + + await reRunServer(server) + + const res = await getCustomConfig(server.url, server.accessToken) + const data = res.body + + expect(data.cache.previews.size).to.equal(2) + expect(data.signup.enabled).to.be.false + expect(data.signup.limit).to.equal(5) + expect(data.admin.email).to.equal('superadmin1@example.com') + expect(data.user.videoQuota).to.equal(5242881) + expect(data.transcoding.enabled).to.be.true + expect(data.transcoding.threads).to.equal(1) + expect(data.transcoding.resolutions['240p']).to.be.false + expect(data.transcoding.resolutions['360p']).to.be.true + expect(data.transcoding.resolutions['480p']).to.be.true + expect(data.transcoding.resolutions['720p']).to.be.false + expect(data.transcoding.resolutions['1080p']).to.be.false + }) + + it('Should remove the custom configuration', async function () { + await deleteCustomConfig(server.url, server.accessToken) + + const res = await getCustomConfig(server.url, server.accessToken) + const data = res.body + + expect(data.cache.previews.size).to.equal(1) + expect(data.signup.enabled).to.be.true + expect(data.signup.limit).to.equal(4) + expect(data.admin.email).to.equal('admin1@example.com') + expect(data.user.videoQuota).to.equal(5242880) + expect(data.transcoding.enabled).to.be.false + expect(data.transcoding.threads).to.equal(2) + expect(data.transcoding.resolutions['240p']).to.be.true + expect(data.transcoding.resolutions['360p']).to.be.true + expect(data.transcoding.resolutions['480p']).to.be.true + expect(data.transcoding.resolutions['720p']).to.be.true + expect(data.transcoding.resolutions['1080p']).to.be.true + }) + after(async function () { process.kill(-server.app.pid) 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' import 'mocha' import { join } from 'path' import { VideoPrivacy } from '../../../../shared/models/videos' +import { readdirPromise } from '../../../helpers/core-utils' import { completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences, getVideoPrivacies, - getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, readdirPromise, removeVideo, runServer, searchVideo, + getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, removeVideo, runServer, searchVideo, searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testVideoImage, updateVideo, uploadVideo, viewVideo } from '../../utils' -- cgit v1.2.3