mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-08-29 07:08:50 +00:00
Docker Hub - Develop / docker-latest (push) Canceled after 0s
GHCR - Development Branches / ghcr-publish (push) Canceled after 0s
Tests / Build & Lint (push) Canceled after 0s
Tests / Unit tests (push) Canceled after 0s
Tests / Integration tests (push) Canceled after 0s
Tests / Application Service Integration tests (push) Canceled after 0s
Validate Docker Build / validate-docker-build (push) Canceled after 0s
* Remove old matrix-protection-suite package aliases. This was leading to issues with monorepo package management. https://github.com/the-draupnir-project/Draupnir/issues/1124 * Fix badly imported symbols from packages that already export them. * Cleanup build command arguments. There was a deprecation warning for short workspaces flag.
88 lines
2.8 KiB
TypeScript
88 lines
2.8 KiB
TypeScript
// SPDX-FileCopyrightText: 2025 Gnuxie <Gnuxie@protonmail.com>
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import Database from "better-sqlite3";
|
|
import { BetterSqliteOptions } from "../../../src/backingstore/better-sqlite3/BetterSqliteStore";
|
|
import {
|
|
describePolicyRule,
|
|
LiteralPolicyRule,
|
|
parsePolicyRule,
|
|
PolicyRuleType,
|
|
randomRoomID,
|
|
randomUserID,
|
|
Recommendation,
|
|
} from "@the-draupnir-project/matrix-protection-suite";
|
|
import expect from "expect";
|
|
import { AccountRestriction } from "@the-draupnir-project/matrix-protection-suite-for-matrix-bot-sdk";
|
|
import { SqliteUserRestrictionAuditLog } from "../../../src/protections/HomeserverUserPolicyApplication/SqliteUserRestrictionAuditLog";
|
|
|
|
describe("UserAuditLog test", function () {
|
|
const options = { path: ":memory:" } satisfies BetterSqliteOptions;
|
|
const db = new Database(options.path);
|
|
db.pragma("FOREIGN_KEYS = ON");
|
|
const store = new SqliteUserRestrictionAuditLog(db);
|
|
it("Can logged suspended users", async function () {
|
|
const bannedUser = randomUserID();
|
|
const policyRoom = randomRoomID([]);
|
|
const moderator = randomUserID();
|
|
expect(
|
|
(await store.isUserRestricted(bannedUser)).expect(
|
|
"Should be able to query if user is suspended"
|
|
)
|
|
).toBe(false);
|
|
const ban = parsePolicyRule(
|
|
describePolicyRule({
|
|
room_id: policyRoom.toRoomIDOrAlias(),
|
|
entity: bannedUser,
|
|
reason: "spam",
|
|
recommendation: Recommendation.Ban,
|
|
type: PolicyRuleType.User,
|
|
}) as never
|
|
).expect("Should be able to parse the policy rule.");
|
|
(
|
|
await store.recordUserRestriction(
|
|
bannedUser,
|
|
AccountRestriction.Suspended,
|
|
{
|
|
sender: moderator,
|
|
rule: ban as LiteralPolicyRule,
|
|
}
|
|
)
|
|
).expect("Should be able to takedown a room");
|
|
expect(
|
|
(await store.isUserRestricted(bannedUser)).expect(
|
|
"Should be able to query if user is suspended"
|
|
)
|
|
).toBe(true);
|
|
// now unsuspend them
|
|
(await store.unrestrictUser(bannedUser, moderator)).expect(
|
|
"Should be able to unsuspend a user"
|
|
);
|
|
expect(
|
|
(await store.isUserRestricted(bannedUser)).expect(
|
|
"Should be able to query if user is suspended"
|
|
)
|
|
).toBe(false);
|
|
});
|
|
it("Can log suspended users even without a policy (when a command is used)", async function () {
|
|
const bannedUser = randomUserID();
|
|
const moderator = randomUserID();
|
|
(
|
|
await store.recordUserRestriction(
|
|
bannedUser,
|
|
AccountRestriction.Suspended,
|
|
{
|
|
sender: moderator,
|
|
rule: null,
|
|
}
|
|
)
|
|
).expect("To be able to do this");
|
|
expect(
|
|
(await store.isUserRestricted(bannedUser)).expect(
|
|
"Should be able to query if user is suspended"
|
|
)
|
|
).toBe(true);
|
|
});
|
|
});
|