mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 18:54:58 +00:00
test(auth-profiles): dedupe oauth mode resolution setup
This commit is contained in:
@@ -38,6 +38,39 @@ describe("resolveApiKeyForProfile fallback to main agent", () => {
|
|||||||
await fs.rm(tmpDir, { recursive: true, force: true });
|
await fs.rm(tmpDir, { recursive: true, force: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function resolveOauthProfileForConfiguredMode(mode: "token" | "api_key") {
|
||||||
|
const profileId = "anthropic:default";
|
||||||
|
const store: AuthProfileStore = {
|
||||||
|
version: 1,
|
||||||
|
profiles: {
|
||||||
|
[profileId]: {
|
||||||
|
type: "oauth",
|
||||||
|
provider: "anthropic",
|
||||||
|
access: "oauth-token",
|
||||||
|
refresh: "refresh-token",
|
||||||
|
expires: Date.now() + 60_000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = await resolveApiKeyForProfile({
|
||||||
|
cfg: {
|
||||||
|
auth: {
|
||||||
|
profiles: {
|
||||||
|
[profileId]: {
|
||||||
|
provider: "anthropic",
|
||||||
|
mode,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
store,
|
||||||
|
profileId,
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
it("falls back to main agent credentials when secondary agent token is expired and refresh fails", async () => {
|
it("falls back to main agent credentials when secondary agent token is expired and refresh fails", async () => {
|
||||||
const profileId = "anthropic:claude-cli";
|
const profileId = "anthropic:claude-cli";
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
@@ -216,34 +249,7 @@ describe("resolveApiKeyForProfile fallback to main agent", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("accepts mode=token + type=oauth for legacy compatibility", async () => {
|
it("accepts mode=token + type=oauth for legacy compatibility", async () => {
|
||||||
const profileId = "anthropic:default";
|
const result = await resolveOauthProfileForConfiguredMode("token");
|
||||||
const store: AuthProfileStore = {
|
|
||||||
version: 1,
|
|
||||||
profiles: {
|
|
||||||
[profileId]: {
|
|
||||||
type: "oauth",
|
|
||||||
provider: "anthropic",
|
|
||||||
access: "oauth-token",
|
|
||||||
refresh: "refresh-token",
|
|
||||||
expires: Date.now() + 60_000,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = await resolveApiKeyForProfile({
|
|
||||||
cfg: {
|
|
||||||
auth: {
|
|
||||||
profiles: {
|
|
||||||
[profileId]: {
|
|
||||||
provider: "anthropic",
|
|
||||||
mode: "token",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
store,
|
|
||||||
profileId,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result?.apiKey).toBe("oauth-token");
|
expect(result?.apiKey).toBe("oauth-token");
|
||||||
});
|
});
|
||||||
@@ -281,34 +287,7 @@ describe("resolveApiKeyForProfile fallback to main agent", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("rejects true mode/type mismatches", async () => {
|
it("rejects true mode/type mismatches", async () => {
|
||||||
const profileId = "anthropic:default";
|
const result = await resolveOauthProfileForConfiguredMode("api_key");
|
||||||
const store: AuthProfileStore = {
|
|
||||||
version: 1,
|
|
||||||
profiles: {
|
|
||||||
[profileId]: {
|
|
||||||
type: "oauth",
|
|
||||||
provider: "anthropic",
|
|
||||||
access: "oauth-token",
|
|
||||||
refresh: "refresh-token",
|
|
||||||
expires: Date.now() + 60_000,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = await resolveApiKeyForProfile({
|
|
||||||
cfg: {
|
|
||||||
auth: {
|
|
||||||
profiles: {
|
|
||||||
[profileId]: {
|
|
||||||
provider: "anthropic",
|
|
||||||
mode: "api_key",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
store,
|
|
||||||
profileId,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result).toBeNull();
|
expect(result).toBeNull();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user