Skip to content

Commit 7ba4df6

Browse files
committed
test(gateway): split node pairing diagnostics suite
1 parent 6a52197 commit 7ba4df6

2 files changed

Lines changed: 236 additions & 208 deletions

File tree

‎src/gateway/server.node-pairing-authz.test.ts‎

Lines changed: 0 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
GATEWAY_CLIENT_NAMES,
1313
type GatewayClientName,
1414
} from "../utils/message-channel.js";
15-
import { callGateway } from "./call.js";
1615
import {
1716
issueOperatorToken,
1817
loadDeviceIdentity,
@@ -718,213 +717,6 @@ describe("gateway node pairing authorization", () => {
718717
});
719718
});
720719

721-
describeWithGatewayServer("pending diagnostics scopes", (getStarted) => {
722-
test("shows pending pairing records to direct-local backend shared-auth callers", async () => {
723-
const pendingOnlyNodeId = "node-local-backend-pending";
724-
await seedNodeDevice(pendingOnlyNodeId);
725-
const pending = await requestNodePairing({
726-
nodeId: pendingOnlyNodeId,
727-
platform: "macos",
728-
commands: ["system.run"],
729-
});
730-
731-
const listed = await callGateway<{
732-
nodes?: Array<{
733-
nodeId: string;
734-
approvalState?: string;
735-
pendingRequestId?: string;
736-
}>;
737-
}>({
738-
config: {
739-
gateway: {
740-
mode: "local",
741-
bind: "loopback",
742-
port: getStarted().port,
743-
auth: { mode: "token", token: "secret" },
744-
},
745-
},
746-
method: "node.list",
747-
scopes: ["operator.read", "operator.pairing"],
748-
requireLocalBackendSharedAuth: true,
749-
timeoutMs: 2_000,
750-
});
751-
752-
expect(listed.nodes).toContainEqual(
753-
expect.objectContaining({
754-
nodeId: pendingOnlyNodeId,
755-
approvalState: "pending-approval",
756-
pendingRequestId: pending.request.requestId,
757-
}),
758-
);
759-
});
760-
761-
test("shows only the caller's pending request id to read-only callers", async () => {
762-
const pairedNodeId = "node-read-only-paired";
763-
const pendingOnlyNodeId = "node-read-only-pending";
764-
const visiblePendingNode = await pairDeviceIdentity({
765-
name: "node-read-only-visible-pending",
766-
role: "operator",
767-
scopes: ["operator.read"],
768-
});
769-
await pairDeviceIdentity({
770-
name: "node-read-only-visible-pending",
771-
role: "node",
772-
scopes: [],
773-
clientId: GATEWAY_CLIENT_NAMES.NODE_HOST,
774-
clientMode: GATEWAY_CLIENT_MODES.NODE,
775-
});
776-
await seedNodeDevice(pairedNodeId);
777-
const initial = await requestNodePairing({
778-
nodeId: pairedNodeId,
779-
platform: "macos",
780-
commands: ["screen.snapshot"],
781-
});
782-
await approveNodePairing(initial.request.requestId, {
783-
callerScopes: ["operator.pairing", "operator.write"],
784-
});
785-
await requestNodePairing({
786-
nodeId: pairedNodeId,
787-
platform: "macos",
788-
commands: ["screen.snapshot", "system.run"],
789-
});
790-
await seedNodeDevice(pendingOnlyNodeId);
791-
await requestNodePairing({
792-
nodeId: pendingOnlyNodeId,
793-
platform: "macos",
794-
commands: ["system.run"],
795-
});
796-
const visiblePending = await requestNodePairing({
797-
nodeId: visiblePendingNode.identity.deviceId,
798-
platform: "android",
799-
commands: ["device.status"],
800-
});
801-
802-
const ws = await openTrackedWs(getStarted().port);
803-
try {
804-
await connectOk(ws, {
805-
token: "secret",
806-
scopes: ["operator.read"],
807-
deviceIdentityPath: `${await makeNodePairingStateDir()}/read-only.sqlite`,
808-
});
809-
810-
type NodeDiagnostics = {
811-
nodeId: string;
812-
approvalState?: string;
813-
pendingRequestId?: string;
814-
pendingDeclaredCommands?: string[];
815-
};
816-
const listed = await rpcReq<{ nodes?: NodeDiagnostics[] }>(ws, "node.list", {});
817-
expect(listed.ok).toBe(true);
818-
const nodes = listed.payload?.nodes ?? [];
819-
// Pending surfaces now attach to paired devices, so the row is visible
820-
// to read-only callers but its approval target stays redacted.
821-
expect(nodes.find((node) => node.nodeId === pendingOnlyNodeId)).toEqual(
822-
expect.objectContaining({
823-
nodeId: pendingOnlyNodeId,
824-
approvalState: "pending-approval",
825-
}),
826-
);
827-
expect(nodes.find((node) => node.nodeId === pendingOnlyNodeId)).not.toHaveProperty(
828-
"pendingRequestId",
829-
);
830-
expect(nodes.find((node) => node.nodeId === pendingOnlyNodeId)).not.toHaveProperty(
831-
"pendingDeclaredCommands",
832-
);
833-
expect(nodes.find((node) => node.nodeId === pairedNodeId)).toEqual(
834-
expect.objectContaining({
835-
nodeId: pairedNodeId,
836-
approvalState: "pending-reapproval",
837-
}),
838-
);
839-
expect(nodes.find((node) => node.nodeId === pairedNodeId)).not.toHaveProperty(
840-
"pendingRequestId",
841-
);
842-
expect(nodes.find((node) => node.nodeId === pairedNodeId)).not.toHaveProperty(
843-
"pendingDeclaredCommands",
844-
);
845-
expect(nodes.find((node) => node.nodeId === visiblePendingNode.identity.deviceId)).toEqual(
846-
expect.objectContaining({
847-
nodeId: visiblePendingNode.identity.deviceId,
848-
approvalState: "pending-approval",
849-
}),
850-
);
851-
expect(
852-
nodes.find((node) => node.nodeId === visiblePendingNode.identity.deviceId),
853-
).not.toHaveProperty("pendingRequestId");
854-
expect(
855-
nodes.find((node) => node.nodeId === visiblePendingNode.identity.deviceId),
856-
).not.toHaveProperty("pendingDeclaredCommands");
857-
858-
const described = await rpcReq<NodeDiagnostics>(ws, "node.describe", {
859-
nodeId: pairedNodeId,
860-
});
861-
expect(described.payload).toEqual(
862-
expect.objectContaining({
863-
nodeId: pairedNodeId,
864-
approvalState: "pending-reapproval",
865-
}),
866-
);
867-
expect(described.payload).not.toHaveProperty("pendingRequestId");
868-
expect(described.payload).not.toHaveProperty("pendingDeclaredCommands");
869-
870-
const describedVisiblePending = await rpcReq<NodeDiagnostics>(ws, "node.describe", {
871-
nodeId: visiblePendingNode.identity.deviceId,
872-
});
873-
expect(describedVisiblePending.payload).toEqual(
874-
expect.objectContaining({
875-
nodeId: visiblePendingNode.identity.deviceId,
876-
approvalState: "pending-approval",
877-
}),
878-
);
879-
expect(describedVisiblePending.payload).not.toHaveProperty("pendingRequestId");
880-
expect(describedVisiblePending.payload).not.toHaveProperty("pendingDeclaredCommands");
881-
882-
const pendingOnly = await rpcReq<NodeDiagnostics>(ws, "node.describe", {
883-
nodeId: pendingOnlyNodeId,
884-
});
885-
expect(pendingOnly.ok).toBe(true);
886-
expect(pendingOnly.payload).not.toHaveProperty("pendingRequestId");
887-
expect(pendingOnly.payload).not.toHaveProperty("pendingDeclaredCommands");
888-
889-
const selfWs = await openTrackedWs(getStarted().port);
890-
try {
891-
await connectOk(selfWs, {
892-
token: "secret",
893-
scopes: ["operator.read"],
894-
deviceIdentityPath: visiblePendingNode.identityPath,
895-
});
896-
const selfListed = await rpcReq<{ nodes?: NodeDiagnostics[] }>(selfWs, "node.list", {});
897-
const selfNodes = selfListed.payload?.nodes ?? [];
898-
expect(
899-
selfNodes.find((node) => node.nodeId === visiblePendingNode.identity.deviceId),
900-
).toEqual(
901-
expect.objectContaining({
902-
approvalState: "pending-approval",
903-
pendingRequestId: visiblePending.request.requestId,
904-
}),
905-
);
906-
expect(selfNodes.find((node) => node.nodeId === pairedNodeId)).not.toHaveProperty(
907-
"pendingRequestId",
908-
);
909-
910-
const selfDescribed = await rpcReq<NodeDiagnostics>(selfWs, "node.describe", {
911-
nodeId: visiblePendingNode.identity.deviceId,
912-
});
913-
expect(selfDescribed.payload).toEqual(
914-
expect.objectContaining({
915-
approvalState: "pending-approval",
916-
pendingRequestId: visiblePending.request.requestId,
917-
}),
918-
);
919-
} finally {
920-
selfWs.close();
921-
}
922-
} finally {
923-
ws.close();
924-
}
925-
});
926-
});
927-
928720
describeWithGatewayServer("paired node reconnects", (getStarted) => {
929721
test("withholds plugin surface URLs until the node capability is approved", async () => {
930722
// The shared Gateway harness disables Canvas startup; expose its descriptor

0 commit comments

Comments
 (0)