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'
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 = { ...updateParams, admin: 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 requiresApproval: true,
318 requiresEmailVerification: true
322 await makePutBodyRequest({
325 fields: newUpdateParams,
326 token: server.accessToken,
327 expectedStatus: HttpStatusCode.BAD_REQUEST_400
331 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
332 const newUpdateParams = {
345 await makePutBodyRequest({
348 fields: newUpdateParams,
349 token: server.accessToken,
350 expectedStatus: HttpStatusCode.BAD_REQUEST_400
354 it('Should fail with a disabled http upload & enabled sync', async function () {
355 const newUpdateParams: CustomConfig = merge({}, updateParams, {
358 http: { enabled: false }
360 videoChannelSynchronization: { enabled: true }
364 await makePutBodyRequest({
367 fields: newUpdateParams,
368 token: server.accessToken,
369 expectedStatus: HttpStatusCode.BAD_REQUEST_400
373 it('Should succeed with the correct parameters', async function () {
374 await makePutBodyRequest({
377 fields: updateParams,
378 token: server.accessToken,
379 expectedStatus: HttpStatusCode.OK_200
384 describe('When deleting the configuration', function () {
385 it('Should fail without token', async function () {
386 await makeDeleteRequest({
389 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
393 it('Should fail if the user is not an administrator', async function () {
394 await makeDeleteRequest({
397 token: userAccessToken,
398 expectedStatus: HttpStatusCode.FORBIDDEN_403
403 after(async function () {
404 await cleanupTests([ server ])