File size: 1,346 Bytes
87dab07 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import { describe, expect, it } from "vitest";
import { classifyGatewaySecret } from "../../ui/src/lib/gateway-secret-shape.ts";
import { encodePairingSetupCode } from "./setup-code.js";
const setupCode = encodePairingSetupCode({
url: "wss://gateway.example/日本語",
bootstrapToken: "synthetic-bootstrap-token",
expiresAtMs: 1,
});
describe("classifyGatewaySecret", () => {
it.each([setupCode, `oc-pair://${setupCode}`, ` OC-PAIR://${setupCode}\n`])(
"recognizes encoded setup payloads even after expiry",
(value) => expect(classifyGatewaySecret(value)).toBe("setup-code"),
);
it.each([
"",
" ",
"ordinary-gateway-token",
"a".repeat(43), // Device tokens cannot be distinguished from configured shared tokens.
Buffer.from("random bytes, not JSON").toString("base64url"),
"oc-pair://not-a-setup-code",
...[
null,
[],
{},
{ url: "wss://gateway.example" },
{ bootstrapToken: "fake" },
{ url: "wss://gateway.example", bootstrapToken: 1 },
{ url: "", bootstrapToken: "fake" },
{ url: "wss://gateway.example", bootstrapToken: " " },
].map((value) => Buffer.from(JSON.stringify(value)).toString("base64url")),
])("leaves unrelated or malformed values unknown", (value) => {
expect(classifyGatewaySecret(value)).toBe("unknown");
});
});
|