mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 21:04:33 +00:00
fix(auth): distinguish revoked API keys from transient auth errors (#25754)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 8f9c07a200
Co-authored-by: rrenamed <87486610+rrenamed@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
committed by
GitHub
parent
f312222159
commit
c0026274d9
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
classifyFailoverReason,
|
||||
isAuthErrorMessage,
|
||||
isAuthPermanentErrorMessage,
|
||||
isBillingErrorMessage,
|
||||
isCloudCodeAssistFormatError,
|
||||
isCloudflareOrHtmlErrorPage,
|
||||
@@ -16,6 +17,39 @@ import {
|
||||
parseImageSizeError,
|
||||
} from "./pi-embedded-helpers.js";
|
||||
|
||||
describe("isAuthPermanentErrorMessage", () => {
|
||||
it("matches permanent auth failure patterns", () => {
|
||||
const samples = [
|
||||
"invalid_api_key",
|
||||
"api key revoked",
|
||||
"api key deactivated",
|
||||
"key has been disabled",
|
||||
"key has been revoked",
|
||||
"account has been deactivated",
|
||||
"could not authenticate api key",
|
||||
"could not validate credentials",
|
||||
"API_KEY_REVOKED",
|
||||
"api_key_deleted",
|
||||
];
|
||||
for (const sample of samples) {
|
||||
expect(isAuthPermanentErrorMessage(sample)).toBe(true);
|
||||
}
|
||||
});
|
||||
it("does not match transient auth errors", () => {
|
||||
const samples = [
|
||||
"unauthorized",
|
||||
"invalid token",
|
||||
"authentication failed",
|
||||
"forbidden",
|
||||
"access denied",
|
||||
"token has expired",
|
||||
];
|
||||
for (const sample of samples) {
|
||||
expect(isAuthPermanentErrorMessage(sample)).toBe(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("isAuthErrorMessage", () => {
|
||||
it("matches credential validation errors", () => {
|
||||
const samples = [
|
||||
@@ -480,6 +514,12 @@ describe("classifyFailoverReason", () => {
|
||||
),
|
||||
).toBe("rate_limit");
|
||||
});
|
||||
it("classifies permanent auth errors as auth_permanent", () => {
|
||||
expect(classifyFailoverReason("invalid_api_key")).toBe("auth_permanent");
|
||||
expect(classifyFailoverReason("Your api key has been revoked")).toBe("auth_permanent");
|
||||
expect(classifyFailoverReason("key has been disabled")).toBe("auth_permanent");
|
||||
expect(classifyFailoverReason("account has been deactivated")).toBe("auth_permanent");
|
||||
});
|
||||
it("classifies JSON api_error internal server failures as timeout", () => {
|
||||
expect(
|
||||
classifyFailoverReason(
|
||||
|
||||
Reference in New Issue
Block a user