Files
Draupnir/test/unit/protections/RedactionSynchronisationTest.ts
T
Gnuxie ff4f78ee65 RedactionSynchronisationProtection invite retraction (#788)
- The _Redaction Synchronisation Protection_ has been improved in a few ways:
  - Invitations in protected rooms will be rejected as part of the redaction
    process when they are sent from users being redacted (e.g. as a brigading
    tactic).
  - User redaction will now be triggered on bans and the reason will be scanned
    for `automaticallyRedactForReasons` from Draupnir's config.

* Update RedactionSynchronisation for new protection apis.

* Rerwrite redaction synchronisation protection

* Reject invitations on ban.

* Add renderer and simulated redaction synchornisation capability.

* Reduce dependencies of redaction synchronisation protection.

* Allow RedactionSynchronisation to be unit tested.

* Update to MPS 3.1.0.

---------

Signed-off-by: Rory& <root@rory.gay>
Co-authored-by: Rory& <root@rory.gay>
2025-03-28 17:48:57 +00:00

83 lines
2.4 KiB
TypeScript

// SPDX-FileCopyrightText: 2025 Gnuxie <Gnuxie@protonmail.com>
//
// SPDX-License-Identifier: AFL-3.0
import {
describeProtectedRoomsSet,
Membership,
Ok,
PolicyRuleType,
randomRoomID,
randomUserID,
Recommendation,
} from "matrix-protection-suite";
import {
RedactionSynchronisationConsequences,
StandardRedactionSynchronisation,
} from "../../../src/protections/RedactionSynchronisation";
import { MatrixGlob } from "@the-draupnir-project/matrix-basic-types";
import { createMock } from "ts-auto-mock";
import expect from "expect";
describe("RedactionSynchronisation", function () {
it("Attempts to retract invitations on permission requirements met", async function () {
const room = randomRoomID([]);
const targetUser = randomUserID();
const { protectedRoomsSet } = await describeProtectedRoomsSet({
rooms: [
{
room,
membershipDescriptions: [
{
sender: targetUser,
membership: Membership.Leave,
},
{
sender: targetUser,
membership: Membership.Invite,
target: randomUserID(),
},
],
},
],
lists: [
{
policyDescriptions: [
{
recommendation: Recommendation.Ban,
entity: targetUser,
reason: "spam",
type: PolicyRuleType.User,
},
],
},
],
});
let mockMethodCalls = 0;
const mockConsequences = createMock<RedactionSynchronisationConsequences>({
async redactMessagesIn(userIDOrGlob, _reason, _roomIDs) {
expect(userIDOrGlob).toBe(targetUser);
mockMethodCalls += 1;
return Ok(undefined);
},
async rejectInvite(roomID, sender, _reciever, _reason) {
expect(roomID).toBe(room.toRoomIDOrAlias());
expect(sender).toBe(targetUser);
mockMethodCalls += 1;
return Ok(undefined);
},
});
const redactionSynronisationService = new StandardRedactionSynchronisation(
[new MatrixGlob("spam")],
mockConsequences,
protectedRoomsSet.watchedPolicyRooms,
protectedRoomsSet.setRoomMembership,
protectedRoomsSet.setPoliciesMatchingMembership
);
redactionSynronisationService.handlePermissionRequirementsMet(
room.toRoomIDOrAlias()
);
expect(mockMethodCalls).toBe(1);
});
});