mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-04-02 12:25:41 +00:00
* add .pre-commit-config.yaml Signed-off-by: Aminda Suomalainen <suomalainen+git@mikaela.info> * .editorconfig: decrease indent size for text * .pre-commit-config.yaml: remove prettier Signed-off-by: Aminda Suomalainen <suomalainen+git@mikaela.info> * .editorconfig consistency. * .pre-commit-config.yaml: restore sample hooks * .editorconfig: disable indent_size for LICENSE & NOTICE * pre-commit run --all-files * tsconfig.json: tabs to spaces * .pre-commit-config.yaml: update editorconfig-checker to 2.7.2 * .editorconfig: disable indent_size for markdown * mjolnir-entrypoint.sh: retab * .editorconfig: also exclude json from indent checking * test/nginx.conf: retab * test/integration/commands/redactCommandTest.ts: remove leading space * retab or remove leading whitespaces for the rest of the files * src/appservice/datastore.ts remove newlines * test/integration/commands/roomTest.ts: remove leading space. --------- Signed-off-by: Aminda Suomalainen <suomalainen+git@mikaela.info> Co-authored-by: gnuxie <Gnuxie@protonmail.com>
65 lines
3.8 KiB
TypeScript
65 lines
3.8 KiB
TypeScript
|
|
import { strict as assert } from "assert";
|
|
import { MatrixClient, Permalinks } from "matrix-bot-sdk";
|
|
import { MatrixRoomReference } from "../../src/commands/interface-manager/MatrixRoomReference";
|
|
import { MatrixSendClient } from "../../src/MatrixEmitter";
|
|
import { Mjolnir } from "../../src/Mjolnir";
|
|
import PolicyList from "../../src/models/PolicyList";
|
|
import { newTestUser } from "./clientHelper";
|
|
import { createBanList } from "./commands/commandUtils";
|
|
|
|
async function createPolicyList(client: MatrixClient): Promise<PolicyList> {
|
|
const policyListId = await client.createRoom({ preset: "public_chat" });
|
|
return new PolicyList(policyListId, Permalinks.forRoom(policyListId), client);
|
|
}
|
|
|
|
async function getProtectedRoomsFromAccountData(client: MatrixSendClient): Promise<string[]> {
|
|
const rooms: { rooms?: string[] } = await client.getAccountData("org.matrix.mjolnir.protected_rooms");
|
|
return rooms.rooms!;
|
|
}
|
|
|
|
describe('Test: config.protectAllJoinedRooms behaves correctly.', function() {
|
|
it('does not clobber the account data.', async function() {
|
|
// set up account data for a protected room with your own list and a watched list.
|
|
const mjolnir: Mjolnir = this.mjolnir!;
|
|
|
|
// moderator sets up some rooms, that aren't explicitly protected
|
|
const moderator = await newTestUser(this.config.homeserverUrl, { name: { contains: "moderator" } });
|
|
await moderator.joinRoom(mjolnir.managementRoomId);
|
|
const implicitlyProtectedRooms = await Promise.all(
|
|
[...Array(2).keys()].map(_ => moderator.createRoom({ preset: "public_chat" }))
|
|
);
|
|
await Promise.all(
|
|
implicitlyProtectedRooms.map(roomId => mjolnir.client.joinRoom(roomId))
|
|
);
|
|
|
|
// we sync and check that none of them end up in account data
|
|
await mjolnir.protectedRoomsTracker.syncLists();
|
|
(await getProtectedRoomsFromAccountData(mjolnir.client))
|
|
.forEach(roomId => assert.equal(implicitlyProtectedRooms.includes(roomId), false));
|
|
|
|
// ... but they are protected
|
|
mjolnir.protectedRoomsTracker.getProtectedRooms()
|
|
.forEach(roomId => assert.equal(implicitlyProtectedRooms.includes(roomId), true));
|
|
|
|
// We create one policy list with Mjolnir, and we watch another that is maintained by someone else.
|
|
const policyListShortcode = await createBanList(mjolnir.managementRoomId, mjolnir.matrixEmitter, moderator);
|
|
const unprotectedWatchedList = await createPolicyList(moderator);
|
|
await mjolnir.policyListManager.watchList(MatrixRoomReference.fromPermalink(unprotectedWatchedList.roomRef));
|
|
await mjolnir.protectedRoomsTracker.syncLists();
|
|
|
|
// We expect that the watched list will not be protected, despite config.protectAllJoinedRooms being true
|
|
// this is necessary so that it doesn't try change acl, ban users etc in someone else's list.
|
|
assert.equal(mjolnir.protectedRoomsTracker.getProtectedRooms().includes(unprotectedWatchedList.roomId), false);
|
|
const accountDataAfterListSetup = await getProtectedRoomsFromAccountData(mjolnir.client);
|
|
assert.equal(accountDataAfterListSetup.includes(unprotectedWatchedList.roomId), false);
|
|
// But our own list should be protected AND stored in account data
|
|
assert.equal(accountDataAfterListSetup.length, 1);
|
|
const policyListId = accountDataAfterListSetup[0];
|
|
assert.equal(mjolnir.protectedRoomsTracker.getProtectedRooms().includes(policyListId), true);
|
|
// Confirm that it is the right room, since we only get the shortcode back when using the command to create a list.
|
|
const shortcodeInfo = await mjolnir.client.getRoomStateEvent(policyListId, "org.matrix.mjolnir.shortcode", "");
|
|
assert.equal(shortcodeInfo.shortcode, policyListShortcode);
|
|
})
|
|
});
|