fix(auth): reject load() when persist read fails
This commit is contained in:
parent
a24091484c
commit
512f45d357
2 changed files with 91 additions and 10 deletions
|
|
@ -2191,7 +2191,15 @@ function App() {
|
|||
}
|
||||
|
||||
void (async () => {
|
||||
await webOAuthStorage.load();
|
||||
try {
|
||||
await webOAuthStorage.load();
|
||||
} catch (err) {
|
||||
connectStartRef.current = undefined;
|
||||
queueMicrotask(() => {
|
||||
showReAuthBanner(server.id, err instanceof Error ? err : String(err));
|
||||
});
|
||||
return;
|
||||
}
|
||||
const client = setupClientForServer(server, sessionId);
|
||||
setActiveServerId(server.id);
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
import { describe, it, expect, beforeEach, vi } from "vitest";
|
||||
import { RemoteOAuthStorage } from "@inspector/core/auth/remote/storage-remote.js";
|
||||
import {
|
||||
type OAuthStore,
|
||||
waitForOAuthStorePersistLoad,
|
||||
} from "@inspector/core/auth/store.js";
|
||||
|
||||
const NOOP_FETCH = vi.fn(
|
||||
async () =>
|
||||
|
|
@ -121,6 +125,12 @@ describe("RemoteOAuthStorage (unit, mocked fetch)", () => {
|
|||
expect(s).toBeInstanceOf(RemoteOAuthStorage);
|
||||
});
|
||||
|
||||
it("waitForOAuthStorePersistLoad resolves for an unregistered store handle", async () => {
|
||||
await expect(
|
||||
waitForOAuthStorePersistLoad({} as OAuthStore),
|
||||
).resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
it("load() waits for remote GET before sync reads see persisted state", async () => {
|
||||
const persisted = {
|
||||
state: {
|
||||
|
|
@ -155,4 +165,20 @@ describe("RemoteOAuthStorage (unit, mocked fetch)", () => {
|
|||
"persisted-verifier",
|
||||
);
|
||||
});
|
||||
|
||||
it("load() rejects when remote GET fails instead of hanging", async () => {
|
||||
const failingFetch = vi.fn(
|
||||
async () => new Response("server error", { status: 500 }),
|
||||
) as unknown as typeof fetch;
|
||||
|
||||
const failingStorage = new RemoteOAuthStorage({
|
||||
baseUrl: "http://remote.example",
|
||||
storeId: `fail-${Math.random().toString(36).slice(2)}`,
|
||||
fetchFn: failingFetch,
|
||||
});
|
||||
|
||||
await expect(failingStorage.load()).rejects.toThrow(
|
||||
"Failed to read store: 500",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue