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,
90 profile: 'vod_profile',
113 maxInstanceLives: -1,
119 profile: 'live_profile',
144 enabled: [ 'hot', 'most-viewed', 'most-liked' ],
145 default: 'most-viewed'
169 indexUrl: 'https://index.example.com'
176 message: 'super message',
186 url: 'https://search.joinpeertube.org',
187 disableLocalSearch: true,
188 isDefaultSearch: true
193 // ---------------------------------------------------------------
195 before(async function () {
198 server = await flushAndRunServer(1)
200 await setAccessTokensToServers([ server ])
206 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
207 userAccessToken = await userLogin(server, user)
210 describe('When getting the configuration', function () {
211 it('Should fail without token', async function () {
212 await makeGetRequest({
215 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
219 it('Should fail if the user is not an administrator', async function () {
220 await makeGetRequest({
223 token: userAccessToken,
224 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
229 describe('When updating the configuration', function () {
230 it('Should fail without token', async function () {
231 await makePutBodyRequest({
234 fields: updateParams,
235 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
239 it('Should fail if the user is not an administrator', async function () {
240 await makePutBodyRequest({
243 fields: updateParams,
244 token: userAccessToken,
245 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
249 it('Should fail if it misses a key', async function () {
250 const newUpdateParams = omit(updateParams, 'admin.email')
252 await makePutBodyRequest({
255 fields: newUpdateParams,
256 token: server.accessToken,
257 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
261 it('Should fail with a bad default NSFW policy', async function () {
262 const newUpdateParams = immutableAssign(updateParams, {
264 defaultNSFWPolicy: 'hello'
268 await makePutBodyRequest({
271 fields: newUpdateParams,
272 token: server.accessToken,
273 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
277 it('Should fail if email disabled and signup requires email verification', async function () {
278 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
279 const newUpdateParams = immutableAssign(updateParams, {
283 requiresEmailVerification: true
287 await makePutBodyRequest({
290 fields: newUpdateParams,
291 token: server.accessToken,
292 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
296 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
297 const newUpdateParams = immutableAssign(updateParams, {
308 await makePutBodyRequest({
311 fields: newUpdateParams,
312 token: server.accessToken,
313 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
317 it('Should success with the correct parameters', async function () {
318 await makePutBodyRequest({
321 fields: updateParams,
322 token: server.accessToken,
323 statusCodeExpected: HttpStatusCode.OK_200
328 describe('When deleting the configuration', function () {
329 it('Should fail without token', async function () {
330 await makeDeleteRequest({
333 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
337 it('Should fail if the user is not an administrator', async function () {
338 await makeDeleteRequest({
341 token: userAccessToken,
342 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
347 after(async function () {
348 await cleanupTests([ server ])