PeerTube/server/tests/plugins/html-injection.ts

77 lines
2.1 KiB
TypeScript
Raw Normal View History

/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
import * as chai from 'chai'
import {
cleanupTests,
2021-07-16 02:47:51 -05:00
createSingleServer,
makeHTMLRequest,
2021-07-16 02:47:51 -05:00
PeerTubeServer,
2021-07-16 07:27:30 -05:00
PluginsCommand,
2021-07-07 03:33:49 -05:00
setAccessTokensToServers
} from '../../../shared/extra-utils'
const expect = chai.expect
2021-06-17 03:43:34 -05:00
describe('Test plugins HTML injection', function () {
2021-07-16 02:47:51 -05:00
let server: PeerTubeServer = null
2021-07-07 03:33:49 -05:00
let command: PluginsCommand
before(async function () {
this.timeout(30000)
2021-07-16 02:47:51 -05:00
server = await createSingleServer(1)
await setAccessTokensToServers([ server ])
2021-07-07 03:33:49 -05:00
2021-07-16 02:04:35 -05:00
command = server.plugins
})
it('Should not inject global css file in HTML', async function () {
{
2021-07-07 03:33:49 -05:00
const text = await command.getCSS()
expect(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)
2021-07-07 03:33:49 -05:00
await command.install({ npmName: 'peertube-plugin-hello-world' })
})
it('Should have the correct global css', async function () {
{
2021-07-07 03:33:49 -05:00
const text = await command.getCSS()
expect(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 () {
2021-07-07 03:33:49 -05:00
await command.uninstall({ npmName: 'peertube-plugin-hello-world' })
{
2021-07-07 03:33:49 -05:00
const text = await command.getCSS()
expect(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 ])
})
})