1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { omit } from 'lodash'
5 import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
16 setAccessTokensToServers,
18 } from '../../../../shared/extra-utils'
19 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
21 describe('Test config API validators', function () {
22 const path = '/api/v1/config/custom'
23 let server: ServerInfo
24 let userAccessToken: string
25 const updateParams: CustomConfig = {
27 name: 'PeerTube updated',
28 shortDescription: 'my short description',
29 description: 'my super description',
30 terms: 'my super terms',
31 codeOfConduct: 'my super coc',
33 creationReason: 'my super reason',
34 moderationInformation: 'my super moderation information',
35 administrator: 'Kuja',
36 maintenanceLifetime: 'forever',
37 businessModel: 'my super business model',
38 hardwareInformation: '2vCore 3GB RAM',
40 languages: [ 'en', 'es' ],
44 defaultNSFWPolicy: 'blur',
46 defaultClientRoute: '/videos/recently-added',
49 javascript: 'alert("coucou")',
50 css: 'body { background-color: red; }'
58 username: '@MySuperUsername',
76 requiresEmailVerification: false,
80 email: 'superadmin1@example.com'
87 videoQuotaDaily: 318742
91 allowAdditionalExtensions: true,
92 allowAudioFiles: true,
95 profile: 'vod_profile',
118 maxInstanceLives: -1,
124 profile: 'live_profile',
150 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
151 default: 'most-viewed'
175 indexUrl: 'https://index.example.com'
182 message: 'super message',
192 url: 'https://search.joinpeertube.org',
193 disableLocalSearch: true,
194 isDefaultSearch: true
199 // ---------------------------------------------------------------
201 before(async function () {
204 server = await flushAndRunServer(1)
206 await setAccessTokensToServers([ server ])
212 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
213 userAccessToken = await userLogin(server, user)
216 describe('When getting the configuration', function () {
217 it('Should fail without token', async function () {
218 await makeGetRequest({
221 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
225 it('Should fail if the user is not an administrator', async function () {
226 await makeGetRequest({
229 token: userAccessToken,
230 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
235 describe('When updating the configuration', function () {
236 it('Should fail without token', async function () {
237 await makePutBodyRequest({
240 fields: updateParams,
241 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
245 it('Should fail if the user is not an administrator', async function () {
246 await makePutBodyRequest({
249 fields: updateParams,
250 token: userAccessToken,
251 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
255 it('Should fail if it misses a key', async function () {
256 const newUpdateParams = omit(updateParams, 'admin.email')
258 await makePutBodyRequest({
261 fields: newUpdateParams,
262 token: server.accessToken,
263 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
267 it('Should fail with a bad default NSFW policy', async function () {
268 const newUpdateParams = immutableAssign(updateParams, {
270 defaultNSFWPolicy: 'hello'
274 await makePutBodyRequest({
277 fields: newUpdateParams,
278 token: server.accessToken,
279 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
283 it('Should fail if email disabled and signup requires email verification', async function () {
284 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
285 const newUpdateParams = immutableAssign(updateParams, {
289 requiresEmailVerification: true
293 await makePutBodyRequest({
296 fields: newUpdateParams,
297 token: server.accessToken,
298 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
302 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
303 const newUpdateParams = immutableAssign(updateParams, {
314 await makePutBodyRequest({
317 fields: newUpdateParams,
318 token: server.accessToken,
319 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
323 it('Should success with the correct parameters', async function () {
324 await makePutBodyRequest({
327 fields: updateParams,
328 token: server.accessToken,
329 statusCodeExpected: HttpStatusCode.OK_200
334 describe('When deleting the configuration', function () {
335 it('Should fail without token', async function () {
336 await makeDeleteRequest({
339 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
343 it('Should fail if the user is not an administrator', async function () {
344 await makeDeleteRequest({
347 token: userAccessToken,
348 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
353 after(async function () {
354 await cleanupTests([ server ])