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',
116 maxInstanceLives: -1,
122 profile: 'live_profile',
148 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
149 default: 'most-viewed'
173 indexUrl: 'https://index.example.com'
180 message: 'super message',
190 url: 'https://search.joinpeertube.org',
191 disableLocalSearch: true,
192 isDefaultSearch: true
197 // ---------------------------------------------------------------
199 before(async function () {
202 server = await createSingleServer(1)
204 await setAccessTokensToServers([ server ])
210 await server.users.create({ username: user.username, password: user.password })
211 userAccessToken = await server.login.getAccessToken(user)
214 describe('When getting the configuration', function () {
215 it('Should fail without token', async function () {
216 await makeGetRequest({
219 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
223 it('Should fail if the user is not an administrator', async function () {
224 await makeGetRequest({
227 token: userAccessToken,
228 expectedStatus: HttpStatusCode.FORBIDDEN_403
233 describe('When updating the configuration', function () {
234 it('Should fail without token', async function () {
235 await makePutBodyRequest({
238 fields: updateParams,
239 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
243 it('Should fail if the user is not an administrator', async function () {
244 await makePutBodyRequest({
247 fields: updateParams,
248 token: userAccessToken,
249 expectedStatus: HttpStatusCode.FORBIDDEN_403
253 it('Should fail if it misses a key', async function () {
254 const newUpdateParams = omit(updateParams, 'admin.email')
256 await makePutBodyRequest({
259 fields: newUpdateParams,
260 token: server.accessToken,
261 expectedStatus: HttpStatusCode.BAD_REQUEST_400
265 it('Should fail with a bad default NSFW policy', async function () {
266 const newUpdateParams = {
270 defaultNSFWPolicy: 'hello'
274 await makePutBodyRequest({
277 fields: newUpdateParams,
278 token: server.accessToken,
279 expectedStatus: 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 = {
291 requiresEmailVerification: true
295 await makePutBodyRequest({
298 fields: newUpdateParams,
299 token: server.accessToken,
300 expectedStatus: HttpStatusCode.BAD_REQUEST_400
304 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
305 const newUpdateParams = {
318 await makePutBodyRequest({
321 fields: newUpdateParams,
322 token: server.accessToken,
323 expectedStatus: HttpStatusCode.BAD_REQUEST_400
327 it('Should success with the correct parameters', async function () {
328 await makePutBodyRequest({
331 fields: updateParams,
332 token: server.accessToken,
333 expectedStatus: HttpStatusCode.OK_200
338 describe('When deleting the configuration', function () {
339 it('Should fail without token', async function () {
340 await makeDeleteRequest({
343 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
347 it('Should fail if the user is not an administrator', async function () {
348 await makeDeleteRequest({
351 token: userAccessToken,
352 expectedStatus: HttpStatusCode.FORBIDDEN_403
357 after(async function () {
358 await cleanupTests([ server ])