2020-05-07 14:32:54 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
import { expect } from 'chai'
|
2021-07-07 08:33:49 +00:00
|
|
|
import { HttpStatusCode } from '@shared/core-utils'
|
2020-05-11 08:15:44 +00:00
|
|
|
import {
|
2021-07-07 08:33:49 +00:00
|
|
|
cleanupTests,
|
2020-05-07 15:08:16 +00:00
|
|
|
doubleFollow,
|
2021-07-07 08:33:49 +00:00
|
|
|
flushAndRunMultipleServers,
|
2020-05-07 15:08:16 +00:00
|
|
|
getVideosList,
|
2021-07-07 08:33:49 +00:00
|
|
|
killallServers,
|
2020-05-11 08:15:44 +00:00
|
|
|
makeGetRequest,
|
2020-05-07 15:08:16 +00:00
|
|
|
MockBlocklist,
|
2021-07-07 08:33:49 +00:00
|
|
|
reRunServer,
|
|
|
|
ServerInfo,
|
2020-05-07 15:08:16 +00:00
|
|
|
setAccessTokensToServers,
|
|
|
|
uploadVideoAndGetId,
|
|
|
|
wait
|
2021-07-07 08:33:49 +00:00
|
|
|
} from '@shared/extra-utils'
|
2020-05-07 14:32:54 +00:00
|
|
|
|
|
|
|
describe('Official plugin auto-mute', function () {
|
2020-05-11 08:15:44 +00:00
|
|
|
const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
|
2020-05-07 14:32:54 +00:00
|
|
|
let servers: ServerInfo[]
|
|
|
|
let blocklistServer: MockBlocklist
|
2021-06-03 07:06:51 +00:00
|
|
|
let port: number
|
2020-05-07 14:32:54 +00:00
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
servers = await flushAndRunMultipleServers(2)
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
2020-05-11 08:15:44 +00:00
|
|
|
for (const server of servers) {
|
2021-07-07 08:33:49 +00:00
|
|
|
await server.pluginsCommand.install({ npmName: 'peertube-plugin-auto-mute' })
|
2020-05-11 08:15:44 +00:00
|
|
|
}
|
2020-05-07 14:32:54 +00:00
|
|
|
|
|
|
|
blocklistServer = new MockBlocklist()
|
2021-06-03 07:06:51 +00:00
|
|
|
port = await blocklistServer.initialize()
|
2020-05-07 14:32:54 +00:00
|
|
|
|
|
|
|
await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
|
|
|
|
await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
|
|
|
|
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should update plugin settings', async function () {
|
2021-07-07 08:33:49 +00:00
|
|
|
await servers[0].pluginsCommand.updateSettings({
|
2020-05-07 14:32:54 +00:00
|
|
|
npmName: 'peertube-plugin-auto-mute',
|
|
|
|
settings: {
|
2021-06-03 07:06:51 +00:00
|
|
|
'blocklist-urls': `http://localhost:${port}/blocklist`,
|
2020-05-07 14:32:54 +00:00
|
|
|
'check-seconds-interval': 1
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should add a server blocklist', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
blocklistServer.replace({
|
|
|
|
data: [
|
|
|
|
{
|
|
|
|
value: 'localhost:' + servers[1].port
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
await wait(2000)
|
|
|
|
|
|
|
|
const res = await getVideosList(servers[0].url)
|
|
|
|
expect(res.body.total).to.equal(1)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should remove a server blocklist', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
blocklistServer.replace({
|
|
|
|
data: [
|
|
|
|
{
|
|
|
|
value: 'localhost:' + servers[1].port,
|
|
|
|
action: 'remove'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
await wait(2000)
|
|
|
|
|
|
|
|
const res = await getVideosList(servers[0].url)
|
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should add an account blocklist', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
blocklistServer.replace({
|
|
|
|
data: [
|
|
|
|
{
|
|
|
|
value: 'root@localhost:' + servers[1].port
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
await wait(2000)
|
|
|
|
|
|
|
|
const res = await getVideosList(servers[0].url)
|
|
|
|
expect(res.body.total).to.equal(1)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should remove an account blocklist', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
blocklistServer.replace({
|
|
|
|
data: [
|
|
|
|
{
|
|
|
|
value: 'root@localhost:' + servers[1].port,
|
|
|
|
action: 'remove'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
await wait(2000)
|
|
|
|
|
|
|
|
const res = await getVideosList(servers[0].url)
|
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
})
|
|
|
|
|
2020-05-07 15:08:16 +00:00
|
|
|
it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
const account = 'root@localhost:' + servers[1].port
|
|
|
|
|
|
|
|
blocklistServer.replace({
|
|
|
|
data: [
|
|
|
|
{
|
|
|
|
value: account,
|
|
|
|
updatedAt: new Date().toISOString()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
await wait(2000)
|
|
|
|
|
|
|
|
{
|
|
|
|
const res = await getVideosList(servers[0].url)
|
|
|
|
expect(res.body.total).to.equal(1)
|
|
|
|
}
|
|
|
|
|
2021-07-07 14:02:46 +00:00
|
|
|
await servers[0].blocklistCommand.removeFromServerBlocklist({ account })
|
2020-05-07 15:08:16 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
const res = await getVideosList(servers[0].url)
|
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
}
|
|
|
|
|
|
|
|
killallServers([ servers[0] ])
|
|
|
|
await reRunServer(servers[0])
|
|
|
|
await wait(2000)
|
|
|
|
|
|
|
|
{
|
|
|
|
const res = await getVideosList(servers[0].url)
|
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-05-11 08:15:44 +00:00
|
|
|
it('Should not expose the auto mute list', async function () {
|
|
|
|
await makeGetRequest({
|
|
|
|
url: servers[0].url,
|
|
|
|
path: '/plugins/auto-mute/router/api/v1/mute-list',
|
2020-12-07 13:32:36 +00:00
|
|
|
statusCodeExpected: HttpStatusCode.FORBIDDEN_403
|
2020-05-11 08:15:44 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should enable auto mute list', async function () {
|
2021-07-07 08:33:49 +00:00
|
|
|
await servers[0].pluginsCommand.updateSettings({
|
2020-05-11 08:15:44 +00:00
|
|
|
npmName: 'peertube-plugin-auto-mute',
|
|
|
|
settings: {
|
|
|
|
'blocklist-urls': '',
|
|
|
|
'check-seconds-interval': 1,
|
|
|
|
'expose-mute-list': true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
await makeGetRequest({
|
|
|
|
url: servers[0].url,
|
|
|
|
path: '/plugins/auto-mute/router/api/v1/mute-list',
|
2020-12-07 13:32:36 +00:00
|
|
|
statusCodeExpected: HttpStatusCode.OK_200
|
2020-05-11 08:15:44 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should mute an account on server 1, and server 2 auto mutes it', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
2021-07-07 08:33:49 +00:00
|
|
|
await servers[1].pluginsCommand.updateSettings({
|
2020-05-11 08:15:44 +00:00
|
|
|
npmName: 'peertube-plugin-auto-mute',
|
|
|
|
settings: {
|
|
|
|
'blocklist-urls': 'http://localhost:' + servers[0].port + autoMuteListPath,
|
|
|
|
'check-seconds-interval': 1,
|
|
|
|
'expose-mute-list': false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-07-07 14:02:46 +00:00
|
|
|
await servers[0].blocklistCommand.addToServerBlocklist({ account: 'root@localhost:' + servers[1].port })
|
|
|
|
await servers[0].blocklistCommand.addToMyBlocklist({ server: 'localhost:' + servers[1].port })
|
2020-05-11 08:15:44 +00:00
|
|
|
|
|
|
|
const res = await makeGetRequest({
|
|
|
|
url: servers[0].url,
|
|
|
|
path: '/plugins/auto-mute/router/api/v1/mute-list',
|
2020-12-07 13:32:36 +00:00
|
|
|
statusCodeExpected: HttpStatusCode.OK_200
|
2020-05-11 08:15:44 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const data = res.body.data
|
|
|
|
expect(data).to.have.lengthOf(1)
|
|
|
|
expect(data[0].updatedAt).to.exist
|
|
|
|
expect(data[0].value).to.equal('root@localhost:' + servers[1].port)
|
|
|
|
|
|
|
|
await wait(2000)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const res = await getVideosList(server.url)
|
|
|
|
expect(res.body.total).to.equal(1)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-05-07 14:32:54 +00:00
|
|
|
after(async function () {
|
2020-06-26 12:50:40 +00:00
|
|
|
await blocklistServer.terminate()
|
|
|
|
|
2020-05-07 14:32:54 +00:00
|
|
|
await cleanupTests(servers)
|
|
|
|
})
|
|
|
|
})
|