mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 02:10:45 +00:00
test: tighten zalouser account scope assertions
This commit is contained in:
@@ -8,6 +8,13 @@ import { setZalouserRuntime } from "./runtime.js";
|
||||
import { createZalouserRuntimeEnv } from "./test-helpers.js";
|
||||
import type { ResolvedZalouserAccount, ZaloInboundMessage } from "./types.js";
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
describe("zalouser monitor pairing account scoping", () => {
|
||||
it("scopes DM pairing-store reads and pairing requests to accountId", async () => {
|
||||
const readAllowFromStore = vi.fn(
|
||||
@@ -28,7 +35,12 @@ describe("zalouser monitor pairing account scoping", () => {
|
||||
return scopedAccountId === "beta" ? [] : ["attacker"];
|
||||
},
|
||||
);
|
||||
const upsertPairingRequest = vi.fn(async () => ({ code: "PAIRME88", created: true }));
|
||||
const upsertPairingRequest = vi.fn(
|
||||
async (_params: { channel: string; id: string; accountId?: string }) => ({
|
||||
code: "PAIRME88",
|
||||
created: true,
|
||||
}),
|
||||
);
|
||||
|
||||
setZalouserRuntime({
|
||||
logging: {
|
||||
@@ -89,19 +101,22 @@ describe("zalouser monitor pairing account scoping", () => {
|
||||
runtime: createZalouserRuntimeEnv(),
|
||||
});
|
||||
|
||||
expect(readAllowFromStore).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
channel: "zalouser",
|
||||
accountId: "beta",
|
||||
}),
|
||||
expect(readAllowFromStore).toHaveBeenCalledOnce();
|
||||
const allowStoreParams = requireRecord(
|
||||
readAllowFromStore.mock.calls[0]?.[0],
|
||||
"allow store params",
|
||||
);
|
||||
expect(upsertPairingRequest).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
channel: "zalouser",
|
||||
id: "attacker",
|
||||
accountId: "beta",
|
||||
}),
|
||||
expect(allowStoreParams.channel).toBe("zalouser");
|
||||
expect(allowStoreParams.accountId).toBe("beta");
|
||||
|
||||
expect(upsertPairingRequest).toHaveBeenCalledOnce();
|
||||
const pairingRequest = requireRecord(
|
||||
upsertPairingRequest.mock.calls[0]?.[0],
|
||||
"pairing request params",
|
||||
);
|
||||
expect(pairingRequest.channel).toBe("zalouser");
|
||||
expect(pairingRequest.id).toBe("attacker");
|
||||
expect(pairingRequest.accountId).toBe("beta");
|
||||
expect(sendMessageZalouserMock).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user