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',
73 requiresEmailVerification: false
76 email: 'superadmin1@example.com'
83 videoQuotaDaily: 318742
87 allowAdditionalExtensions: true,
88 allowAudioFiles: true,
112 maxInstanceLives: -1,
142 enabled: [ 'hot', 'most-viewed', 'most-liked' ],
143 default: 'most-viewed'
167 indexUrl: 'https://index.example.com'
174 message: 'super message',
184 url: 'https://search.joinpeertube.org',
185 disableLocalSearch: true,
186 isDefaultSearch: true
191 // ---------------------------------------------------------------
193 before(async function () {
196 server = await flushAndRunServer(1)
198 await setAccessTokensToServers([ server ])
204 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
205 userAccessToken = await userLogin(server, user)
208 describe('When getting the configuration', function () {
209 it('Should fail without token', async function () {
210 await makeGetRequest({
213 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
217 it('Should fail if the user is not an administrator', async function () {
218 await makeGetRequest({
221 token: userAccessToken,
222 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
227 describe('When updating the configuration', function () {
228 it('Should fail without token', async function () {
229 await makePutBodyRequest({
232 fields: updateParams,
233 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
237 it('Should fail if the user is not an administrator', async function () {
238 await makePutBodyRequest({
241 fields: updateParams,
242 token: userAccessToken,
243 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
247 it('Should fail if it misses a key', async function () {
248 const newUpdateParams = omit(updateParams, 'admin.email')
250 await makePutBodyRequest({
253 fields: newUpdateParams,
254 token: server.accessToken,
255 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
259 it('Should fail with a bad default NSFW policy', async function () {
260 const newUpdateParams = immutableAssign(updateParams, {
262 defaultNSFWPolicy: 'hello'
266 await makePutBodyRequest({
269 fields: newUpdateParams,
270 token: server.accessToken,
271 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
275 it('Should fail if email disabled and signup requires email verification', async function () {
276 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
277 const newUpdateParams = immutableAssign(updateParams, {
281 requiresEmailVerification: true
285 await makePutBodyRequest({
288 fields: newUpdateParams,
289 token: server.accessToken,
290 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
294 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
295 const newUpdateParams = immutableAssign(updateParams, {
306 await makePutBodyRequest({
309 fields: newUpdateParams,
310 token: server.accessToken,
311 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
315 it('Should success with the correct parameters', async function () {
316 await makePutBodyRequest({
319 fields: updateParams,
320 token: server.accessToken,
321 statusCodeExpected: HttpStatusCode.OK_200
326 describe('When deleting the configuration', function () {
327 it('Should fail without token', async function () {
328 await makeDeleteRequest({
331 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
335 it('Should fail if the user is not an administrator', async function () {
336 await makeDeleteRequest({
339 token: userAccessToken,
340 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
345 after(async function () {
346 await cleanupTests([ server ])