Skip to content

Commit d5171bd

Browse files
committed
Activity tracker wouldn't update for recently joined/parted protected rooms.
1 parent 21aabc8 commit d5171bd

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/queues/ProtectedRoomActivityTracker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class ProtectedRoomActivityTracker {
3939
*/
4040
public addProtectedRoom(roomId: string): void {
4141
this.protectedRoomActivities.set(roomId, /* epoch */ 0);
42+
this.activeRoomsCache = null;
4243
}
4344

4445
/**
@@ -47,6 +48,7 @@ export class ProtectedRoomActivityTracker {
4748
*/
4849
public removeProtectedRoom(roomId: string): void {
4950
this.protectedRoomActivities.delete(roomId);
51+
this.activeRoomsCache = null;
5052
}
5153

5254
/**

test/integration/banListTest.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ describe("Test: Updating the PolicyList", function() {
141141
assert.equal(banList.userRules.filter(rule => rule.entity === entity).length, 0, 'The rule should no longer be stored.');
142142
})
143143
it("A rule of the most recent type won't be deleted when an old rule is deleted for the same entity.", async function() {
144-
this.timeout(3000);
145144
const mjolnir: Mjolnir = this.mjolnir!
146145
const moderator = await newTestUser({ name: { contains: "moderator" } });
147146
const banListId = await mjolnir.client.createRoom({ invite: [await moderator.getUserId()] });
@@ -299,22 +298,22 @@ describe('Test: ACL updates will batch when rules are added in succession.', fun
299298
describe('Test: unbaning entities via the PolicyList.', function() {
300299
afterEach(function() { this.moderator?.stop(); });
301300
it('Will remove rules that have legacy types', async function() {
302-
this.timeout(20000)
303301
const mjolnir: Mjolnir = this.mjolnir!
304302
const serverName: string = new UserID(await mjolnir.client.getUserId()).domain
305303
const moderator = await newTestUser({ name: { contains: "moderator" } });
306304
this.moderator = moderator;
307-
moderator.joinRoom(mjolnir.managementRoomId);
305+
await moderator.joinRoom(mjolnir.managementRoomId);
308306
const mjolnirId = await mjolnir.client.getUserId();
309307

310308
// We'll make 1 protected room to test ACLs in.
311-
const protectedRoom = await moderator.createRoom({ invite: [mjolnirId] });
309+
const protectedRoom = await moderator.createRoom({ invite: [mjolnirId], name: "Look for me" });
312310
await mjolnir.client.joinRoom(protectedRoom);
313311
await moderator.setUserPowerLevel(mjolnirId, protectedRoom, 100);
314312
await mjolnir.addProtectedRoom(protectedRoom);
315313

316314
// If a previous test hasn't cleaned up properly, these rooms will be populated by bogus ACLs at this point.
317315
await mjolnir.syncLists();
316+
// If this is not present, then it means the room isn't being protected, which is really bad.
318317
const roomAcl = await mjolnir.client.getRoomStateEvent(protectedRoom, "m.room.server_acl", "");
319318
assert.equal(roomAcl?.deny?.length ?? 0, 0, 'There should be no entries in the deny ACL.');
320319

@@ -323,7 +322,7 @@ describe('Test: unbaning entities via the PolicyList.', function() {
323322
await moderator.setUserPowerLevel(await mjolnir.client.getUserId(), banListId, 100);
324323
await moderator.sendStateEvent(banListId, 'org.matrix.mjolnir.shortcode', '', { shortcode: "unban-test" });
325324
await mjolnir.client.joinRoom(banListId);
326-
this.mjolnir!.watchList(Permalinks.forRoom(banListId));
325+
await mjolnir.watchList(Permalinks.forRoom(banListId));
327326
// we use this to compare changes.
328327
const banList = new PolicyList(banListId, banListId, moderator);
329328
// we need two because we need to test the case where an entity has all rule types in the list
@@ -350,16 +349,16 @@ describe('Test: unbaning entities via the PolicyList.', function() {
350349
try {
351350
await moderator.start();
352351
for (const server of [olderBadServer, newerBadServer]) {
353-
await getFirstReaction(moderator, this.mjolnir.managementRoomId, '✅', async () => {
354-
return await moderator.sendMessage(this.mjolnir.managementRoomId, { msgtype: 'm.text', body: `!mjolnir unban unban-test server ${server}` });
352+
await getFirstReaction(moderator, mjolnir.managementRoomId, '✅', async () => {
353+
return await moderator.sendMessage(mjolnir.managementRoomId, { msgtype: 'm.text', body: `!mjolnir unban unban-test server ${server}` });
355354
});
356355
}
357356
} finally {
358357
moderator.stop();
359358
}
360359

361360
// Wait for mjolnir to sync protected rooms to update ACL.
362-
await this.mjolnir!.syncLists();
361+
await mjolnir.syncLists();
363362
// Confirm that the server is unbanned.
364363
await banList.updateList();
365364
assert.equal(banList.allRules.length, 0);

0 commit comments

Comments
 (0)