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',
129 maxInstanceLives: -1,
135 profile: 'live_profile',
165 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
166 default: 'most-viewed'
190 indexUrl: 'https://index.example.com'
197 message: 'super message',
207 url: 'https://search.joinpeertube.org',
208 disableLocalSearch: true,
209 isDefaultSearch: true
214 // ---------------------------------------------------------------
216 before(async function () {
219 server = await createSingleServer(1)
221 await setAccessTokensToServers([ server ])
227 await server.users.create({ username: user.username, password: user.password })
228 userAccessToken = await server.login.getAccessToken(user)
231 describe('When getting the configuration', function () {
232 it('Should fail without token', async function () {
233 await makeGetRequest({
236 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
240 it('Should fail if the user is not an administrator', async function () {
241 await makeGetRequest({
244 token: userAccessToken,
245 expectedStatus: HttpStatusCode.FORBIDDEN_403
250 describe('When updating the configuration', function () {
251 it('Should fail without token', async function () {
252 await makePutBodyRequest({
255 fields: updateParams,
256 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
260 it('Should fail if the user is not an administrator', async function () {
261 await makePutBodyRequest({
264 fields: updateParams,
265 token: userAccessToken,
266 expectedStatus: HttpStatusCode.FORBIDDEN_403
270 it('Should fail if it misses a key', async function () {
271 const newUpdateParams = omit(updateParams, 'admin.email')
273 await makePutBodyRequest({
276 fields: newUpdateParams,
277 token: server.accessToken,
278 expectedStatus: HttpStatusCode.BAD_REQUEST_400
282 it('Should fail with a bad default NSFW policy', async function () {
283 const newUpdateParams = {
287 defaultNSFWPolicy: 'hello'
291 await makePutBodyRequest({
294 fields: newUpdateParams,
295 token: server.accessToken,
296 expectedStatus: HttpStatusCode.BAD_REQUEST_400
300 it('Should fail if email disabled and signup requires email verification', async function () {
301 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
302 const newUpdateParams = {
308 requiresEmailVerification: true
312 await makePutBodyRequest({
315 fields: newUpdateParams,
316 token: server.accessToken,
317 expectedStatus: HttpStatusCode.BAD_REQUEST_400
321 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
322 const newUpdateParams = {
335 await makePutBodyRequest({
338 fields: newUpdateParams,
339 token: server.accessToken,
340 expectedStatus: HttpStatusCode.BAD_REQUEST_400
344 it('Should success with the correct parameters', async function () {
345 await makePutBodyRequest({
348 fields: updateParams,
349 token: server.accessToken,
350 expectedStatus: HttpStatusCode.OK_200
355 describe('When deleting the configuration', function () {
356 it('Should fail without token', async function () {
357 await makeDeleteRequest({
360 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
364 it('Should fail if the user is not an administrator', async function () {
365 await makeDeleteRequest({
368 token: userAccessToken,
369 expectedStatus: HttpStatusCode.FORBIDDEN_403
374 after(async function () {
375 await cleanupTests([ server ])