
























@@ -4,6 +4,17 @@ import {
44resolveMatrixMonitorCommandAccess,
55} from "./access-state.js";
667+async function expectCommandAccess(
8+state: Parameters<typeof resolveMatrixMonitorCommandAccess>[0],
9+params: Parameters<typeof resolveMatrixMonitorCommandAccess>[1],
10+expected: { authorized: boolean; shouldBlockControlCommand: boolean },
11+): Promise<void> {
12+const access = await resolveMatrixMonitorCommandAccess(state, params);
13+14+expect(access.authorized).toBe(expected.authorized);
15+expect(access.shouldBlockControlCommand).toBe(expected.shouldBlockControlCommand);
16+}
17+718describe("resolveMatrixMonitorAccessState", () => {
819it("normalizes group allowlists and uses shared ingress matching", async () => {
920const state = await resolveMatrixMonitorAccessState({
@@ -31,16 +42,15 @@ describe("resolveMatrixMonitorAccessState", () => {
3142isRoom: true,
3243});
334434-expect(
35-await resolveMatrixMonitorCommandAccess(state, {
45+await expectCommandAccess(
46+state,
47+{
3648useAccessGroups: true,
3749allowTextCommands: true,
3850hasControlCommand: true,
39-}),
40-).toMatchObject({
41-authorized: false,
42-shouldBlockControlCommand: true,
43-});
51+},
52+{ authorized: false, shouldBlockControlCommand: true },
53+);
4454});
45554656it("does not let pairing-store entries authorize open DMs without wildcard", async () => {
@@ -69,16 +79,15 @@ describe("resolveMatrixMonitorAccessState", () => {
6979isRoom: true,
7080});
718172-expect(
73-await resolveMatrixMonitorCommandAccess(state, {
82+await expectCommandAccess(
83+state,
84+{
7485useAccessGroups: true,
7586allowTextCommands: true,
7687hasControlCommand: true,
77-}),
78-).toMatchObject({
79-authorized: false,
80-shouldBlockControlCommand: true,
81-});
88+},
89+{ authorized: false, shouldBlockControlCommand: true },
90+);
8291});
83928493it("treats unresolved configured room allowlists as configured but nonmatching", async () => {
@@ -107,26 +116,24 @@ describe("resolveMatrixMonitorAccessState", () => {
107116expect(roomState.effectiveRoomUsers).toEqual(["dana"]);
108117expect(roomState.messageIngress.ingress.decision).toBe("block");
109118expect(roomState.messageIngress.ingress.reasonCode).toBe("group_policy_not_allowlisted");
110-await expect(
111-resolveMatrixMonitorCommandAccess(groupState, {
119+await expectCommandAccess(
120+groupState,
121+{
112122useAccessGroups: true,
113123allowTextCommands: true,
114124hasControlCommand: true,
115-}),
116-).resolves.toMatchObject({
117-authorized: false,
118-shouldBlockControlCommand: true,
119-});
120-await expect(
121-resolveMatrixMonitorCommandAccess(roomState, {
125+},
126+{ authorized: false, shouldBlockControlCommand: true },
127+);
128+await expectCommandAccess(
129+roomState,
130+{
122131useAccessGroups: true,
123132allowTextCommands: true,
124133hasControlCommand: true,
125-}),
126-).resolves.toMatchObject({
127-authorized: false,
128-shouldBlockControlCommand: true,
129-});
134+},
135+{ authorized: false, shouldBlockControlCommand: true },
136+);
130137});
131138132139it("authorizes room control commands through the shared ingress command gate", async () => {
@@ -139,16 +146,15 @@ describe("resolveMatrixMonitorAccessState", () => {
139146isRoom: true,
140147});
141148142-expect(
143-await resolveMatrixMonitorCommandAccess(state, {
149+await expectCommandAccess(
150+state,
151+{
144152useAccessGroups: true,
145153allowTextCommands: true,
146154hasControlCommand: true,
147-}),
148-).toMatchObject({
149-authorized: true,
150-shouldBlockControlCommand: false,
151-});
155+},
156+{ authorized: true, shouldBlockControlCommand: false },
157+);
152158});
153159154160it("keeps command allow mode when access groups are disabled", async () => {
@@ -161,16 +167,15 @@ describe("resolveMatrixMonitorAccessState", () => {
161167isRoom: true,
162168});
163169164-expect(
165-await resolveMatrixMonitorCommandAccess(state, {
170+await expectCommandAccess(
171+state,
172+{
166173useAccessGroups: false,
167174allowTextCommands: true,
168175hasControlCommand: true,
169-}),
170-).toMatchObject({
171-authorized: true,
172-shouldBlockControlCommand: false,
173-});
176+},
177+{ authorized: true, shouldBlockControlCommand: false },
178+);
174179});
175180176181it("keeps room-user allowlists out of dm traffic", async () => {
@@ -184,16 +189,15 @@ describe("resolveMatrixMonitorAccessState", () => {
184189});
185190186191expect(state.messageIngress.senderAccess.decision).toBe("pairing");
187-expect(
188-await resolveMatrixMonitorCommandAccess(state, {
192+await expectCommandAccess(
193+state,
194+{
189195useAccessGroups: true,
190196allowTextCommands: true,
191197hasControlCommand: true,
192-}),
193-).toMatchObject({
194-authorized: false,
195-shouldBlockControlCommand: true,
196-});
198+},
199+{ authorized: false, shouldBlockControlCommand: true },
200+);
197201});
198202199203it("uses the shared ingress decision for room user sender gates", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。