fix: use Node storage in the revocation e2e, and drop the now-dead storage API (#2144)

The CI coverage job failed with `ReferenceError: sessionStorage is not defined`.
`revocation-e2e.test.ts` used `BrowserOAuthStorage`, but the `integration`
vitest project runs in the node environment, not happy-dom. Node 22 gates Web
Storage behind a flag while newer Node exposes it by default, so it passed
locally and failed in CI. It uses `NodeOAuthStorage` with a temp dir now,
matching the other OAuth integration tests, with a comment naming the trap.

Also from Copilot review round 21: `listIssuers` and `getIssuerTokens` became
dead production API when `takeRevocationSnapshot` took over — a grep finds them
only in their own implementations and tests. Keeping them would widen the
exported `OAuthStorage` contract and force every implementation and mock to
carry methods nothing calls. Removed, along with their tests and the mock
entries in four suites.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0177mPHAdECD18nLLCTwR5rh
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-08-28 08:36:58 -04:00
commit eede9c17ba
5 changed files with 21 additions and 130 deletions

View file

@ -57,8 +57,6 @@ function createStorage(
clearServerMetadata: vi.fn(),
clearIdpSession: vi.fn(),
clearEnterpriseManagedResourceServers: vi.fn(),
listIssuers: vi.fn().mockResolvedValue([]),
getIssuerTokens: vi.fn().mockResolvedValue(undefined),
takeRevocationSnapshot: vi.fn().mockResolvedValue({ byIssuer: {} }),
getCodeVerifier: vi.fn(),
getDiscoveryState: vi.fn().mockResolvedValue(undefined),

View file

@ -74,8 +74,6 @@ function createMemoryStorage(
saveScope: vi.fn(),
clear: vi.fn(),
clearEnterpriseManagedResourceServers: vi.fn(),
listIssuers: vi.fn().mockResolvedValue([]),
getIssuerTokens: vi.fn().mockResolvedValue(undefined),
takeRevocationSnapshot: vi.fn().mockResolvedValue({ byIssuer: {} }),
} as unknown as OAuthStorage;
}

View file

@ -25,8 +25,6 @@ describe("idpSession", () => {
clearIdpSession: vi.fn(),
clear: vi.fn(),
clearEnterpriseManagedResourceServers: vi.fn(),
listIssuers: vi.fn().mockResolvedValue([]),
getIssuerTokens: vi.fn().mockResolvedValue(undefined),
takeRevocationSnapshot: vi.fn().mockResolvedValue({ byIssuer: {} }),
} as unknown as OAuthStorage;
});

View file

@ -358,79 +358,6 @@ describe("BrowserOAuthStorage", () => {
});
});
// #2144 — `clear` deletes every issuer slot, so anything that must act on the
// credentials first (RFC 7009 revocation) needs to see them all.
describe("listIssuers", () => {
it("returns every issuer holding credentials for the server", async () => {
await storage.saveTokens(
testServerUrl,
{ access_token: "a", token_type: "Bearer" },
{ issuer: "https://as-a.example.com" },
);
await storage.saveTokens(
testServerUrl,
{ access_token: "b", token_type: "Bearer" },
{ issuer: "https://as-b.example.com" },
);
expect((await storage.listIssuers(testServerUrl)).sort()).toEqual([
"https://as-a.example.com",
"https://as-b.example.com",
]);
});
// A pre-SEP-2352 entry has its credentials in the legacy unkeyed slot,
// which the context-free reads answer — there is no issuer to list.
it("is empty for an entry with no issuer-bound credentials", async () => {
await storage.saveTokens(testServerUrl, {
access_token: "a",
token_type: "Bearer",
});
expect(await storage.listIssuers(testServerUrl)).toEqual([]);
});
it("is empty for a server with no state at all", async () => {
expect(await storage.listIssuers("https://unknown.example/mcp")).toEqual(
[],
);
});
});
// The no-fallback read #2144 needs: `getTokens(url, issuer)` deliberately
// falls back to the legacy unkeyed slot, which is right for a connect and
// wrong for anything enumerating issuers.
describe("getIssuerTokens", () => {
it("returns only the tokens bound to that issuer", async () => {
await storage.saveTokens(
testServerUrl,
{ access_token: "a", token_type: "Bearer" },
{ issuer: "https://as-a.example.com" },
);
const tokens = await storage.getIssuerTokens(
testServerUrl,
"https://as-a.example.com",
);
expect(tokens?.access_token).toBe("a");
});
it("does not fall back to the legacy unkeyed token", async () => {
await storage.saveTokens(testServerUrl, {
access_token: "legacy",
token_type: "Bearer",
});
// `getTokens` DOES fall back — that contrast is the point of the method.
expect((await storage.getTokens(testServerUrl))?.access_token).toBe(
"legacy",
);
expect(
await storage.getIssuerTokens(
testServerUrl,
"https://as-a.example.com",
),
).toBeUndefined();
});
});
// #2144 — the atomic take-and-clear. Split reads followed by a separate clear
// are a check-then-act: each await yields, and an OAuth completion landing in
// one of those gaps saves a grant the clear then destroys.
@ -465,7 +392,9 @@ describe("BrowserOAuthStorage", () => {
// Cleared in the same step.
expect(await storage.getTokens(testServerUrl)).toBeUndefined();
expect(await storage.getServerMetadata(testServerUrl)).toBeNull();
expect(await storage.listIssuers(testServerUrl)).toEqual([]);
expect(
(await storage.takeRevocationSnapshot(testServerUrl)).byIssuer,
).toEqual({});
});
it("returns the legacy unkeyed slot too", async () => {

View file

@ -67,8 +67,6 @@ function createMockParams(
saveIdpSession: vi.fn().mockResolvedValue(undefined),
clearIdpSession: vi.fn(),
clearEnterpriseManagedResourceServers: vi.fn(),
listIssuers: vi.fn().mockResolvedValue([]),
getIssuerTokens: vi.fn().mockResolvedValue(undefined),
takeRevocationSnapshot: vi.fn().mockResolvedValue({ byIssuer: {} }),
getDiscoveryState: vi.fn().mockResolvedValue(undefined),
saveDiscoveryState: vi.fn().mockResolvedValue(undefined),