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 requiresEmailVerification: false,
86 email: 'superadmin1@example.com'
93 videoQuotaDaily: 318742
100 allowAdditionalExtensions: true,
101 allowAudioFiles: true,
104 profile: 'vod_profile',
116 alwaysTranscodeOriginalResolution: false,
132 maxInstanceLives: -1,
138 profile: 'live_profile',
149 alwaysTranscodeOriginalResolution: false
165 videoChannelSynchronization: {
173 enabled: [ 'hot', 'most-viewed', 'most-liked' ],
174 default: 'most-viewed'
198 indexUrl: 'https://index.example.com'
205 message: 'super message',
215 url: 'https://search.joinpeertube.org',
216 disableLocalSearch: true,
217 isDefaultSearch: true
222 // ---------------------------------------------------------------
224 before(async function () {
227 server = await createSingleServer(1)
229 await setAccessTokensToServers([ server ])
235 await server.users.create({ username: user.username, password: user.password })
236 userAccessToken = await server.login.getAccessToken(user)
239 describe('When getting the configuration', function () {
240 it('Should fail without token', async function () {
241 await makeGetRequest({
244 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
248 it('Should fail if the user is not an administrator', async function () {
249 await makeGetRequest({
252 token: userAccessToken,
253 expectedStatus: HttpStatusCode.FORBIDDEN_403
258 describe('When updating the configuration', function () {
259 it('Should fail without token', async function () {
260 await makePutBodyRequest({
263 fields: updateParams,
264 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
268 it('Should fail if the user is not an administrator', async function () {
269 await makePutBodyRequest({
272 fields: updateParams,
273 token: userAccessToken,
274 expectedStatus: HttpStatusCode.FORBIDDEN_403
278 it('Should fail if it misses a key', async function () {
279 const newUpdateParams = { ...updateParams, admin: omit(updateParams.admin, [ 'email' ]) }
281 await makePutBodyRequest({
284 fields: newUpdateParams,
285 token: server.accessToken,
286 expectedStatus: HttpStatusCode.BAD_REQUEST_400
290 it('Should fail with a bad default NSFW policy', async function () {
291 const newUpdateParams = {
295 defaultNSFWPolicy: 'hello'
299 await makePutBodyRequest({
302 fields: newUpdateParams,
303 token: server.accessToken,
304 expectedStatus: HttpStatusCode.BAD_REQUEST_400
308 it('Should fail if email disabled and signup requires email verification', async function () {
309 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
310 const newUpdateParams = {
316 requiresEmailVerification: true
320 await makePutBodyRequest({
323 fields: newUpdateParams,
324 token: server.accessToken,
325 expectedStatus: HttpStatusCode.BAD_REQUEST_400
329 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
330 const newUpdateParams = {
343 await makePutBodyRequest({
346 fields: newUpdateParams,
347 token: server.accessToken,
348 expectedStatus: HttpStatusCode.BAD_REQUEST_400
352 it('Should fail with a disabled http upload & enabled sync', async function () {
353 const newUpdateParams: CustomConfig = merge({}, updateParams, {
356 http: { enabled: false }
358 videoChannelSynchronization: { enabled: true }
362 await makePutBodyRequest({
365 fields: newUpdateParams,
366 token: server.accessToken,
367 expectedStatus: HttpStatusCode.BAD_REQUEST_400
371 it('Should succeed with the correct parameters', async function () {
372 await makePutBodyRequest({
375 fields: updateParams,
376 token: server.accessToken,
377 expectedStatus: HttpStatusCode.OK_200
382 describe('When deleting the configuration', function () {
383 it('Should fail without token', async function () {
384 await makeDeleteRequest({
387 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
391 it('Should fail if the user is not an administrator', async function () {
392 await makeDeleteRequest({
395 token: userAccessToken,
396 expectedStatus: HttpStatusCode.FORBIDDEN_403
401 after(async function () {
402 await cleanupTests([ server ])