

























@@ -33,6 +33,22 @@ import {
33333434const operatorIdentityPathByPrefix = new Map<string, string>();
353536+function expectArrayIncludes(actual: unknown, expectedValues: string[]): void {
37+expect(Array.isArray(actual)).toBe(true);
38+const values = actual as unknown[];
39+for (const expected of expectedValues) {
40+expect(values).toContain(expected);
41+}
42+}
43+44+function expectArrayExcludes(actual: unknown, deniedValues: string[]): void {
45+expect(Array.isArray(actual)).toBe(true);
46+const values = actual as unknown[];
47+for (const denied of deniedValues) {
48+expect(values).not.toContain(denied);
49+}
50+}
51+3652export function registerControlUiAndPairingSuite(): void {
3753const trustedProxyControlUiCases: Array<{
3854name: string;
@@ -830,7 +846,7 @@ export function registerControlUiAndPairingSuite(): void {
830846(entry) => entry.deviceId === identity.deviceId,
831847);
832848expect(pendingAfterAdmin).toHaveLength(1);
833-expect(pendingAfterAdmin[0]?.scopes ?? []).toEqual(expect.arrayContaining(["operator.admin"]));
849+expectArrayIncludes(pendingAfterAdmin[0]?.scopes, ["operator.admin"]);
834850if (!(await getPairedDevice(identity.deviceId))) {
835851throw new Error(`expected paired device ${identity.deviceId}`);
836852}
@@ -868,7 +884,7 @@ export function registerControlUiAndPairingSuite(): void {
868884const pending = await listDevicePairing();
869885const pendingUpgrade = pending.pending.filter((entry) => entry.deviceId === identity.deviceId);
870886expect(pendingUpgrade).toHaveLength(1);
871-expect(pendingUpgrade[0]?.scopes ?? []).toEqual(expect.arrayContaining(["operator.admin"]));
887+expectArrayIncludes(pendingUpgrade[0]?.scopes, ["operator.admin"]);
872888const updated = await getPairedDevice(identity.deviceId);
873889expect(updated?.tokens?.operator?.scopes ?? []).not.toContain("operator.admin");
874890@@ -1023,39 +1039,35 @@ export function registerControlUiAndPairingSuite(): void {
10231039expect(initialPayload?.auth?.deviceTokens?.some((entry) => entry.role === "node")).toBe(
10241040false,
10251041);
1026-expect(
1027-initialPayload?.auth?.deviceTokens?.find((entry) => entry.role === "operator")?.scopes,
1028-).toEqual(
1029-expect.arrayContaining([
1030-"operator.approvals",
1031-"operator.read",
1032-"operator.talk.secrets",
1033-"operator.write",
1034-]),
1035-);
1036-expect(
1037-initialPayload?.auth?.deviceTokens?.find((entry) => entry.role === "operator")?.scopes,
1038-).not.toEqual(
1039-expect.arrayContaining(["node.camera", "node.display", "node.exec", "node.voice"]),
1040-);
1041-expect(
1042-initialPayload?.auth?.deviceTokens?.find((entry) => entry.role === "operator")?.scopes,
1043-).not.toEqual(expect.arrayContaining(["operator.admin", "operator.pairing"]));
1042+const operatorBootstrapScopes = initialPayload?.auth?.deviceTokens?.find(
1043+(entry) => entry.role === "operator",
1044+)?.scopes;
1045+expectArrayIncludes(operatorBootstrapScopes, [
1046+"operator.approvals",
1047+"operator.read",
1048+"operator.talk.secrets",
1049+"operator.write",
1050+]);
1051+expectArrayExcludes(operatorBootstrapScopes, [
1052+"node.camera",
1053+"node.display",
1054+"node.exec",
1055+"node.voice",
1056+]);
1057+expectArrayExcludes(operatorBootstrapScopes, ["operator.admin", "operator.pairing"]);
1044105810451059const afterBootstrap = await listDevicePairing();
10461060expect(
10471061afterBootstrap.pending.filter((entry) => entry.deviceId === identity.deviceId),
10481062).toEqual([]);
10491063const paired = await getPairedDevice(identity.deviceId);
1050-expect(paired?.roles).toEqual(expect.arrayContaining(["node", "operator"]));
1051-expect(paired?.approvedScopes ?? []).toEqual(
1052-expect.arrayContaining([
1053-"operator.approvals",
1054-"operator.read",
1055-"operator.talk.secrets",
1056-"operator.write",
1057-]),
1058-);
1064+expectArrayIncludes(paired?.roles, ["node", "operator"]);
1065+expectArrayIncludes(paired?.approvedScopes, [
1066+"operator.approvals",
1067+"operator.read",
1068+"operator.talk.secrets",
1069+"operator.write",
1070+]);
10591071expect(paired?.tokens?.node?.token).toBe(issuedDeviceToken);
10601072expect(paired?.tokens?.operator?.token).toBe(issuedOperatorToken);
10611073if (!issuedDeviceToken || !issuedOperatorToken) {
@@ -1278,7 +1290,7 @@ export function registerControlUiAndPairingSuite(): void {
12781290expect(pending[0]?.role).toBe("node");
12791291expect(pending[0]?.roles).toEqual(["node"]);
12801292const paired = await getPairedDevice(identity.deviceId);
1281-expect(paired?.roles).toEqual(expect.arrayContaining(["operator"]));
1293+expectArrayIncludes(paired?.roles, ["operator"]);
12821294wsUpgrade.close();
12831295} finally {
12841296await server.close();
@@ -1322,7 +1334,7 @@ export function registerControlUiAndPairingSuite(): void {
13221334);
13231335expect(pending).toHaveLength(1);
13241336expect(pending[0]?.role).toBe("operator");
1325-expect(pending[0]?.scopes ?? []).toEqual(expect.arrayContaining(["operator.read"]));
1337+expectArrayIncludes(pending[0]?.scopes, ["operator.read"]);
13261338expect(await getPairedDevice(identity.deviceId)).toBeNull();
13271339wsBootstrap.close();
13281340} finally {
@@ -1377,15 +1389,11 @@ export function registerControlUiAndPairingSuite(): void {
13771389(entry) => entry.deviceId === identity.deviceId,
13781390);
13791391expect(pendingForTestDevice).toHaveLength(1);
1380-expect(pendingForTestDevice[0]?.scopes ?? []).toEqual(
1381-expect.arrayContaining(["operator.read", "operator.write"]),
1382-);
1392+expectArrayIncludes(pendingForTestDevice[0]?.scopes, ["operator.read", "operator.write"]);
1383139313841394const paired = await getPairedDevice(identity.deviceId);
1385-expect(paired?.roles).toEqual(expect.arrayContaining(["node", "operator"]));
1386-expect(paired?.approvedScopes ?? []).toEqual(
1387-expect.arrayContaining(["operator.read", "operator.write"]),
1388-);
1395+expectArrayIncludes(paired?.roles, ["node", "operator"]);
1396+expectArrayIncludes(paired?.approvedScopes, ["operator.read", "operator.write"]);
1389139713901398const approvedOperatorConnect = await connectWithNonce("operator", ["operator.read"]);
13911399expect(approvedOperatorConnect.ok).toBe(true);
@@ -1576,10 +1584,10 @@ export function registerControlUiAndPairingSuite(): void {
15761584if (!pendingUpgrade) {
15771585throw new Error(`expected pending upgrade for device ${identity.deviceId}`);
15781586}
1579-expect(pendingUpgrade?.scopes ?? []).toEqual(expect.arrayContaining(["operator.admin"]));
1587+expectArrayIncludes(pendingUpgrade.scopes, ["operator.admin"]);
15801588const repaired = await getPairedDevice(identity.deviceId);
15811589expect(repaired?.role).toBe("operator");
1582-expect(repaired?.approvedScopes ?? []).toEqual(expect.arrayContaining(["operator.read"]));
1590+expectArrayIncludes(repaired?.approvedScopes, ["operator.read"]);
15831591} finally {
15841592ws2?.close();
15851593await server.close();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。