]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/config.ts
Introduce server commands
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / config.ts
index 26df8373e3f27e9d8e29933b301c2988b0194b82..55cf2a1b86fe684729027051b8c825cd016dc8b7 100644 (file)
@@ -2,26 +2,20 @@
 
 import 'mocha'
 import * as chai from 'chai'
-import { About } from '../../../../shared/models/server/about.model'
-import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
+import { HttpStatusCode } from '@shared/core-utils'
 import {
   cleanupTests,
-  deleteCustomConfig,
   flushAndRunServer,
-  getAbout,
-  getConfig,
-  getCustomConfig,
   killallServers,
+  makeGetRequest,
   parallelTests,
   registerUser,
   reRunServer,
   ServerInfo,
   setAccessTokensToServers,
-  updateCustomConfig,
   uploadVideo
-} from '../../../../shared/extra-utils'
-import { ServerConfig } from '../../../../shared/models'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+} from '@shared/extra-utils'
+import { CustomConfig } from '@shared/models'
 
 const expect = chai.expect
 
@@ -55,9 +49,11 @@ function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
 
   expect(data.cache.previews.size).to.equal(1)
   expect(data.cache.captions.size).to.equal(1)
+  expect(data.cache.torrents.size).to.equal(1)
 
   expect(data.signup.enabled).to.be.true
   expect(data.signup.limit).to.equal(4)
+  expect(data.signup.minimumAge).to.equal(16)
   expect(data.signup.requiresEmailVerification).to.be.false
 
   expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
@@ -70,6 +66,7 @@ function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
   expect(data.transcoding.allowAdditionalExtensions).to.be.false
   expect(data.transcoding.allowAudioFiles).to.be.false
   expect(data.transcoding.threads).to.equal(2)
+  expect(data.transcoding.concurrency).to.equal(2)
   expect(data.transcoding.profile).to.equal('default')
   expect(data.transcoding.resolutions['240p']).to.be.true
   expect(data.transcoding.resolutions['360p']).to.be.true
@@ -97,6 +94,7 @@ function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
   expect(data.live.transcoding.resolutions['1440p']).to.be.false
   expect(data.live.transcoding.resolutions['2160p']).to.be.false
 
+  expect(data.import.videos.concurrency).to.equal(2)
   expect(data.import.videos.http.enabled).to.be.true
   expect(data.import.videos.torrent.enabled).to.be.true
   expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
