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 defaultClientRoute: '/videos/recently-added',
45 defaultNSFWPolicy: 'blur',
47 javascript: 'alert("coucou")',
48 css: 'body { background-color: red; }'
56 username: '@MySuperUsername',
71 requiresEmailVerification: false
74 email: 'superadmin1@example.com'
81 videoQuotaDaily: 318742
85 allowAdditionalExtensions: true,
86 allowAudioFiles: true,
109 maxInstanceLives: -1,
155 indexUrl: 'https://index.example.com'
162 message: 'super message',
172 url: 'https://search.joinpeertube.org',
173 disableLocalSearch: true,
174 isDefaultSearch: true
179 // ---------------------------------------------------------------
181 before(async function () {
184 server = await flushAndRunServer(1)
186 await setAccessTokensToServers([ server ])
192 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
193 userAccessToken = await userLogin(server, user)
196 describe('When getting the configuration', function () {
197 it('Should fail without token', async function () {
198 await makeGetRequest({
201 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
205 it('Should fail if the user is not an administrator', async function () {
206 await makeGetRequest({
209 token: userAccessToken,
210 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
215 describe('When updating the configuration', function () {
216 it('Should fail without token', async function () {
217 await makePutBodyRequest({
220 fields: updateParams,
221 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
225 it('Should fail if the user is not an administrator', async function () {
226 await makePutBodyRequest({
229 fields: updateParams,
230 token: userAccessToken,
231 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
235 it('Should fail if it misses a key', async function () {
236 const newUpdateParams = omit(updateParams, 'admin.email')
238 await makePutBodyRequest({
241 fields: newUpdateParams,
242 token: server.accessToken,
243 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
247 it('Should fail with a bad default NSFW policy', async function () {
248 const newUpdateParams = immutableAssign(updateParams, {
250 defaultNSFWPolicy: 'hello'
254 await makePutBodyRequest({
257 fields: newUpdateParams,
258 token: server.accessToken,
259 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
263 it('Should fail if email disabled and signup requires email verification', async function () {
264 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
265 const newUpdateParams = immutableAssign(updateParams, {
269 requiresEmailVerification: true
273 await makePutBodyRequest({
276 fields: newUpdateParams,
277 token: server.accessToken,
278 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
282 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
283 const newUpdateParams = immutableAssign(updateParams, {
294 await makePutBodyRequest({
297 fields: newUpdateParams,
298 token: server.accessToken,
299 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
303 it('Should success with the correct parameters', async function () {
304 await makePutBodyRequest({
307 fields: updateParams,
308 token: server.accessToken,
309 statusCodeExpected: HttpStatusCode.OK_200
314 describe('When deleting the configuration', function () {
315 it('Should fail without token', async function () {
316 await makeDeleteRequest({
319 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
323 it('Should fail if the user is not an administrator', async function () {
324 await makeDeleteRequest({
327 token: userAccessToken,
328 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
333 after(async function () {
334 await cleanupTests([ server ])