aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/server/plugins.ts48
-rw-r--r--server/tests/plugins/html-injection.ts83
-rw-r--r--server/tests/plugins/index.ts1
3 files changed, 89 insertions, 43 deletions
diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts
index ad0a5139b..ecf7c0d3f 100644
--- a/server/tests/api/server/plugins.ts
+++ b/server/tests/api/server/plugins.ts
@@ -11,7 +11,6 @@ import {
11 getPlugin, 11 getPlugin,
12 getPluginPackageJSON, 12 getPluginPackageJSON,
13 getPluginRegisteredSettings, 13 getPluginRegisteredSettings,
14 getPluginsCSS,
15 getPublicSettings, 14 getPublicSettings,
16 installPlugin, 15 installPlugin,
17 killallServers, 16 killallServers,
@@ -28,17 +27,16 @@ import {
28 updatePluginPackageJSON, 27 updatePluginPackageJSON,
29 updatePluginSettings, 28 updatePluginSettings,
30 wait, 29 wait,
31 waitUntilLog, 30 waitUntilLog
32 makeHTMLRequest
33} from '../../../../shared/extra-utils' 31} from '../../../../shared/extra-utils'
34import { PluginType } from '../../../../shared/models/plugins/plugin.type'
35import { PeerTubePluginIndex } from '../../../../shared/models/plugins/peertube-plugin-index.model' 32import { PeerTubePluginIndex } from '../../../../shared/models/plugins/peertube-plugin-index.model'
36import { ServerConfig } from '../../../../shared/models/server'
37import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model' 33import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model'
38import { User } from '../../../../shared/models/users'
39import { PluginPackageJson } from '../../../../shared/models/plugins/plugin-package-json.model' 34import { PluginPackageJson } from '../../../../shared/models/plugins/plugin-package-json.model'
40import { RegisteredServerSettings } from '../../../../shared/models/plugins/register-server-setting.model' 35import { PluginType } from '../../../../shared/models/plugins/plugin.type'
41import { PublicServerSetting } from '../../../../shared/models/plugins/public-server.setting' 36import { PublicServerSetting } from '../../../../shared/models/plugins/public-server.setting'
37import { RegisteredServerSettings } from '../../../../shared/models/plugins/register-server-setting.model'
38import { ServerConfig } from '../../../../shared/models/server'
39import { User } from '../../../../shared/models/users'
42 40
43const expect = chai.expect 41const expect = chai.expect
44 42
@@ -119,18 +117,6 @@ describe('Test plugins', function () {
119 } 117 }
120 }) 118 })
121 119
122 it('Should have an empty global css', async function () {
123 {
124 const res = await getPluginsCSS(server.url)
125 expect(res.text).to.be.empty
126 }
127
128 for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
129 const res = await makeHTMLRequest(server.url, path)
130 expect(res.text).to.not.include('link rel="stylesheet" href="/plugins/global.css')
131 }
132 })
133
134 it('Should install a plugin and a theme', async function () { 120 it('Should install a plugin and a theme', async function () {
135 this.timeout(30000) 121 this.timeout(30000)
136 122
@@ -147,18 +133,6 @@ describe('Test plugins', function () {
147 }) 133 })
148 }) 134 })
149 135
150 it('Should have the correct global css', async function () {
151 {
152 const res = await getPluginsCSS(server.url)
153 expect(res.text).to.contain('background-color: red')
154 }
155
156 for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
157 const res = await makeHTMLRequest(server.url, path)
158 expect(res.text).to.include('link rel="stylesheet" href="/plugins/global.css')
159 }
160 })
161
162 it('Should have the plugin loaded in the configuration', async function () { 136 it('Should have the plugin loaded in the configuration', async function () {
163 const res = await getConfig(server.url) 137 const res = await getConfig(server.url)
164 const config: ServerConfig = res.body 138 const config: ServerConfig = res.body
@@ -400,18 +374,6 @@ describe('Test plugins', function () {
400 expect(res.body.data).to.have.lengthOf(0) 374 expect(res.body.data).to.have.lengthOf(0)
401 }) 375 })
402 376
403 it('Should have an empty global css', async function () {
404 {
405 const res = await getPluginsCSS(server.url)
406 expect(res.text).to.be.empty
407 }
408
409 for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
410 const res = await makeHTMLRequest(server.url, path)
411 expect(res.text).to.not.include('link rel="stylesheet" href="/plugins/global.css')
412 }
413 })
414
415 it('Should list uninstalled plugins', async function () { 377 it('Should list uninstalled plugins', async function () {
416 const res = await listPlugins({ 378 const res = await listPlugins({
417 url: server.url, 379 url: server.url,
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 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import {
6 cleanupTests,
7 flushAndRunServer,
8 getPluginsCSS,
9 installPlugin,
10 makeHTMLRequest,
11 ServerInfo,
12 setAccessTokensToServers,
13 uninstallPlugin
14} from '../../../shared/extra-utils'
15
16const expect = chai.expect
17
18describe('Test plugins HTML inection', function () {
19 let server: ServerInfo = null
20
21 before(async function () {
22 this.timeout(30000)
23
24 server = await flushAndRunServer(1)
25 await setAccessTokensToServers([ server ])
26 })
27
28 it('Should not inject global css file in HTML', async function () {
29 {
30 const res = await getPluginsCSS(server.url)
31 expect(res.text).to.be.empty
32 }
33
34 for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
35 const res = await makeHTMLRequest(server.url, path)
36 expect(res.text).to.not.include('link rel="stylesheet" href="/plugins/global.css')
37 }
38 })
39
40 it('Should install a plugin and a theme', async function () {
41 this.timeout(30000)
42
43 await installPlugin({
44 url: server.url,
45 accessToken: server.accessToken,
46 npmName: 'peertube-plugin-hello-world'
47 })
48 })
49
50 it('Should have the correct global css', async function () {
51 {
52 const res = await getPluginsCSS(server.url)
53 expect(res.text).to.contain('background-color: red')
54 }
55
56 for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
57 const res = await makeHTMLRequest(server.url, path)
58 expect(res.text).to.include('link rel="stylesheet" href="/plugins/global.css')
59 }
60 })
61
62 it('Should have an empty global css on uninstall', async function () {
63 await uninstallPlugin({
64 url: server.url,
65 accessToken: server.accessToken,
66 npmName: 'peertube-plugin-hello-world'
67 })
68
69 {
70 const res = await getPluginsCSS(server.url)
71 expect(res.text).to.be.empty
72 }
73
74 for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
75 const res = await makeHTMLRequest(server.url, path)
76 expect(res.text).to.not.include('link rel="stylesheet" href="/plugins/global.css')
77 }
78 })
79
80 after(async function () {
81 await cleanupTests([ server ])
82 })
83})
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 @@
1import './action-hooks' 1import './action-hooks'
2import './html-injection'
2import './id-and-pass-auth' 3import './id-and-pass-auth'
3import './external-auth' 4import './external-auth'
4import './filter-hooks' 5import './filter-hooks'