Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out rooms where user was never a member when redacting rooms #551

Merged
merged 5 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function matchUserId(userId: string, targetId: string, isGlob: boolean): boolean
* @param isGlob - whether the user ID is a glob
* @param client - Matrix client
*/
async function filterRooms(
export async function filterRooms(
targetRooms: string[],
user: string,
isGlob: boolean,
Expand Down
31 changes: 30 additions & 1 deletion test/integration/commands/redactCommandTest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { strict as assert } from "assert";

import { newTestUser } from "../clientHelper";
import { getMessagesByUserIn } from "../../../src/utils";
import { getMessagesByUserIn, filterRooms } from "../../../src/utils";
import { LogService } from "@vector-im/matrix-bot-sdk";
import { getFirstReaction } from "./commandUtils";
import { SynapseAdminApis } from "@vector-im/matrix-bot-sdk";
Expand Down Expand Up @@ -413,4 +413,33 @@ describe("Test: The redaction command - if not admin", function () {
throw new Error(`Error restoring mjolnir to admin.`);
}
});

it("Correctly tracks room membership of redactee", async function () {
this.timeout(60000);
let badUser = await newTestUser(this.config.homeserverUrl, { name: { contains: "spammer" } });
let moderator = await newTestUser(this.config.homeserverUrl, { name: { contains: "moderator" } });
this.moderator = moderator;
const mjolnir = this.config.RUNTIME.client!;
let mjolnirUserId = await mjolnir.getUserId();
const badUserId = await badUser.getUserId();

await moderator.joinRoom(this.config.managementRoom);
let targetRoom = await moderator.createRoom({ invite: [await badUser.getUserId(), mjolnirUserId] });
await badUser.joinRoom(targetRoom);
await badUser.createRoom();
H-Shay marked this conversation as resolved.
Show resolved Hide resolved

// send a message, leave, then get banned
badUser.sendMessage(targetRoom, {
msgtype: "m.text.",
body: `a bad message`,
});
badUser.leaveRoom(targetRoom);
await moderator.banUser(badUserId, targetRoom, "spam");

// check that filterRooms tracks that badUser was in target room, and doesn't pick up other room badUser
// is in
const rooms = await filterRooms([targetRoom], badUserId, false, moderator);
assert.equal(rooms.length, 1);
assert.equal(rooms[0], targetRoom);
});
});
Loading