1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { omit } from 'lodash'
5 import { HttpStatusCode } from '@shared/core-utils'
14 setAccessTokensToServers
15 } from '@shared/extra-utils'
16 import { CustomConfig } from '@shared/models'
18 describe('Test config API validators', function () {
19 const path = '/api/v1/config/custom'
20 let server: ServerInfo
21 let userAccessToken: string
22 const updateParams: CustomConfig = {
24 name: 'PeerTube updated',
25 shortDescription: 'my short description',
26 description: 'my super description',
27 terms: 'my super terms',
28 codeOfConduct: 'my super coc',
30 creationReason: 'my super reason',
31 moderationInformation: 'my super moderation information',
32 administrator: 'Kuja',
33 maintenanceLifetime: 'forever',
34 businessModel: 'my super business model',
35 hardwareInformation: '2vCore 3GB RAM',
37 languages: [ 'en', 'es' ],
41 defaultNSFWPolicy: 'blur',
43 defaultClientRoute: '/videos/recently-added',
46 javascript: 'alert("coucou")',
47 css: 'body { background-color: red; }'
55 username: '@MySuperUsername',
73 requiresEmailVerification: false,
77 email: 'superadmin1@example.com'
84 videoQuotaDaily: 318742
88 allowAdditionalExtensions: true,
89 allowAudioFiles: true,
92 profile: 'vod_profile',
115 maxInstanceLives: -1,
121 profile: 'live_profile',
147 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
148 default: 'most-viewed'
172 indexUrl: 'https://index.example.com'
179 message: 'super message',
189 url: 'https://search.joinpeertube.org',
190 disableLocalSearch: true,
191 isDefaultSearch: true
196 // ---------------------------------------------------------------
198 before(async function () {
201 server = await flushAndRunServer(1)
203 await setAccessTokensToServers([ server ])
209 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
210 userAccessToken = await server.loginCommand.getAccessToken(user)
213 describe('When getting the configuration', function () {
214 it('Should fail without token', async function () {
215 await makeGetRequest({
218 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
222 it('Should fail if the user is not an administrator', async function () {
223 await makeGetRequest({
226 token: userAccessToken,
227 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
232 describe('When updating the configuration', function () {
233 it('Should fail without token', async function () {
234 await makePutBodyRequest({
237 fields: updateParams,
238 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
242 it('Should fail if the user is not an administrator', async function () {
243 await makePutBodyRequest({
246 fields: updateParams,
247 token: userAccessToken,
248 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
252 it('Should fail if it misses a key', async function () {
253 const newUpdateParams = omit(updateParams, 'admin.email')
255 await makePutBodyRequest({
258 fields: newUpdateParams,
259 token: server.accessToken,
260 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
264 it('Should fail with a bad default NSFW policy', async function () {
265 const newUpdateParams = {
269 defaultNSFWPolicy: 'hello'
273 await makePutBodyRequest({
276 fields: newUpdateParams,
277 token: server.accessToken,
278 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
282 it('Should fail if email disabled and signup requires email verification', async function () {
283 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
284 const newUpdateParams = {
290 requiresEmailVerification: true
294 await makePutBodyRequest({
297 fields: newUpdateParams,
298 token: server.accessToken,
299 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
303 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
304 const newUpdateParams = {
317 await makePutBodyRequest({
320 fields: newUpdateParams,
321 token: server.accessToken,
322 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
326 it('Should success with the correct parameters', async function () {
327 await makePutBodyRequest({
330 fields: updateParams,
331 token: server.accessToken,
332 statusCodeExpected: HttpStatusCode.OK_200
337 describe('When deleting the configuration', function () {
338 it('Should fail without token', async function () {
339 await makeDeleteRequest({
342 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
346 it('Should fail if the user is not an administrator', async function () {
347 await makeDeleteRequest({
350 token: userAccessToken,
351 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
356 after(async function () {
357 await cleanupTests([ server ])