1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { merge, omit } from 'lodash'
5 import { CustomConfig, HttpStatusCode } from '@shared/models'
13 setAccessTokensToServers
14 } from '@shared/server-commands'
16 describe('Test config API validators', function () {
17 const path = '/api/v1/config/custom'
18 let server: PeerTubeServer
19 let userAccessToken: string
20 const updateParams: CustomConfig = {
22 name: 'PeerTube updated',
23 shortDescription: 'my short description',
24 description: 'my super description',
25 terms: 'my super terms',
26 codeOfConduct: 'my super coc',
28 creationReason: 'my super reason',
29 moderationInformation: 'my super moderation information',
30 administrator: 'Kuja',
31 maintenanceLifetime: 'forever',
32 businessModel: 'my super business model',
33 hardwareInformation: '2vCore 3GB RAM',
35 languages: [ 'en', 'es' ],
39 defaultNSFWPolicy: 'blur',
41 defaultClientRoute: '/videos/recently-added',
44 javascript: 'alert("coucou")',
45 css: 'body { background-color: red; }'
53 username: '@MySuperUsername',
60 preferAuthorDisplayName: false
65 redirectOnSingleExternalAuth: false
83 requiresEmailVerification: false,
87 email: 'superadmin1@example.com'
94 videoQuotaDaily: 318742
101 allowAdditionalExtensions: true,
102 allowAudioFiles: true,
105 profile: 'vod_profile',
117 alwaysTranscodeOriginalResolution: false,
133 maxInstanceLives: -1,
139 profile: 'live_profile',
150 alwaysTranscodeOriginalResolution: false
166 videoChannelSynchronization: {
174 enabled: [ 'hot', 'most-viewed', 'most-liked' ],
175 default: 'most-viewed'
199 indexUrl: 'https://index.example.com'
206 message: 'super message',
216 url: 'https://search.joinpeertube.org',
217 disableLocalSearch: true,
218 isDefaultSearch: true
223 // ---------------------------------------------------------------
225 before(async function () {
228 server = await createSingleServer(1)
230 await setAccessTokensToServers([ server ])
236 await server.users.create({ username: user.username, password: user.password })
237 userAccessToken = await server.login.getAccessToken(user)
240 describe('When getting the configuration', function () {
241 it('Should fail without token', async function () {
242 await makeGetRequest({
245 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
249 it('Should fail if the user is not an administrator', async function () {
250 await makeGetRequest({
253 token: userAccessToken,
254 expectedStatus: HttpStatusCode.FORBIDDEN_403
259 describe('When updating the configuration', function () {
260 it('Should fail without token', async function () {
261 await makePutBodyRequest({
264 fields: updateParams,
265 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
269 it('Should fail if the user is not an administrator', async function () {
270 await makePutBodyRequest({
273 fields: updateParams,
274 token: userAccessToken,
275 expectedStatus: HttpStatusCode.FORBIDDEN_403
279 it('Should fail if it misses a key', async function () {
280 const newUpdateParams = omit(updateParams, 'admin.email')
282 await makePutBodyRequest({
285 fields: newUpdateParams,
286 token: server.accessToken,
287 expectedStatus: HttpStatusCode.BAD_REQUEST_400
291 it('Should fail with a bad default NSFW policy', async function () {
292 const newUpdateParams = {
296 defaultNSFWPolicy: 'hello'
300 await makePutBodyRequest({
303 fields: newUpdateParams,
304 token: server.accessToken,
305 expectedStatus: HttpStatusCode.BAD_REQUEST_400
309 it('Should fail if email disabled and signup requires email verification', async function () {
310 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
311 const newUpdateParams = {
317 requiresEmailVerification: true
321 await makePutBodyRequest({
324 fields: newUpdateParams,
325 token: server.accessToken,
326 expectedStatus: HttpStatusCode.BAD_REQUEST_400
330 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
331 const newUpdateParams = {
344 await makePutBodyRequest({
347 fields: newUpdateParams,
348 token: server.accessToken,
349 expectedStatus: HttpStatusCode.BAD_REQUEST_400
353 it('Should fail with a disabled http upload & enabled sync', async function () {
354 const newUpdateParams: CustomConfig = merge({}, updateParams, {
357 http: { enabled: false }
359 videoChannelSynchronization: { enabled: true }
363 await makePutBodyRequest({
366 fields: newUpdateParams,
367 token: server.accessToken,
368 expectedStatus: HttpStatusCode.BAD_REQUEST_400
372 it('Should succeed with the correct parameters', async function () {
373 await makePutBodyRequest({
376 fields: updateParams,
377 token: server.accessToken,
378 expectedStatus: HttpStatusCode.OK_200
383 describe('When deleting the configuration', function () {
384 it('Should fail without token', async function () {
385 await makeDeleteRequest({
388 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
392 it('Should fail if the user is not an administrator', async function () {
393 await makeDeleteRequest({
396 token: userAccessToken,
397 expectedStatus: HttpStatusCode.FORBIDDEN_403
402 after(async function () {
403 await cleanupTests([ server ])