1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { omit } from 'lodash'
12 setAccessTokensToServers
13 } from '@shared/extra-utils'
14 import { CustomConfig, HttpStatusCode } from '@shared/models'
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',
129 maxInstanceLives: -1,
135 profile: 'live_profile',
162 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
163 default: 'most-viewed'
187 indexUrl: 'https://index.example.com'
194 message: 'super message',
204 url: 'https://search.joinpeertube.org',
205 disableLocalSearch: true,
206 isDefaultSearch: true
211 // ---------------------------------------------------------------
213 before(async function () {
216 server = await createSingleServer(1)
218 await setAccessTokensToServers([ server ])
224 await server.users.create({ username: user.username, password: user.password })
225 userAccessToken = await server.login.getAccessToken(user)
228 describe('When getting the configuration', function () {
229 it('Should fail without token', async function () {
230 await makeGetRequest({
233 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
237 it('Should fail if the user is not an administrator', async function () {
238 await makeGetRequest({
241 token: userAccessToken,
242 expectedStatus: HttpStatusCode.FORBIDDEN_403
247 describe('When updating the configuration', function () {
248 it('Should fail without token', async function () {
249 await makePutBodyRequest({
252 fields: updateParams,
253 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
257 it('Should fail if the user is not an administrator', async function () {
258 await makePutBodyRequest({
261 fields: updateParams,
262 token: userAccessToken,
263 expectedStatus: HttpStatusCode.FORBIDDEN_403
267 it('Should fail if it misses a key', async function () {
268 const newUpdateParams = omit(updateParams, 'admin.email')
270 await makePutBodyRequest({
273 fields: newUpdateParams,
274 token: server.accessToken,
275 expectedStatus: HttpStatusCode.BAD_REQUEST_400
279 it('Should fail with a bad default NSFW policy', async function () {
280 const newUpdateParams = {
284 defaultNSFWPolicy: 'hello'
288 await makePutBodyRequest({
291 fields: newUpdateParams,
292 token: server.accessToken,
293 expectedStatus: HttpStatusCode.BAD_REQUEST_400
297 it('Should fail if email disabled and signup requires email verification', async function () {
298 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
299 const newUpdateParams = {
305 requiresEmailVerification: true
309 await makePutBodyRequest({
312 fields: newUpdateParams,
313 token: server.accessToken,
314 expectedStatus: HttpStatusCode.BAD_REQUEST_400
318 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
319 const newUpdateParams = {
332 await makePutBodyRequest({
335 fields: newUpdateParams,
336 token: server.accessToken,
337 expectedStatus: HttpStatusCode.BAD_REQUEST_400
341 it('Should success with the correct parameters', async function () {
342 await makePutBodyRequest({
345 fields: updateParams,
346 token: server.accessToken,
347 expectedStatus: HttpStatusCode.OK_200
352 describe('When deleting the configuration', function () {
353 it('Should fail without token', async function () {
354 await makeDeleteRequest({
357 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
361 it('Should fail if the user is not an administrator', async function () {
362 await makeDeleteRequest({
365 token: userAccessToken,
366 expectedStatus: HttpStatusCode.FORBIDDEN_403
371 after(async function () {
372 await cleanupTests([ server ])