mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-09-26 04:33:39 +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.
87 lines
2.7 KiB
TypeScript
87 lines
2.7 KiB
TypeScript
// Copyright 2022 - 2024 Gnuxie <Gnuxie@protonmail.com>
|
|
// Copyright 2021, 2022 Marco Cirillo
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
// SPDX-FileAttributionText: <text>
|
|
// This modified file incorporates work from mjolnir
|
|
// https://github.com/matrix-org/mjolnir
|
|
// </text>
|
|
|
|
import { strict as assert } from "assert";
|
|
import { newTestUser } from "../clientHelper";
|
|
import { getFirstReaction } from "./commandUtils";
|
|
import { DraupnirTestContext, draupnirSafeEmitter } from "../mjolnirSetupUtils";
|
|
import { PowerLevelsEventContent } from "@the-draupnir-project/matrix-protection-suite";
|
|
|
|
// Breaks with this test.
|
|
describe("Test: The make admin command", function () {
|
|
it("Draupnir make the bot self room administrator", async function (
|
|
this: DraupnirTestContext
|
|
) {
|
|
this.timeout(90000);
|
|
if (!this.config.admin?.enableMakeRoomAdminCommand) {
|
|
return;
|
|
}
|
|
const draupnir = this.draupnir;
|
|
if (draupnir === undefined) {
|
|
throw new TypeError(`Test didn't setup correctly`);
|
|
}
|
|
const moderator = await newTestUser(this.config.homeserverUrl, {
|
|
name: { contains: "moderator" },
|
|
});
|
|
const userA = await newTestUser(this.config.homeserverUrl, {
|
|
name: { contains: "a" },
|
|
});
|
|
const userAId = await userA.getUserId();
|
|
|
|
await moderator.joinRoom(draupnir.managementRoomID);
|
|
const targetRoom = await moderator.createRoom({
|
|
invite: [draupnir.clientUserID],
|
|
preset: "public_chat",
|
|
});
|
|
await moderator.sendMessage(draupnir.managementRoomID, {
|
|
msgtype: "m.text.",
|
|
body: `!draupnir rooms add ${targetRoom}`,
|
|
});
|
|
await userA.joinRoom(targetRoom);
|
|
const powerLevelsBefore = (await moderator.getRoomStateEvent(
|
|
targetRoom,
|
|
"m.room.power_levels",
|
|
""
|
|
)) as PowerLevelsEventContent;
|
|
assert.notEqual(
|
|
powerLevelsBefore["users"]?.[draupnir.clientUserID],
|
|
100,
|
|
`Bot should not yet be an admin of ${targetRoom}`
|
|
);
|
|
await getFirstReaction(
|
|
draupnirSafeEmitter(),
|
|
draupnir.managementRoomID,
|
|
"✅",
|
|
async () => {
|
|
return await moderator.sendMessage(draupnir.managementRoomID, {
|
|
msgtype: "m.text",
|
|
body: `!draupnir hijack room ${targetRoom} ${draupnir.clientUserID}`,
|
|
});
|
|
}
|
|
);
|
|
|
|
const powerLevelsAfter = (await moderator.getRoomStateEvent(
|
|
targetRoom,
|
|
"m.room.power_levels",
|
|
""
|
|
)) as PowerLevelsEventContent;
|
|
assert.equal(
|
|
powerLevelsAfter["users"]?.[draupnir.clientUserID],
|
|
100,
|
|
"Bot should be a room admin."
|
|
);
|
|
assert.equal(
|
|
powerLevelsAfter["users"][userAId],
|
|
undefined,
|
|
"User A is not supposed to be a room admin."
|
|
);
|
|
} as unknown as Mocha.AsyncFunc);
|
|
});
|