From 1f5221fb4a511bb175083a9c7f578679c6122ce3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 24 Aug 2020 13:37:49 +0200 Subject: Move html injection plugin tests in its own file --- server/tests/plugins/html-injection.ts | 83 ++++++++++++++++++++++++++++++++++ server/tests/plugins/index.ts | 1 + 2 files changed, 84 insertions(+) create mode 100644 server/tests/plugins/html-injection.ts (limited to 'server/tests/plugins') diff --git a/server/tests/plugins/html-injection.ts b/server/tests/plugins/html-injection.ts new file mode 100644 index 000000000..293c1df21 --- /dev/null +++ b/server/tests/plugins/html-injection.ts @@ -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 ]) + }) +}) diff --git a/server/tests/plugins/index.ts b/server/tests/plugins/index.ts index 39c4c958a..b870a4055 100644 --- a/server/tests/plugins/index.ts +++ b/server/tests/plugins/index.ts @@ -1,4 +1,5 @@ import './action-hooks' +import './html-injection' import './id-and-pass-auth' import './external-auth' import './filter-hooks' -- cgit v1.2.3