Device pairing: cover constrained setup code verification

This commit is contained in:
Vincent Koc 2026-03-14 23:19:20 -07:00
parent 7b3630e310
commit db3f25ae75
2 changed files with 22 additions and 0 deletions

View File

@ -238,6 +238,26 @@ describe("device bootstrap tokens", () => {
).resolves.toEqual({ ok: false, reason: "bootstrap_token_invalid" });
});
it("accepts constrained tokens when the requested role and scopes match", async () => {
const baseDir = await createTempDir();
const issued = await issueDeviceBootstrapToken({
baseDir,
role: "node",
scopes: [],
});
await expect(
verifyDeviceBootstrapToken({
token: issued.token,
deviceId: "device-123",
publicKey: "public-key-123",
role: "node",
scopes: [],
baseDir,
}),
).resolves.toEqual({ ok: true });
});
it("rejects scopes that do not match the issued pairing profile", async () => {
const baseDir = await createTempDir();
const issued = await issueDeviceBootstrapToken({

View File

@ -124,6 +124,8 @@ export async function verifyDeviceBootstrapToken(params: {
}
if (Array.isArray(entry.scopes)) {
const allowedScopes = normalizeDeviceAuthScopes(entry.scopes);
// Both arrays are normalized through normalizeDeviceAuthScopes, which
// sorts and deduplicates them before comparison.
if (
allowedScopes.length !== requestedScopes.length ||
allowedScopes.some((value, index) => value !== requestedScopes[index])