1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { omit } from 'lodash'
12 setAccessTokensToServers
13 } from '@shared/extra-utils'
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',
71 requiresEmailVerification: false,
75 email: 'superadmin1@example.com'
82 videoQuotaDaily: 318742
86 allowAdditionalExtensions: true,
87 allowAudioFiles: true,
90 profile: 'vod_profile',
113 maxInstanceLives: -1,
119 profile: 'live_profile',
145 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
146 default: 'most-viewed'
170 indexUrl: 'https://index.example.com'
177 message: 'super message',
187 url: 'https://search.joinpeertube.org',
188 disableLocalSearch: true,
189 isDefaultSearch: true
194 // ---------------------------------------------------------------
196 before(async function () {
199 server = await createSingleServer(1)
201 await setAccessTokensToServers([ server ])
207 await server.users.create({ username: user.username, password: user.password })
208 userAccessToken = await server.login.getAccessToken(user)
211 describe('When getting the configuration', function () {
212 it('Should fail without token', async function () {
213 await makeGetRequest({
216 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
220 it('Should fail if the user is not an administrator', async function () {
221 await makeGetRequest({
224 token: userAccessToken,
225 expectedStatus: HttpStatusCode.FORBIDDEN_403
230 describe('When updating the configuration', function () {
231 it('Should fail without token', async function () {
232 await makePutBodyRequest({
235 fields: updateParams,
236 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
240 it('Should fail if the user is not an administrator', async function () {
241 await makePutBodyRequest({
244 fields: updateParams,
245 token: userAccessToken,
246 expectedStatus: HttpStatusCode.FORBIDDEN_403
250 it('Should fail if it misses a key', async function () {
251 const newUpdateParams = omit(updateParams, 'admin.email')
253 await makePutBodyRequest({
256 fields: newUpdateParams,
257 token: server.accessToken,
258 expectedStatus: HttpStatusCode.BAD_REQUEST_400
262 it('Should fail with a bad default NSFW policy', async function () {
263 const newUpdateParams = {
267 defaultNSFWPolicy: 'hello'
271 await makePutBodyRequest({
274 fields: newUpdateParams,
275 token: server.accessToken,
276 expectedStatus: HttpStatusCode.BAD_REQUEST_400
280 it('Should fail if email disabled and signup requires email verification', async function () {
281 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
282 const newUpdateParams = {
288 requiresEmailVerification: true
292 await makePutBodyRequest({
295 fields: newUpdateParams,
296 token: server.accessToken,
297 expectedStatus: HttpStatusCode.BAD_REQUEST_400
301 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
302 const newUpdateParams = {
315 await makePutBodyRequest({
318 fields: newUpdateParams,
319 token: server.accessToken,
320 expectedStatus: HttpStatusCode.BAD_REQUEST_400
324 it('Should success with the correct parameters', async function () {
325 await makePutBodyRequest({
328 fields: updateParams,
329 token: server.accessToken,
330 expectedStatus: HttpStatusCode.OK_200
335 describe('When deleting the configuration', function () {
336 it('Should fail without token', async function () {
337 await makeDeleteRequest({
340 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
344 it('Should fail if the user is not an administrator', async function () {
345 await makeDeleteRequest({
348 token: userAccessToken,
349 expectedStatus: HttpStatusCode.FORBIDDEN_403
354 after(async function () {
355 await cleanupTests([ server ])