diff --git a/server/tests/external-plugins/auto-mute.ts b/server/tests/external-plugins/auto-mute.ts index 2f2c9102d..bfdbee80a 100644 --- a/server/tests/external-plugins/auto-mute.ts +++ b/server/tests/external-plugins/auto-mute.ts @@ -2,11 +2,16 @@ import 'mocha' import { expect } from 'chai' -import { removeAccountFromServerBlocklist } from '@shared/extra-utils/users/blocklist' +import { + addAccountToServerBlocklist, + addServerToAccountBlocklist, + removeAccountFromServerBlocklist +} from '@shared/extra-utils/users/blocklist' import { doubleFollow, getVideosList, installPlugin, + makeGetRequest, MockBlocklist, setAccessTokensToServers, updatePluginSettings, @@ -22,6 +27,7 @@ import { } from '../../../shared/extra-utils/server/servers' describe('Official plugin auto-mute', function () { + const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list' let servers: ServerInfo[] let blocklistServer: MockBlocklist @@ -31,11 +37,13 @@ describe('Official plugin auto-mute', function () { servers = await flushAndRunMultipleServers(2) await setAccessTokensToServers(servers) - await installPlugin({ - url: servers[0].url, - accessToken: servers[0].accessToken, - npmName: 'peertube-plugin-auto-mute' - }) + for (const server of servers) { + await installPlugin({ + url: server.url, + accessToken: server.accessToken, + npmName: 'peertube-plugin-auto-mute' + }) + } blocklistServer = new MockBlocklist() await blocklistServer.initialize() @@ -166,6 +174,69 @@ describe('Official plugin auto-mute', function () { } }) + 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', + statusCodeExpected: 403 + }) + }) + + it('Should enable auto mute list', async function () { + await updatePluginSettings({ + url: servers[0].url, + accessToken: servers[0].accessToken, + 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', + statusCodeExpected: 200 + }) + }) + + it('Should mute an account on server 1, and server 2 auto mutes it', async function () { + this.timeout(20000) + + await updatePluginSettings({ + url: servers[1].url, + accessToken: servers[1].accessToken, + npmName: 'peertube-plugin-auto-mute', + settings: { + 'blocklist-urls': 'http://localhost:' + servers[0].port + autoMuteListPath, + 'check-seconds-interval': 1, + 'expose-mute-list': false + } + }) + + await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port) + await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port) + + const res = await makeGetRequest({ + url: servers[0].url, + path: '/plugins/auto-mute/router/api/v1/mute-list', + statusCodeExpected: 200 + }) + + 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) + } + }) + after(async function () { await cleanupTests(servers) }) diff --git a/server/tests/external-plugins/index.ts b/server/tests/external-plugins/index.ts index 352d38de9..d17894c15 100644 --- a/server/tests/external-plugins/index.ts +++ b/server/tests/external-plugins/index.ts @@ -1,2 +1,2 @@ -export * from './auth-ldap' -export * from './auto-mute' +import './auth-ldap' +import './auto-mute'