fix(regression): allow external device pair approvals

This commit is contained in:
Tak Hoffman
2026-03-27 16:07:54 -05:00
parent eacd5ac3ef
commit 85cf23a9d6
2 changed files with 58 additions and 3 deletions

View File

@@ -516,6 +516,59 @@ describe("device-pair /pair approve", () => {
expect(result).toEqual({ text: "✅ Paired Victim Phone (ios)." });
});
it("does not force an empty caller scope context for external approvals", 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).mockResolvedValueOnce({
status: "approved",
requestId: "req-1",
device: {
deviceId: "victim-phone",
publicKey: "victim-public-key",
displayName: "Victim Phone",
platform: "ios",
role: "operator",
roles: ["operator"],
scopes: ["operator.pairing"],
approvedScopes: ["operator.pairing"],
tokens: {
operator: {
token: "token-1",
role: "operator",
scopes: ["operator.pairing"],
createdAtMs: Date.now(),
},
},
createdAtMs: Date.now(),
approvedAtMs: Date.now(),
},
});
const command = registerPairCommand();
const result = await command.handler(
createCommandContext({
channel: "telegram",
args: "approve latest",
commandBody: "/pair approve latest",
gatewayClientScopes: undefined,
}),
);
expect(vi.mocked(approveDevicePairing)).toHaveBeenCalledWith("req-1");
expect(result).toEqual({ text: "✅ Paired Victim Phone (ios)." });
});
it("rejects approvals above the caller scopes", async () => {
vi.mocked(listDevicePairing).mockResolvedValueOnce({
pending: [

View File

@@ -611,9 +611,11 @@ export default definePluginEntry({
if (!pending) {
return { text: "Pairing request not found." };
}
const approved = await approveDevicePairing(pending.requestId, {
callerScopes: gatewayClientScopes ?? [],
});
const approved = gatewayClientScopes
? await approveDevicePairing(pending.requestId, {
callerScopes: gatewayClientScopes,
})
: await approveDevicePairing(pending.requestId);
if (!approved) {
return { text: "Pairing request not found." };
}