]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Move html injection plugin tests in its own file
authorChocobozzz <me@florianbigard.com>
Mon, 24 Aug 2020 11:37:49 +0000 (13:37 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 24 Aug 2020 11:37:49 +0000 (13:37 +0200)
server/tests/api/server/plugins.ts
server/tests/plugins/html-injection.ts [new file with mode: 0644]
server/tests/plugins/index.ts

index ad0a5139b6ee37f2c28e296d12c5e90e99ab109f..ecf7c0d3f7f1ec4a0a7200c1d252b267b5215788 100644 (file)
@@ -11,7 +11,6 @@ import {
   getPlugin,
   getPluginPackageJSON,
   getPluginRegisteredSettings,
-  getPluginsCSS,
   getPublicSettings,
   installPlugin,
   killallServers,
@@ -28,17 +27,16 @@ import {
   updatePluginPackageJSON,
   updatePluginSettings,
   wait,
-  waitUntilLog,
-  makeHTMLRequest
+  waitUntilLog
 } from '../../../../shared/extra-utils'
-import { PluginType } from '../../../../shared/models/plugins/plugin.type'
 import { PeerTubePluginIndex } from '../../../../shared/models/plugins/peertube-plugin-index.model'
-import { ServerConfig } from '../../../../shared/models/server'
 import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model'
-import { User } from '../../../../shared/models/users'
 import { PluginPackageJson } from '../../../../shared/models/plugins/plugin-package-json.model'
-import { RegisteredServerSettings } from '../../../../shared/models/plugins/register-server-setting.model'
+import { PluginType } from '../../../../shared/models/plugins/plugin.type'
 import { PublicServerSetting } from '../../../../shared/models/plugins/public-server.setting'
+import { RegisteredServerSettings } from '../../../../shared/models/plugins/register-server-setting.model'
+import { ServerConfig } from '../../../../shared/models/server'
+import { User } from '../../../../shared/models/users'
 
 const expect = chai.expect
 
@@ -119,18 +117,6 @@ describe('Test plugins', function () {
     }
   })
 
-  it('Should have an empty global css', async function () {
-    {
-      const res = await getPluginsCSS(server.url)
-      expect(res.text).to.be.empty
-    }
-
-    for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
-      const res = await makeHTMLRequest(server.url, path)
-      expect(res.text).to.not.include('link rel="stylesheet" href="/plugins/global.css')
-    }
-  })
-
   it('Should install a plugin and a theme', async function () {
     this.timeout(30000)
 
@@ -147,18 +133,6 @@ describe('Test plugins', function () {
     })
   })
 
-  it('Should have the correct global css', async function () {
-    {
-      const res = await getPluginsCSS(server.url)
-      expect(res.text).to.contain('background-color: red')
-    }
-
-    for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
-      const res = await makeHTMLRequest(server.url, path)
-      expect(res.text).to.include('link rel="stylesheet" href="/plugins/global.css')
-    }
-  })
-
   it('Should have the plugin loaded in the configuration', async function () {
     const res = await getConfig(server.url)
     const config: ServerConfig = res.body
@@ -400,18 +374,6 @@ describe('Test plugins', function () {
     expect(res.body.data).to.have.lengthOf(0)
   })
 
-  it('Should have an empty global css', async function () {
-    {
-      const res = await getPluginsCSS(server.url)
-      expect(res.text).to.be.empty
-    }
-
-    for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
-      const res = await makeHTMLRequest(server.url, path)
-      expect(res.text).to.not.include('link rel="stylesheet" href="/plugins/global.css')
-    }
-  })
-
   it('Should list uninstalled plugins', async function () {
     const res = await listPlugins({
       url: server.url,
diff --git a/server/tests/plugins/html-injection.ts b/server/tests/plugins/html-injection.ts
new file mode 100644 (file)
index 0000000..293c1df
--- /dev/null
@@ -0,0 +1,83 @@
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
+
+import 'mocha'
+import * as chai from 'chai'
+import {
+  cleanupTests,
+  flushAndRunServer,
+  getPluginsCSS,
+  installPlugin,
+  makeHTMLRequest,
+  ServerInfo,
+  setAccessTokensToServers,
+  uninstallPlugin
+} from '../../../shared/extra-utils'
+
+const expect = chai.expect
+
+describe('Test plugins HTML inection', function () {
+  let server: ServerInfo = null
+
+  before(async function () {
+    this.timeout(30000)
+
+    server = await flushAndRunServer(1)
+    await setAccessTokensToServers([ server ])
+  })
+
+  it('Should not inject global css file in HTML', async function () {
+    {
+      const res = await getPluginsCSS(server.url)
+      expect(res.text).to.be.empty
+    }
+
+    for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
+      const res = await makeHTMLRequest(server.url, path)
+      expect(res.text).to.not.include('link rel="stylesheet" href="/plugins/global.css')
+    }
+  })
+
+  it('Should install a plugin and a theme', async function () {
+    this.timeout(30000)
+
+    await installPlugin({
+      url: server.url,
+      accessToken: server.accessToken,
+      npmName: 'peertube-plugin-hello-world'
+    })
+  })
+
+  it('Should have the correct global css', async function () {
+    {
+      const res = await getPluginsCSS(server.url)
+      expect(res.text).to.contain('background-color: red')
+    }
+
+    for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
+      const res = await makeHTMLRequest(server.url, path)
+      expect(res.text).to.include('link rel="stylesheet" href="/plugins/global.css')
+    }
+  })
+
+  it('Should have an empty global css on uninstall', async function () {
+    await uninstallPlugin({
+      url: server.url,
+      accessToken: server.accessToken,
+      npmName: 'peertube-plugin-hello-world'
+    })
+
+    {
+      const res = await getPluginsCSS(server.url)
+      expect(res.text).to.be.empty
+    }
+
+    for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
+      const res = await makeHTMLRequest(server.url, path)
+      expect(res.text).to.not.include('link rel="stylesheet" href="/plugins/global.css')
+    }
+  })
+
+  after(async function () {
+    await cleanupTests([ server ])
+  })
+})
index 39c4c958aa78803868f898c4d4f482c644570b56..b870a4055fb1ea1d54dac5b6626a0d1e58982c34 100644 (file)
@@ -1,4 +1,5 @@
 import './action-hooks'
+import './html-injection'
 import './id-and-pass-auth'
 import './external-auth'
 import './filter-hooks'