test: specify oauth profile ref ids

This commit is contained in:
Shakker
2026-05-12 01:27:02 +01:00
parent e9421bbdec
commit b46475a52b
+13 -8
View File
@@ -61,14 +61,21 @@ function isPathInsideOrEqual(parentDir: string, candidatePath: string): boolean
);
}
function expectOAuthProfileRefId(value: unknown): asserts value is string {
expect(typeof value).toBe("string");
if (typeof value !== "string") {
throw new Error("Expected OAuth profile ref id");
}
expect(value).toMatch(/^[a-f0-9]{32}$/);
}
function readPersistedOAuthRefId(agentDir: string, profileId: string): string {
const persisted = JSON.parse(fs.readFileSync(resolveAuthStorePath(agentDir), "utf8")) as {
profiles: Record<string, { oauthRef?: { id?: string } }>;
};
const refId = persisted.profiles[profileId]?.oauthRef?.id;
expect(typeof refId).toBe("string");
expect(refId?.length).toBeGreaterThan(0);
return String(refId);
expectOAuthProfileRefId(refId);
return refId;
}
function resolvePersistedOAuthSecretPath(refId: string): string {
@@ -127,8 +134,7 @@ function expectOpenClawCredentialsOAuthRef(
const ref = oauthRef as Record<string, unknown>;
expect(ref.source).toBe("openclaw-credentials");
expect(ref.provider).toBe(provider);
expect(typeof ref.id).toBe("string");
expect(String(ref.id).length).toBeGreaterThan(0);
expectOAuthProfileRefId(ref.id);
}
describe("promoteAuthProfileInOrder", () => {
@@ -858,9 +864,8 @@ describe("promoteAuthProfileInOrder", () => {
profiles: Record<string, { oauthRef?: { id?: string } }>;
};
const refId = persisted.profiles[profileId]?.oauthRef?.id;
expect(typeof refId).toBe("string");
expect(refId?.length).toBeGreaterThan(0);
const secretPath = resolvePersistedOAuthSecretPath(String(refId));
expectOAuthProfileRefId(refId);
const secretPath = resolvePersistedOAuthSecretPath(refId);
const secretFile = fs.readFileSync(secretPath, "utf8");
expect(secretFile).not.toContain("delete-access-token");
expect(secretFile).not.toContain("delete-refresh-token");