fix: fail closed when pairing scopes are missing

This commit is contained in:
Coy Geek 2026-03-27 12:50:20 -07:00 committed by Peter Steinberger
parent 353d93613c
commit 05ca581ed0
1 changed files with 37 additions and 0 deletions

View File

@ -772,4 +772,41 @@ describe("device-pair /pair approve", () => {
text: "⚠️ This command requires operator.admin to approve this pairing request.",
});
});
it("fails closed when gateway scopes are absent", async () => {
vi.mocked(listDevicePairing).mockResolvedValueOnce({
pending: [
{
requestId: "req-1",
deviceId: "victim-phone",
publicKey: "victim-public-key",
displayName: "Victim Phone",
platform: "ios",
ts: Date.now(),
},
],
paired: [],
});
vi.mocked(approveDevicePairing).mockImplementationOnce(async () => ({
status: "forbidden",
missingScope: "operator.admin",
}));
const command = registerPairCommand();
const result = await command.handler(
createCommandContext({
channel: "webchat",
args: "approve latest",
commandBody: "/pair approve latest",
gatewayClientScopes: undefined,
}),
);
expect(vi.mocked(approveDevicePairing)).toHaveBeenCalledWith("req-1", {
callerScopes: [],
});
expect(result).toEqual({
text: "⚠️ This command requires operator.admin to approve this pairing request.",
});
});
});