aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins/html-injection.ts
blob: 293c1df21d9845c0eb9a20370409524206f06e63 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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 ])
  })
})