mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-05-25 18:04:01 +00:00
Unit test and fix sqlite room audit log.
This commit is contained in:
@@ -31,13 +31,13 @@ const schema = [
|
||||
room_id TEXT NOT NULL,
|
||||
state_key TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
recommendation TEXT NOT NULL,
|
||||
recommendation TEXT NOT NULL
|
||||
) STRICT;`,
|
||||
`CREATE TABLE room_takedown (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
policy_id TEXT NOT NULL,
|
||||
target_room_id TEXT NOT NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
created_at INTEGER DEFAULT (unixepoch()) NOT NULL,
|
||||
FOREIGN KEY (policy_id) REFERENCES policy_info(policy_id)
|
||||
) STRICT;`,
|
||||
];
|
||||
@@ -119,7 +119,7 @@ export class SqliteRoomAuditLog
|
||||
|
||||
private loadTakendownRooms(): StringRoomID[] {
|
||||
return this.db
|
||||
.prepare(`SELECT room_id FROM room_takedown`)
|
||||
.prepare(`SELECT target_room_id FROM room_takedown`)
|
||||
.all() as StringRoomID[];
|
||||
}
|
||||
isRoomTakendown(roomID: StringRoomID): boolean {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
// SPDX-FileCopyrightText: 2025 Gnuxie <Gnuxie@protonmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: AFL-3.0
|
||||
|
||||
import Database from "better-sqlite3";
|
||||
import { BetterSqliteOptions } from "../../../src/backingstore/better-sqlite3/BetterSqliteStore";
|
||||
import { SqliteRoomAuditLog } from "../../../src/protections/RoomTakedown/SqliteRoomAuditLog";
|
||||
import {
|
||||
describePolicyRule,
|
||||
LiteralPolicyRule,
|
||||
parsePolicyRule,
|
||||
PolicyRuleType,
|
||||
randomRoomID,
|
||||
Recommendation,
|
||||
} from "matrix-protection-suite";
|
||||
import expect from "expect";
|
||||
|
||||
describe("RoomAuditLog test", function () {
|
||||
const options = { path: ":memory:" } satisfies BetterSqliteOptions;
|
||||
const db = new Database(options.path);
|
||||
db.pragma("FOREIGN_KEYS = ON");
|
||||
const store = new SqliteRoomAuditLog(options, db);
|
||||
it("Test that it doesn't return null or something", async function () {
|
||||
expect(store.isRoomTakendown(randomRoomID([]).toRoomIDOrAlias())).toBe(
|
||||
false
|
||||
);
|
||||
});
|
||||
it("Can logged takendown rooms", async function () {
|
||||
const bannedRoom = randomRoomID([]);
|
||||
const policyRoom = randomRoomID([]);
|
||||
const ban = parsePolicyRule(
|
||||
describePolicyRule({
|
||||
room_id: policyRoom.toRoomIDOrAlias(),
|
||||
entity: bannedRoom.toRoomIDOrAlias(),
|
||||
reason: "spam",
|
||||
recommendation: Recommendation.Takedown,
|
||||
type: PolicyRuleType.Room,
|
||||
}) as never
|
||||
).expect("Should bea ble to parse the policy rule.");
|
||||
(await store.takedownRoom(ban as LiteralPolicyRule)).expect(
|
||||
"Should be able to takedown a room"
|
||||
);
|
||||
expect(store.isRoomTakendown(bannedRoom.toRoomIDOrAlias())).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user