@@ -142,10 +140,12 @@ function checkUpdatedConfig (data: CustomConfig) {
 
   expect(data.cache.previews.size).to.equal(2)
   expect(data.cache.captions.size).to.equal(3)
+  expect(data.cache.torrents.size).to.equal(4)
 
   expect(data.signup.enabled).to.be.false
   expect(data.signup.limit).to.equal(5)
   expect(data.signup.requiresEmailVerification).to.be.false
+  expect(data.signup.minimumAge).to.equal(10)
 
   // We override admin email in parallel tests, so skip this exception
   if (parallelTests() === false) {
@@ -159,6 +159,7 @@ function checkUpdatedConfig (data: CustomConfig) {
 
   expect(data.transcoding.enabled).to.be.true
   expect(data.transcoding.threads).to.equal(1)
+  expect(data.transcoding.concurrency).to.equal(3)
   expect(data.transcoding.allowAdditionalExtensions).to.be.true
   expect(data.transcoding.allowAudioFiles).to.be.true
   expect(data.transcoding.profile).to.equal('vod_profile')
@@ -186,6 +187,7 @@ function checkUpdatedConfig (data: CustomConfig) {
   expect(data.live.transcoding.resolutions['1080p']).to.be.true
   expect(data.live.transcoding.resolutions['2160p']).to.be.true
 
+  expect(data.import.videos.concurrency).to.equal(4)
   expect(data.import.videos.http.enabled).to.be.false
   expect(data.import.videos.torrent.enabled).to.be.false
   expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
@@ -204,7 +206,7 @@ function checkUpdatedConfig (data: CustomConfig) {
 }
 
 describe('Test config', function () {
-  let server = null
+  let server: ServerInfo = null
 
   before(async function () {
     this.timeout(30000)
@@ -214,8 +216,7 @@ describe('Test config', function () {
   })
 
   it('Should have a correct config on a server with registration enabled', async function () {
-    const res = await getConfig(server.url)
-    const data: ServerConfig = res.body
+    const data = await server.configCommand.getConfig()
 
     expect(data.signup.allowed).to.be.true
   })
@@ -229,15 +230,13 @@ describe('Test config', function () {
       registerUser(server.url, 'user3', 'super password')
     ])
 
-    const res = await getConfig(server.url)
-    const data: ServerConfig = res.body
+    const data = await server.configCommand.getConfig()
 
     expect(data.signup.allowed).to.be.false
   })
 
   it('Should have the correct video allowed extensions', async function () {
-    const res = await getConfig(server.url)
-    const data: ServerConfig = res.body
+    const data = await server.configCommand.getConfig()
 
     expect(data.video.file.extensions).to.have.lengthOf(3)
     expect(data.video.file.extensions).to.contain('.mp4')
@@ -251,8 +250,7 @@ describe('Test config', function () {
   })
 
   it('Should get the customized configuration', async function () {
-    const res = await getCustomConfig(server.url, server.accessToken)
-    const data = res.body as CustomConfig
+    const data = await server.configCommand.getCustomConfig()
 
     checkInitialConfig(server, data)
   })
@@ -301,12 +299,16 @@ describe('Test config', function () {
         },
         captions: {
           size: 3
+        },
+        torrents: {
+          size: 4
         }
       },
       signup: {
         enabled: false,
         limit: 5,
-        requiresEmailVerification: false
+        requiresEmailVerification: false,
+        minimumAge: 10
       },
       admin: {
         email: 'superadmin1@example.com'
@@ -323,6 +325,7 @@ describe('Test config', function () {
         allowAdditionalExtensions: true,
         allowAudioFiles: true,
         threads: 1,
+        concurrency: 3,
         profile: 'vod_profile',
         resolutions: {
           '0p': false,
@@ -364,6 +367,7 @@ describe('Test config', function () {
       },
       import: {
         videos: {
+          concurrency: 4,
           http: {
             enabled: false
           },
@@ -423,19 +427,16 @@ describe('Test config', function () {
         }
       }
     }
-    await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
-
-    const res = await getCustomConfig(server.url, server.accessToken)
-    const data = res.body
+    await server.configCommand.updateCustomConfig({ newCustomConfig })
 
+    const data = await server.configCommand.getCustomConfig()
     checkUpdatedConfig(data)
   })
 
   it('Should have the correct updated video allowed extensions', async function () {
     this.timeout(10000)
 
-    const res = await getConfig(server.url)
-    const data: ServerConfig = res.body
+    const data = await server.configCommand.getConfig()
 
     expect(data.video.file.extensions).to.have.length.above(4)
     expect(data.video.file.extensions).to.contain('.mp4')
@@ -455,19 +456,17 @@ describe('Test config', function () {
   it('Should have the configuration updated after a restart', async function () {
     this.timeout(10000)
 
-    killallServers([ server ])
+    await killallServers([ server ])
 
     await reRunServer(server)
 
-    const res = await getCustomConfig(server.url, server.accessToken)
-    const data = res.body
+    const data = await server.configCommand.getCustomConfig()
 
     checkUpdatedConfig(data)
   })
 
   it('Should fetch the about information', async function () {
-    const res = await getAbout(server.url)
-    const data: About = res.body
+    const data = await server.configCommand.getAbout()
 
     expect(data.instance.name).to.equal('PeerTube updated')
     expect(data.instance.shortDescription).to.equal('my short description')
@@ -489,14 +488,45 @@ describe('Test config', function () {
   it('Should remove the custom configuration', async function () {
     this.timeout(10000)
 
-    await deleteCustomConfig(server.url, server.accessToken)
-
-    const res = await getCustomConfig(server.url, server.accessToken)
-    const data = res.body
+    await server.configCommand.deleteCustomConfig()
 
+    const data = await server.configCommand.getCustomConfig()
     checkInitialConfig(server, data)
   })
 
+  it('Should enable frameguard', async function () {
+    this.timeout(25000)
+
+    {
+      const res = await makeGetRequest({
+        url: server.url,
+        path: '/api/v1/config',
+        statusCodeExpected: 200
+      })
+
+      expect(res.headers['x-frame-options']).to.exist
+    }
+
+    await killallServers([ server ])
+
+    const config = {
+      security: {
+        frameguard: { enabled: false }
+      }
+    }
+    server = await reRunServer(server, config)
+
+    {
+      const res = await makeGetRequest({
+        url: server.url,
+        path: '/api/v1/config',
+        statusCodeExpected: 200
+      })
+
+      expect(res.headers['x-frame-options']).to.not.exist
+    }
+  })
+
   after(async function () {
     await cleanupTests([ server ])
   })