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'
20 describe('Test config API validators', function () {
21 const path = '/api/v1/config/custom'
22 let server: ServerInfo
23 let userAccessToken: string
24 const updateParams: CustomConfig = {
26 name: 'PeerTube updated',
27 shortDescription: 'my short description',
28 description: 'my super description',
29 terms: 'my super terms',
30 codeOfConduct: 'my super coc',
32 creationReason: 'my super reason',
33 moderationInformation: 'my super moderation information',
34 administrator: 'Kuja',
35 maintenanceLifetime: 'forever',
36 businessModel: 'my super business model',
37 hardwareInformation: '2vCore 3GB RAM',
39 languages: [ 'en', 'es' ],
43 defaultClientRoute: '/videos/recently-added',
44 defaultNSFWPolicy: 'blur',
46 javascript: 'alert("coucou")',
47 css: 'body { background-color: red; }'
55 username: '@MySuperUsername',
70 requiresEmailVerification: false
73 email: 'superadmin1@example.com'
80 videoQuotaDaily: 318742
84 allowAdditionalExtensions: true,
85 allowAudioFiles: true,
133 indexUrl: 'https://index.example.com'
140 message: 'super message',
145 // ---------------------------------------------------------------
147 before(async function () {
150 server = await flushAndRunServer(1)
152 await setAccessTokensToServers([ server ])
158 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
159 userAccessToken = await userLogin(server, user)
162 describe('When getting the configuration', function () {
163 it('Should fail without token', async function () {
164 await makeGetRequest({
167 statusCodeExpected: 401
171 it('Should fail if the user is not an administrator', async function () {
172 await makeGetRequest({
175 token: userAccessToken,
176 statusCodeExpected: 403
181 describe('When updating the configuration', function () {
182 it('Should fail without token', async function () {
183 await makePutBodyRequest({
186 fields: updateParams,
187 statusCodeExpected: 401
191 it('Should fail if the user is not an administrator', async function () {
192 await makePutBodyRequest({
195 fields: updateParams,
196 token: userAccessToken,
197 statusCodeExpected: 403
201 it('Should fail if it misses a key', async function () {
202 const newUpdateParams = omit(updateParams, 'admin.email')
204 await makePutBodyRequest({
207 fields: newUpdateParams,
208 token: server.accessToken,
209 statusCodeExpected: 400
213 it('Should fail with a bad default NSFW policy', async function () {
214 const newUpdateParams = immutableAssign(updateParams, {
216 defaultNSFWPolicy: 'hello'
220 await makePutBodyRequest({
223 fields: newUpdateParams,
224 token: server.accessToken,
225 statusCodeExpected: 400
229 it('Should fail if email disabled and signup requires email verification', async function () {
230 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
231 const newUpdateParams = immutableAssign(updateParams, {
235 requiresEmailVerification: true
239 await makePutBodyRequest({
242 fields: newUpdateParams,
243 token: server.accessToken,
244 statusCodeExpected: 400
248 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
249 const newUpdateParams = immutableAssign(updateParams, {
260 await makePutBodyRequest({
263 fields: newUpdateParams,
264 token: server.accessToken,
265 statusCodeExpected: 400
269 it('Should success with the correct parameters', async function () {
270 await makePutBodyRequest({
273 fields: updateParams,
274 token: server.accessToken,
275 statusCodeExpected: 200
280 describe('When deleting the configuration', function () {
281 it('Should fail without token', async function () {
282 await makeDeleteRequest({
285 statusCodeExpected: 401
289 it('Should fail if the user is not an administrator', async function () {
290 await makeDeleteRequest({
293 token: userAccessToken,
294 statusCodeExpected: 403
299 after(async function () {
300 await cleanupTests([ server ])