From eebd9838f067369031af9770b899f75f30810549 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Mar 2021 17:18:18 +0100 Subject: Add filter hook to forbid embed access --- server/tests/fixtures/peertube-plugin-test/main.js | 20 ++++++++ server/tests/plugins/filter-hooks.ts | 54 +++++++++++++++++++++- 2 files changed, 72 insertions(+), 2 deletions(-) (limited to 'server/tests') diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js index 9913d0846..dfcc874d4 100644 --- a/server/tests/fixtures/peertube-plugin-test/main.js +++ b/server/tests/fixtures/peertube-plugin-test/main.js @@ -210,6 +210,26 @@ async function register ({ registerHook, registerSetting, settingsManager, stora return result } }) + + registerHook({ + target: 'filter:html.embed.video.allowed.result', + handler: (result, params) => { + return { + allowed: false, + html: 'Lu Bu' + } + } + }) + + registerHook({ + target: 'filter:html.embed.video-playlist.allowed.result', + handler: (result, params) => { + return { + allowed: false, + html: 'Diao Chan' + } + } + }) } async function unregister () { diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 6996ae788..be47b20ba 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -3,10 +3,12 @@ import 'mocha' import * as chai from 'chai' import { ServerConfig } from '@shared/models' +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' import { addVideoCommentReply, addVideoCommentThread, createLive, + createVideoPlaylist, doubleFollow, getAccountVideos, getConfig, @@ -15,6 +17,7 @@ import { getVideo, getVideoChannelVideos, getVideoCommentThreads, + getVideoPlaylist, getVideosList, getVideosListPagination, getVideoThreadComments, @@ -32,9 +35,15 @@ import { } from '../../../shared/extra-utils' import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers' import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports' -import { VideoDetails, VideoImport, VideoImportState, VideoPrivacy } from '../../../shared/models/videos' +import { + VideoDetails, + VideoImport, + VideoImportState, + VideoPlaylist, + VideoPlaylistPrivacy, + VideoPrivacy +} from '../../../shared/models/videos' import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -418,6 +427,47 @@ describe('Test plugin filter hooks', function () { }) }) + describe('Embed filters', function () { + const embedVideos: VideoDetails[] = [] + const embedPlaylists: VideoPlaylist[] = [] + + before(async function () { + this.timeout(60000) + + await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { + transcoding: { + enabled: false + } + }) + + for (const name of [ 'bad embed', 'good embed' ]) { + { + const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid + const res = await getVideo(servers[0].url, uuid) + embedVideos.push(res.body) + } + + { + const playlistAttrs = { displayName: name, videoChannelId: servers[0].videoChannel.id, privacy: VideoPlaylistPrivacy.PUBLIC } + const res = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs }) + + const resPlaylist = await getVideoPlaylist(servers[0].url, res.body.videoPlaylist.id) + embedPlaylists.push(resPlaylist.body) + } + } + }) + + it('Should run filter:html.embed.video.allowed.result', async function () { + const res = await makeRawRequest(servers[0].url + embedVideos[0].embedPath, 200) + expect(res.text).to.equal('Lu Bu') + }) + + it('Should run filter:html.embed.video-playlist.allowed.result', async function () { + const res = await makeRawRequest(servers[0].url + embedPlaylists[0].embedPath, 200) + expect(res.text).to.equal('Diao Chan') + }) + }) + after(async function () { await cleanupTests(servers) }) -- cgit v1.2.3