Q91: sign-in and renewal requests end on cancel or a stalled server
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bcab38f003
commit
6655982368
10 files changed
+140
-67
No files matched your search
@@ -10,6 +10,7 @@ import { AuthBrokerService } from "../../src/main/services/auth-broker-service";
|
||||
import { IntegrationKeyStore } from "../../src/main/services/integration-key-store";
|
||||
import { loadConfiguredProvider } from "../../src/main/services/provider-internal";
|
||||
import { resolveTurnCredential } from "../../src/main/services/provider-tool-turns/credential-resolver";
|
||||
import { stopRun, withRunControl } from "../../src/main/services/run-control";
|
||||
|
||||
const vault = { encryptSecret: (secret: string) => Buffer.from(secret, "utf8"), decryptSecret: (ciphertext: Buffer) => ciphertext.toString("utf8") };
|
||||
|
||||
@@ -57,6 +58,18 @@ describe("an expired sign-in is refreshed once, however many runs need it", () =
|
||||
h.connection.close();
|
||||
});
|
||||
|
||||
test("stopping one run ends its wait on the shared refresh; the other run still gets the new sign-in", async () => {
|
||||
const calls = rotatingTokenEndpoint();
|
||||
const h = expiredClaudePro();
|
||||
const stopped = withRunControl("run-stopped", () => h.resolve(), 60_000);
|
||||
const other = withRunControl("run-other", () => h.resolve(), 60_000);
|
||||
stopRun("run-stopped", "Stopped by the operator.");
|
||||
await expect(stopped).rejects.toThrow("Stopped by the operator.");
|
||||
expect((await other).accessToken).toBe("access-1");
|
||||
expect(calls).toEqual(["refresh-0"]);
|
||||
h.connection.close();
|
||||
});
|
||||
|
||||
test("a run that comes after the refresh uses the stored new sign-in", async () => {
|
||||
const calls = rotatingTokenEndpoint();
|
||||
const h = expiredClaudePro();
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import { oauthFetch, OAUTH_REQUEST_TIMEOUT_MS } from "../../src/main/services/oauth/oauth-fetch";
|
||||
import { ProviderHttpError } from "../../src/main/services/provider-http";
|
||||
|
||||
/** A server that accepts the connection and never answers, until the request is aborted. */
|
||||
function stalledServer(): void {
|
||||
vi.stubGlobal("fetch", (_url: string, init: RequestInit) => new Promise((_resolve, reject) => {
|
||||
init.signal?.addEventListener("abort", () => reject(new DOMException("aborted", "AbortError")), { once: true });
|
||||
}));
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
describe("sign-in and renewal requests end when they should", () => {
|
||||
test("cancelling a sign-in ends the wait on a stalled token exchange", async () => {
|
||||
stalledServer();
|
||||
const cancel = new AbortController();
|
||||
const pending = oauthFetch("https://auth.example.test/token", { method: "POST" }, cancel.signal);
|
||||
cancel.abort();
|
||||
await expect(pending).rejects.toThrow("Login cancelled");
|
||||
});
|
||||
|
||||
test("a stalled exchange or refresh fails as a timeout instead of waiting forever", async () => {
|
||||
vi.useFakeTimers();
|
||||
stalledServer();
|
||||
const pending = oauthFetch("https://auth.example.test/token", { method: "POST" }).catch((error: unknown) => error);
|
||||
await vi.advanceTimersByTimeAsync(OAUTH_REQUEST_TIMEOUT_MS);
|
||||
const failure = await pending;
|
||||
expect(failure).toBeInstanceOf(ProviderHttpError);
|
||||
expect(failure).toMatchObject({ timedOut: true, message: "Sign-in request to auth.example.test timed out." });
|
||||
});
|
||||
|
||||
test("a request that answers returns its status and body", async () => {
|
||||
vi.stubGlobal("fetch", async () => new Response("{\"ok\":true}", { status: 200 }));
|
||||
const { response, text } = await oauthFetch("https://auth.example.test/token", { method: "POST" });
|
||||
expect([response.status, text]).toEqual([200, "{\"ok\":true}"]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user