mirror of https://github.com/openclaw/openclaw.git
Device pairing: cover constrained setup code verification
This commit is contained in:
parent
7b3630e310
commit
db3f25ae75
|
|
@ -238,6 +238,26 @@ describe("device bootstrap tokens", () => {
|
||||||
).resolves.toEqual({ ok: false, reason: "bootstrap_token_invalid" });
|
).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 () => {
|
it("rejects scopes that do not match the issued pairing profile", async () => {
|
||||||
const baseDir = await createTempDir();
|
const baseDir = await createTempDir();
|
||||||
const issued = await issueDeviceBootstrapToken({
|
const issued = await issueDeviceBootstrapToken({
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,8 @@ export async function verifyDeviceBootstrapToken(params: {
|
||||||
}
|
}
|
||||||
if (Array.isArray(entry.scopes)) {
|
if (Array.isArray(entry.scopes)) {
|
||||||
const allowedScopes = normalizeDeviceAuthScopes(entry.scopes);
|
const allowedScopes = normalizeDeviceAuthScopes(entry.scopes);
|
||||||
|
// Both arrays are normalized through normalizeDeviceAuthScopes, which
|
||||||
|
// sorts and deduplicates them before comparison.
|
||||||
if (
|
if (
|
||||||
allowedScopes.length !== requestedScopes.length ||
|
allowedScopes.length !== requestedScopes.length ||
|
||||||
allowedScopes.some((value, index) => value !== requestedScopes[index])
|
allowedScopes.some((value, index) => value !== requestedScopes[index])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue