2020-06-25 04:32:17 -04:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
import { expect } from 'chai'
|
|
|
|
import {
|
|
|
|
cleanupTests,
|
2021-07-16 03:47:51 -04:00
|
|
|
createMultipleServers,
|
2021-07-16 08:27:30 -04:00
|
|
|
doubleFollow,
|
2020-06-25 04:32:17 -04:00
|
|
|
killallServers,
|
2021-07-15 04:02:54 -04:00
|
|
|
MockBlocklist,
|
2021-07-16 03:47:51 -04:00
|
|
|
PeerTubeServer,
|
2021-07-15 04:02:54 -04:00
|
|
|
setAccessTokensToServers,
|
|
|
|
wait
|
|
|
|
} from '@shared/extra-utils'
|
|
|
|
import { Video } from '@shared/models'
|
2020-06-25 04:32:17 -04:00
|
|
|
|
2021-07-16 03:47:51 -04:00
|
|
|
async function check (server: PeerTubeServer, videoUUID: string, exists = true) {
|
2021-07-16 03:04:35 -04:00
|
|
|
const { data } = await server.videos.list()
|
2020-06-25 04:32:17 -04:00
|
|
|
|
2021-07-15 04:02:54 -04:00
|
|
|
const video = data.find(v => v.uuid === videoUUID)
|
2020-06-25 04:32:17 -04:00
|
|
|
|
2021-07-07 04:33:49 -04:00
|
|
|
if (exists) expect(video).to.not.be.undefined
|
|
|
|
else expect(video).to.be.undefined
|
2020-06-25 04:32:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('Official plugin auto-block videos', function () {
|
2021-07-16 03:47:51 -04:00
|
|
|
let servers: PeerTubeServer[]
|
2020-06-25 04:32:17 -04:00
|
|
|
let blocklistServer: MockBlocklist
|
|
|
|
let server1Videos: Video[] = []
|
|
|
|
let server2Videos: Video[] = []
|
2021-06-03 03:06:51 -04:00
|
|
|
let port: number
|
2020-06-25 04:32:17 -04:00
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
2021-07-16 03:47:51 -04:00
|
|
|
servers = await createMultipleServers(2)
|
2020-06-25 04:32:17 -04:00
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-07-16 03:04:35 -04:00
|
|
|
await server.plugins.install({ npmName: 'peertube-plugin-auto-block-videos' })
|
2020-06-25 04:32:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
blocklistServer = new MockBlocklist()
|
2021-06-03 03:06:51 -04:00
|
|
|
port = await blocklistServer.initialize()
|
2020-06-25 04:32:17 -04:00
|
|
|
|
2021-07-16 04:42:24 -04:00
|
|
|
await servers[0].videos.quickUpload({ name: 'video server 1' })
|
|
|
|
await servers[1].videos.quickUpload({ name: 'video server 2' })
|
|
|
|
await servers[1].videos.quickUpload({ name: 'video 2 server 2' })
|
|
|
|
await servers[1].videos.quickUpload({ name: 'video 3 server 2' })
|
2020-06-25 04:32:17 -04:00
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const { data } = await servers[0].videos.list()
|
2021-07-15 04:02:54 -04:00
|
|
|
server1Videos = data.map(v => Object.assign(v, { url: servers[0].url + '/videos/watch/' + v.uuid }))
|
2020-06-25 04:32:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const { data } = await servers[1].videos.list()
|
2021-07-15 04:02:54 -04:00
|
|
|
server2Videos = data.map(v => Object.assign(v, { url: servers[1].url + '/videos/watch/' + v.uuid }))
|
2020-06-25 04:32:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should update plugin settings', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].plugins.updateSettings({
|
2020-06-25 04:32:17 -04:00
|
|
|
npmName: 'peertube-plugin-auto-block-videos',
|
|
|
|
settings: {
|
2021-06-03 03:06:51 -04:00
|
|
|
'blocklist-urls': `http://localhost:${port}/blocklist`,
|
2020-06-25 04:32:17 -04:00
|
|
|
'check-seconds-interval': 1
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should auto block a video', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
await check(servers[0], server2Videos[0].uuid, true)
|
|
|
|
|
|
|
|
blocklistServer.replace({
|
|
|
|
data: [
|
|
|
|
{
|
|
|
|
value: server2Videos[0].url
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
await wait(2000)
|
|
|
|
|
|
|
|
await check(servers[0], server2Videos[0].uuid, false)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have video in blacklists', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
const body = await servers[0].blacklist.list()
|
2020-06-25 04:32:17 -04:00
|
|
|
|
2021-07-08 05:17:55 -04:00
|
|
|
const videoBlacklists = body.data
|
2020-06-25 04:32:17 -04:00
|
|
|
expect(videoBlacklists).to.have.lengthOf(1)
|
|
|
|
expect(videoBlacklists[0].reason).to.contains('Automatically blocked from auto block plugin')
|
|
|
|
expect(videoBlacklists[0].video.name).to.equal(server2Videos[0].name)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not block a local video', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
await check(servers[0], server1Videos[0].uuid, true)
|
|
|
|
|
|
|
|
blocklistServer.replace({
|
|
|
|
data: [
|
|
|
|
{
|
|
|
|
value: server1Videos[0].url
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
await wait(2000)
|
|
|
|
|
|
|
|
await check(servers[0], server1Videos[0].uuid, true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should remove a video block', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
await check(servers[0], server2Videos[0].uuid, false)
|
|
|
|
|
|
|
|
blocklistServer.replace({
|
|
|
|
data: [
|
|
|
|
{
|
|
|
|
value: server2Videos[0].url,
|
|
|
|
action: 'remove'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
await wait(2000)
|
|
|
|
|
|
|
|
await check(servers[0], server2Videos[0].uuid, true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should auto block a video, manually unblock it and do not reblock it automatically', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
const video = server2Videos[1]
|
|
|
|
|
|
|
|
await check(servers[0], video.uuid, true)
|
|
|
|
|
|
|
|
blocklistServer.replace({
|
|
|
|
data: [
|
|
|
|
{
|
|
|
|
value: video.url,
|
|
|
|
updatedAt: new Date().toISOString()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
await wait(2000)
|
|
|
|
|
|
|
|
await check(servers[0], video.uuid, false)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].blacklist.remove({ videoId: video.uuid })
|
2020-06-25 04:32:17 -04:00
|
|
|
|
|
|
|
await check(servers[0], video.uuid, true)
|
|
|
|
|
2021-07-09 09:37:43 -04:00
|
|
|
await killallServers([ servers[0] ])
|
2021-07-16 03:47:51 -04:00
|
|
|
await servers[0].run()
|
2020-06-25 04:32:17 -04:00
|
|
|
await wait(2000)
|
|
|
|
|
|
|
|
await check(servers[0], video.uuid, true)
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
2020-06-26 08:50:40 -04:00
|
|
|
await blocklistServer.terminate()
|
|
|
|
|
2020-06-25 04:32:17 -04:00
|
|
|
await cleanupTests(servers)
|
|
|
|
})
|
|
|
|
})
|