1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 import { merge } from 'lodash'
3 import { omit } from '@shared/core-utils'
4 import { CustomConfig, HttpStatusCode } from '@shared/models'
12 setAccessTokensToServers
13 } from '@shared/server-commands'
15 describe('Test config API validators', function () {
16 const path = '/api/v1/config/custom'
17 let server: PeerTubeServer
18 let userAccessToken: string
19 const updateParams: CustomConfig = {
21 name: 'PeerTube updated',
22 shortDescription: 'my short description',
23 description: 'my super description',
24 terms: 'my super terms',
25 codeOfConduct: 'my super coc',
27 creationReason: 'my super reason',
28 moderationInformation: 'my super moderation information',
29 administrator: 'Kuja',
30 maintenanceLifetime: 'forever',
31 businessModel: 'my super business model',
32 hardwareInformation: '2vCore 3GB RAM',
34 languages: [ 'en', 'es' ],
38 defaultNSFWPolicy: 'blur',
40 defaultClientRoute: '/videos/recently-added',
43 javascript: 'alert("coucou")',
44 css: 'body { background-color: red; }'
52 username: '@MySuperUsername',
59 preferAuthorDisplayName: false
64 redirectOnSingleExternalAuth: false
82 requiresApproval: false,
83 requiresEmailVerification: false,
87 email: 'superadmin1@example.com'
99 videoQuotaDaily: 318742
109 allowAdditionalExtensions: true,
110 allowAudioFiles: true,
113 profile: 'vod_profile',
125 alwaysTranscodeOriginalResolution: false,
141 maxInstanceLives: -1,
150 profile: 'live_profile',
161 alwaysTranscodeOriginalResolution: false
180 videoChannelSynchronization: {
188 enabled: [ 'hot', 'most-viewed', 'most-liked' ],
189 default: 'most-viewed'
213 indexUrl: 'https://index.example.com'
220 message: 'super message',
230 url: 'https://search.joinpeertube.org',
231 disableLocalSearch: true,
232 isDefaultSearch: true
237 // ---------------------------------------------------------------
239 before(async function () {
242 server = await createSingleServer(1)
244 await setAccessTokensToServers([ server ])
250 await server.users.create({ username: user.username, password: user.password })
251 userAccessToken = await server.login.getAccessToken(user)
254 describe('When getting the configuration', function () {
255 it('Should fail without token', async function () {
256 await makeGetRequest({
259 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
263 it('Should fail if the user is not an administrator', async function () {
264 await makeGetRequest({
267 token: userAccessToken,
268 expectedStatus: HttpStatusCode.FORBIDDEN_403
273 describe('When updating the configuration', function () {
274 it('Should fail without token', async function () {
275 await makePutBodyRequest({
278 fields: updateParams,
279 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
283 it('Should fail if the user is not an administrator', async function () {
284 await makePutBodyRequest({
287 fields: updateParams,
288 token: userAccessToken,
289 expectedStatus: HttpStatusCode.FORBIDDEN_403
293 it('Should fail if it misses a key', async function () {
294 const newUpdateParams = { ...updateParams, admin: omit(updateParams.admin, [ 'email' ]) }
296 await makePutBodyRequest({
299 fields: newUpdateParams,
300 token: server.accessToken,
301 expectedStatus: HttpStatusCode.BAD_REQUEST_400
305 it('Should fail with a bad default NSFW policy', async function () {
306 const newUpdateParams = {
310 defaultNSFWPolicy: 'hello'
314 await makePutBodyRequest({
317 fields: newUpdateParams,
318 token: server.accessToken,
319 expectedStatus: HttpStatusCode.BAD_REQUEST_400
323 it('Should fail if email disabled and signup requires email verification', async function () {
324 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
325 const newUpdateParams = {
331 requiresApproval: true,
332 requiresEmailVerification: true
336 await makePutBodyRequest({
339 fields: newUpdateParams,
340 token: server.accessToken,
341 expectedStatus: HttpStatusCode.BAD_REQUEST_400
345 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
346 const newUpdateParams = {
359 await makePutBodyRequest({
362 fields: newUpdateParams,
363 token: server.accessToken,
364 expectedStatus: HttpStatusCode.BAD_REQUEST_400
368 it('Should fail with a disabled http upload & enabled sync', async function () {
369 const newUpdateParams: CustomConfig = merge({}, updateParams, {
372 http: { enabled: false }
374 videoChannelSynchronization: { enabled: true }
378 await makePutBodyRequest({
381 fields: newUpdateParams,
382 token: server.accessToken,
383 expectedStatus: HttpStatusCode.BAD_REQUEST_400
387 it('Should succeed with the correct parameters', async function () {
388 await makePutBodyRequest({
391 fields: updateParams,
392 token: server.accessToken,
393 expectedStatus: HttpStatusCode.OK_200
398 describe('When deleting the configuration', function () {
399 it('Should fail without token', async function () {
400 await makeDeleteRequest({
403 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
407 it('Should fail if the user is not an administrator', async function () {
408 await makeDeleteRequest({
411 token: userAccessToken,
412 expectedStatus: HttpStatusCode.FORBIDDEN_403
417 after(async function () {
418 await cleanupTests([ server ])