1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { omit } from 'lodash'
12 setAccessTokensToServers
13 } from '@shared/server-commands'
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',
132 maxInstanceLives: -1,
138 profile: 'live_profile',
168 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
169 default: 'most-viewed'
193 indexUrl: 'https://index.example.com'
200 message: 'super message',
210 url: 'https://search.joinpeertube.org',
211 disableLocalSearch: true,
212 isDefaultSearch: true
217 // ---------------------------------------------------------------
219 before(async function () {
222 server = await createSingleServer(1)
224 await setAccessTokensToServers([ server ])
230 await server.users.create({ username: user.username, password: user.password })
231 userAccessToken = await server.login.getAccessToken(user)
234 describe('When getting the configuration', function () {
235 it('Should fail without token', async function () {
236 await makeGetRequest({
239 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
243 it('Should fail if the user is not an administrator', async function () {
244 await makeGetRequest({
247 token: userAccessToken,
248 expectedStatus: HttpStatusCode.FORBIDDEN_403
253 describe('When updating the configuration', function () {
254 it('Should fail without token', async function () {
255 await makePutBodyRequest({
258 fields: updateParams,
259 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
263 it('Should fail if the user is not an administrator', async function () {
264 await makePutBodyRequest({
267 fields: updateParams,
268 token: userAccessToken,
269 expectedStatus: HttpStatusCode.FORBIDDEN_403
273 it('Should fail if it misses a key', async function () {
274 const newUpdateParams = omit(updateParams, 'admin.email')
276 await makePutBodyRequest({
279 fields: newUpdateParams,
280 token: server.accessToken,
281 expectedStatus: HttpStatusCode.BAD_REQUEST_400
285 it('Should fail with a bad default NSFW policy', async function () {
286 const newUpdateParams = {
290 defaultNSFWPolicy: 'hello'
294 await makePutBodyRequest({
297 fields: newUpdateParams,
298 token: server.accessToken,
299 expectedStatus: HttpStatusCode.BAD_REQUEST_400
303 it('Should fail if email disabled and signup requires email verification', async function () {
304 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
305 const newUpdateParams = {
311 requiresEmailVerification: true
315 await makePutBodyRequest({
318 fields: newUpdateParams,
319 token: server.accessToken,
320 expectedStatus: HttpStatusCode.BAD_REQUEST_400
324 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
325 const newUpdateParams = {
338 await makePutBodyRequest({
341 fields: newUpdateParams,
342 token: server.accessToken,
343 expectedStatus: HttpStatusCode.BAD_REQUEST_400
347 it('Should success with the correct parameters', async function () {
348 await makePutBodyRequest({
351 fields: updateParams,
352 token: server.accessToken,
353 expectedStatus: HttpStatusCode.OK_200
358 describe('When deleting the configuration', function () {
359 it('Should fail without token', async function () {
360 await makeDeleteRequest({
363 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
367 it('Should fail if the user is not an administrator', async function () {
368 await makeDeleteRequest({
371 token: userAccessToken,
372 expectedStatus: HttpStatusCode.FORBIDDEN_403
377 after(async function () {
378 await cleanupTests([ server ])