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
89 allowAdditionalExtensions: true,
90 allowAudioFiles: true,
93 profile: 'vod_profile',
117 maxInstanceLives: -1,
123 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 createSingleServer(1)
206 await setAccessTokensToServers([ server ])
212 await server.users.create({ username: user.username, password: user.password })
213 userAccessToken = await server.login.getAccessToken(user)
216 describe('When getting the configuration', function () {
217 it('Should fail without token', async function () {
218 await makeGetRequest({
221 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
225 it('Should fail if the user is not an administrator', async function () {
226 await makeGetRequest({
229 token: userAccessToken,
230 expectedStatus: 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 expectedStatus: 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 expectedStatus: 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 expectedStatus: HttpStatusCode.BAD_REQUEST_400
267 it('Should fail with a bad default NSFW policy', async function () {
268 const newUpdateParams = {
272 defaultNSFWPolicy: 'hello'
276 await makePutBodyRequest({
279 fields: newUpdateParams,
280 token: server.accessToken,
281 expectedStatus: HttpStatusCode.BAD_REQUEST_400
285 it('Should fail if email disabled and signup requires email verification', async function () {
286 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
287 const newUpdateParams = {
293 requiresEmailVerification: true
297 await makePutBodyRequest({
300 fields: newUpdateParams,
301 token: server.accessToken,
302 expectedStatus: HttpStatusCode.BAD_REQUEST_400
306 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
307 const newUpdateParams = {
320 await makePutBodyRequest({
323 fields: newUpdateParams,
324 token: server.accessToken,
325 expectedStatus: HttpStatusCode.BAD_REQUEST_400
329 it('Should success with the correct parameters', async function () {
330 await makePutBodyRequest({
333 fields: updateParams,
334 token: server.accessToken,
335 expectedStatus: HttpStatusCode.OK_200
340 describe('When deleting the configuration', function () {
341 it('Should fail without token', async function () {
342 await makeDeleteRequest({
345 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
349 it('Should fail if the user is not an administrator', async function () {
350 await makeDeleteRequest({
353 token: userAccessToken,
354 expectedStatus: HttpStatusCode.FORBIDDEN_403
359 after(async function () {
360 await cleanupTests([ server ])