2020-05-07 10:32:54 -04:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import { expect } from 'chai'
|
2021-12-17 05:58:15 -05:00
|
|
|
import { wait } from '@shared/core-utils'
|
|
|
|
import { HttpStatusCode } from '@shared/models'
|
2020-05-11 04:15:44 -04:00
|
|
|
import {
|
2021-07-07 04:33:49 -04:00
|
|
|
cleanupTests,
|
2021-07-16 03:47:51 -04:00
|
|
|
createMultipleServers,
|
2021-07-16 08:27:30 -04:00
|
|
|
doubleFollow,
|
2021-07-07 04:33:49 -04:00
|
|
|
killallServers,
|
2020-05-11 04:15:44 -04:00
|
|
|
makeGetRequest,
|
2021-07-16 03:47:51 -04:00
|
|
|
PeerTubeServer,
|
2021-12-17 05:58:15 -05:00
|
|
|
setAccessTokensToServers
|
2021-12-17 03:29:23 -05:00
|
|
|
} from '@shared/server-commands'
|
2021-12-17 05:58:15 -05:00
|
|
|
import { MockBlocklist } from '../shared'
|
2020-05-07 10:32:54 -04:00
|
|
|
|
|
|
|
describe('Official plugin auto-mute', function () {
|
2020-05-11 04:15:44 -04:00
|
|
|
const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
|
2021-07-16 03:47:51 -04:00
|
|
|
let servers: PeerTubeServer[]
|
2020-05-07 10:32:54 -04:00
|
|
|
let blocklistServer: MockBlocklist
|
2021-06-03 03:06:51 -04:00
|
|
|
let port: number
|
2020-05-07 10:32:54 -04:00
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2021-07-16 03:47:51 -04:00
|
|
|
servers = await createMultipleServers(2)
|
2020-05-07 10:32:54 -04:00
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
2020-05-11 04:15:44 -04:00
|
|
|
for (const server of servers) {
|
2021-07-16 03:04:35 -04:00
|
|
|
await server.plugins.install({ npmName: 'peertube-plugin-auto-mute' })
|
2020-05-11 04:15:44 -04:00
|
|
|
}
|
2020-05-07 10:32:54 -04:00
|
|
|
|
|
|
|
blocklistServer = new MockBlocklist()
|
2021-06-03 03:06:51 -04:00
|
|
|
port = await blocklistServer.initialize()
|
2020-05-07 10:32:54 -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' })
|
2020-05-07 10:32:54 -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-05-07 10:32:54 -04:00
|
|
|
npmName: 'peertube-plugin-auto-mute',
|
|
|
|
settings: {
|
2022-12-09 05:14:47 -05:00
|
|
|
'blocklist-urls': `http://127.0.0.1:${port}/blocklist`,
|
2020-05-07 10:32:54 -04:00
|
|
|
'check-seconds-interval': 1
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should add a server blocklist', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
blocklistServer.replace({
|
|
|
|
data: [
|
|
|
|
{
|
2022-12-09 05:14:47 -05:00
|
|
|
value: servers[1].host
|
2020-05-07 10:32:54 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
await wait(2000)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
const { total } = await servers[0].videos.list()
|
2021-07-15 04:02:54 -04:00
|
|
|
expect(total).to.equal(1)
|
2020-05-07 10:32:54 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should remove a server blocklist', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
blocklistServer.replace({
|
|
|
|
data: [
|
|
|
|
{
|
2022-12-09 05:14:47 -05:00
|
|
|
value: servers[1].host,
|
2020-05-07 10:32:54 -04:00
|
|
|
action: 'remove'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
await wait(2000)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
const { total } = await servers[0].videos.list()
|
2021-07-15 04:02:54 -04:00
|
|
|
expect(total).to.equal(2)
|
2020-05-07 10:32:54 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should add an account blocklist', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
blocklistServer.replace({
|
|
|
|
data: [
|
|
|
|
{
|
2022-12-09 05:14:47 -05:00
|
|
|
value: 'root@' + servers[1].host
|
2020-05-07 10:32:54 -04:00
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
await wait(2000)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
const { total } = await servers[0].videos.list()
|
2021-07-15 04:02:54 -04:00
|
|
|
expect(total).to.equal(1)
|
2020-05-07 10:32:54 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should remove an account blocklist', async function () {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
blocklistServer.replace({
|
|
|
|
data: [
|
|
|
|
{
|
2022-12-09 05:14:47 -05:00
|
|
|
value: 'root@' + servers[1].host,
|
2020-05-07 10:32:54 -04:00
|
|
|
action: 'remove'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
await wait(2000)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
const { total } = await servers[0].videos.list()
|
2021-07-15 04:02:54 -04:00
|
|
|
expect(total).to.equal(2)
|
2020-05-07 10:32:54 -04:00
|
|
|
})
|
|
|
|
|
2020-05-07 11:08:16 -04:00
|
|
|
it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
2022-12-09 05:14:47 -05:00
|
|
|
const account = 'root@' + servers[1].host
|
2020-05-07 11:08:16 -04:00
|
|
|
|
|
|
|
blocklistServer.replace({
|
|
|
|
data: [
|
|
|
|
{
|
|
|
|
value: account,
|
|
|
|
updatedAt: new Date().toISOString()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
await wait(2000)
|
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const { total } = await servers[0].videos.list()
|
2021-07-15 04:02:54 -04:00
|
|
|
expect(total).to.equal(1)
|
2020-05-07 11:08:16 -04:00
|
|
|
}
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].blocklist.removeFromServerBlocklist({ account })
|
2020-05-07 11:08:16 -04:00
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const { total } = await servers[0].videos.list()
|
2021-07-15 04:02:54 -04:00
|
|
|
expect(total).to.equal(2)
|
2020-05-07 11:08:16 -04:00
|
|
|
}
|
|
|
|
|
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-05-07 11:08:16 -04:00
|
|
|
await wait(2000)
|
|
|
|
|
|
|
|
{
|
2021-07-16 03:04:35 -04:00
|
|
|
const { total } = await servers[0].videos.list()
|
2021-07-15 04:02:54 -04:00
|
|
|
expect(total).to.equal(2)
|
2020-05-07 11:08:16 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-05-11 04:15:44 -04: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',
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
2020-05-11 04:15:44 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should enable auto mute list', async function () {
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[0].plugins.updateSettings({
|
2020-05-11 04:15:44 -04: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',
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.OK_200
|
2020-05-11 04:15:44 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should mute an account on server 1, and server 2 auto mutes it', async function () {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
2021-07-16 03:04:35 -04:00
|
|
|
await servers[1].plugins.updateSettings({
|
2020-05-11 04:15:44 -04:00
|
|
|
npmName: 'peertube-plugin-auto-mute',
|
|
|
|
settings: {
|
2022-12-09 05:14:47 -05:00
|
|
|
'blocklist-urls': 'http://' + servers[0].host + autoMuteListPath,
|
2020-05-11 04:15:44 -04:00
|
|
|
'check-seconds-interval': 1,
|
|
|
|
'expose-mute-list': false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-12-09 05:14:47 -05:00
|
|
|
await servers[0].blocklist.addToServerBlocklist({ account: 'root@' + servers[1].host })
|
|
|
|
await servers[0].blocklist.addToMyBlocklist({ server: servers[1].host })
|
2020-05-11 04:15:44 -04:00
|
|
|
|
|
|
|
const res = await makeGetRequest({
|
|
|
|
url: servers[0].url,
|
|
|
|
path: '/plugins/auto-mute/router/api/v1/mute-list',
|
2021-07-16 04:42:24 -04:00
|
|
|
expectedStatus: HttpStatusCode.OK_200
|
2020-05-11 04:15:44 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
const data = res.body.data
|
|
|
|
expect(data).to.have.lengthOf(1)
|
|
|
|
expect(data[0].updatedAt).to.exist
|
2022-12-09 05:14:47 -05:00
|
|
|
expect(data[0].value).to.equal('root@' + servers[1].host)
|
2020-05-11 04:15:44 -04:00
|
|
|
|
|
|
|
await wait(2000)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-07-16 03:04:35 -04:00
|
|
|
const { total } = await server.videos.list()
|
2021-07-15 04:02:54 -04:00
|
|
|
expect(total).to.equal(1)
|
2020-05-11 04:15:44 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-05-07 10:32:54 -04:00
|
|
|
after(async function () {
|
2020-06-26 08:50:40 -04:00
|
|
|
await blocklistServer.terminate()
|
|
|
|
|
2020-05-07 10:32:54 -04:00
|
|
|
await cleanupTests(servers)
|
|
|
|
})
|
|
|
|
})
|