2022-04-26 05:37:14 -04:00
|
|
|
import { strict as assert } from "assert";
|
|
|
|
|
|
|
|
import config from "../../src/config";
|
|
|
|
import { Mjolnir } from "../../src/Mjolnir";
|
|
|
|
import { IProtection } from "../../src/protections/IProtection";
|
|
|
|
import { PROTECTIONS } from "../../src/protections/protections";
|
|
|
|
import { ProtectionSettingValidationError } from "../../src/protections/ProtectionSettings";
|
|
|
|
import { NumberProtectionSetting, StringProtectionSetting, StringListProtectionSetting } from "../../src/protections/ProtectionSettings";
|
|
|
|
import { newTestUser, noticeListener } from "./clientHelper";
|
|
|
|
import { matrixClient, mjolnir } from "./mjolnirSetupUtils";
|
|
|
|
|
2022-04-26 07:14:11 -04:00
|
|
|
describe("Test: Report polling", function() {
|
2022-04-26 05:37:14 -04:00
|
|
|
let client;
|
|
|
|
this.beforeEach(async function () {
|
|
|
|
client = await newTestUser({ name: { contains: "protection-settings" }});
|
|
|
|
await client.start();
|
|
|
|
})
|
|
|
|
this.afterEach(async function () {
|
|
|
|
await client.stop();
|
|
|
|
})
|
2022-04-26 07:14:11 -04:00
|
|
|
it("Mjolnir correctly retreives a report from synapse", async function() {
|
2022-04-26 05:37:14 -04:00
|
|
|
this.timeout(20000);
|
|
|
|
|
2022-04-27 10:07:49 -04:00
|
|
|
const reportPromise = new Promise(async (resolve, reject) => {
|
|
|
|
await this.mjolnir.registerProtection(new class implements IProtection {
|
|
|
|
name = "jYvufI";
|
|
|
|
description = "A test protection";
|
|
|
|
settings = { };
|
|
|
|
handleReport = (mjolnir: Mjolnir, roomId: string, reporterId: string, event: any, reason?: string) => {
|
|
|
|
resolve(null);
|
|
|
|
};
|
|
|
|
});
|
2022-04-26 05:37:14 -04:00
|
|
|
});
|
|
|
|
await this.mjolnir.enableProtection("jYvufI");
|
|
|
|
|
|
|
|
const roomId = this.mjolnir.managementRoomId;
|
|
|
|
await this.mjolnir.client.inviteUser(await client.getUserId(), roomId);
|
|
|
|
await client.joinRoom(roomId);
|
|
|
|
|
2022-04-27 10:07:49 -04:00
|
|
|
const eventId = await badUser.sendMesosage(roomId, {msgtype: "m.text", body: "uwNd3q"});
|
2022-04-26 05:37:14 -04:00
|
|
|
await client.doRequest(
|
|
|
|
"POST",
|
|
|
|
`/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/report/${encodeURIComponent(eventId)}`, "", {
|
|
|
|
reason: "dont like it :("
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
await reportPromise;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|