Skip to content

Commit db3f25a

Browse files
committed
Device pairing: cover constrained setup code verification
1 parent 7b3630e commit db3f25a

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎src/infra/device-bootstrap.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,26 @@ describe("device bootstrap tokens", () => {
238238
).resolves.toEqual({ ok: false, reason: "bootstrap_token_invalid" });
239239
});
240240

241+
it("accepts constrained tokens when the requested role and scopes match", async () => {
242+
const baseDir = await createTempDir();
243+
const issued = await issueDeviceBootstrapToken({
244+
baseDir,
245+
role: "node",
246+
scopes: [],
247+
});
248+
249+
await expect(
250+
verifyDeviceBootstrapToken({
251+
token: issued.token,
252+
deviceId: "device-123",
253+
publicKey: "public-key-123",
254+
role: "node",
255+
scopes: [],
256+
baseDir,
257+
}),
258+
).resolves.toEqual({ ok: true });
259+
});
260+
241261
it("rejects scopes that do not match the issued pairing profile", async () => {
242262
const baseDir = await createTempDir();
243263
const issued = await issueDeviceBootstrapToken({

‎src/infra/device-bootstrap.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ export async function verifyDeviceBootstrapToken(params: {
124124
}
125125
if (Array.isArray(entry.scopes)) {
126126
const allowedScopes = normalizeDeviceAuthScopes(entry.scopes);
127+
// Both arrays are normalized through normalizeDeviceAuthScopes, which
128+
// sorts and deduplicates them before comparison.
127129
if (
128130
allowedScopes.length !== requestedScopes.length ||
129131
allowedScopes.some((value, index) => value !== requestedScopes[index])

0 commit comments

Comments
 (0)