1 /* tslint:disable:no-unused-expression */
3 import { omit } from 'lodash'
5 import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
16 setAccessTokensToServers,
18 } from '../../../../shared/extra-utils'
20 describe('Test config API validators', function () {
21 const path = '/api/v1/config/custom'
22 let server: ServerInfo
23 let userAccessToken: string
24 const updateParams: CustomConfig = {
26 name: 'PeerTube updated',
27 shortDescription: 'my short description',
28 description: 'my super description',
29 terms: 'my super terms',
30 codeOfConduct: 'my super coc',
32 creationReason: 'my super reason',
33 moderationInformation: 'my super moderation information',
34 administrator: 'Kuja',
35 maintenanceLifetime: 'forever',
36 businessModel: 'my super business model',
37 hardwareInformation: '2vCore 3GB RAM',
39 languages: [ 'en', 'es' ],
43 defaultClientRoute: '/videos/recently-added',
44 defaultNSFWPolicy: 'blur',
46 javascript: 'alert("coucou")',
47 css: 'body { background-color: red; }'
55 username: '@MySuperUsername',
70 requiresEmailVerification: false
73 email: 'superadmin1@example.com'
80 videoQuotaDaily: 318742
84 allowAdditionalExtensions: true,
85 allowAudioFiles: true,
129 indexUrl: 'https://index.example.com'
135 // ---------------------------------------------------------------
137 before(async function () {
140 server = await flushAndRunServer(1)
142 await setAccessTokensToServers([ server ])
148 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
149 userAccessToken = await userLogin(server, user)
152 describe('When getting the configuration', function () {
153 it('Should fail without token', async function () {
154 await makeGetRequest({
157 statusCodeExpected: 401
161 it('Should fail if the user is not an administrator', async function () {
162 await makeGetRequest({
165 token: userAccessToken,
166 statusCodeExpected: 403
171 describe('When updating the configuration', function () {
172 it('Should fail without token', async function () {
173 await makePutBodyRequest({
176 fields: updateParams,
177 statusCodeExpected: 401
181 it('Should fail if the user is not an administrator', async function () {
182 await makePutBodyRequest({
185 fields: updateParams,
186 token: userAccessToken,
187 statusCodeExpected: 403
191 it('Should fail if it misses a key', async function () {
192 const newUpdateParams = omit(updateParams, 'admin.email')
194 await makePutBodyRequest({
197 fields: newUpdateParams,
198 token: server.accessToken,
199 statusCodeExpected: 400
203 it('Should fail with a bad default NSFW policy', async function () {
204 const newUpdateParams = immutableAssign(updateParams, {
206 defaultNSFWPolicy: 'hello'
210 await makePutBodyRequest({
213 fields: newUpdateParams,
214 token: server.accessToken,
215 statusCodeExpected: 400
219 it('Should fail if email disabled and signup requires email verification', async function () {
220 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
221 const newUpdateParams = immutableAssign(updateParams, {
225 requiresEmailVerification: true
229 await makePutBodyRequest({
232 fields: newUpdateParams,
233 token: server.accessToken,
234 statusCodeExpected: 400
238 it('Should success with the correct parameters', async function () {
239 await makePutBodyRequest({
242 fields: updateParams,
243 token: server.accessToken,
244 statusCodeExpected: 200
249 describe('When deleting the configuration', function () {
250 it('Should fail without token', async function () {
251 await makeDeleteRequest({
254 statusCodeExpected: 401
258 it('Should fail if the user is not an administrator', async function () {
259 await makeDeleteRequest({
262 token: userAccessToken,
263 statusCodeExpected: 403
268 after(async function () {
269 await cleanupTests([ server ])