Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
473 changes: 473 additions & 0 deletions clients/web/src/test/core/auth/oauth-namespace-ledger.test.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ vi.mock("@inspector/core/auth/node/file-lock.js", async (importOriginal) => {

import {
writeOAuthSections,
removeOAuthStore,
SECRETS_NAMESPACE_KEY,
} from "@inspector/core/auth/node/oauth-persist-file.js";
import { recordNamespaceKeys } from "@inspector/core/auth/node/oauth-namespace-ledger.js";
import {
InMemorySecretStore,
SecretStoreUnavailableError,
Expand Down Expand Up @@ -173,3 +175,34 @@ describe("legacy adoption under a degraded (unlocked) file lock", () => {
).toMatchObject({ access_token: "at-second" });
});
});

describe("namespace-ledger purge under a degraded (unlocked) file lock (#2560)", () => {
const OTHER_NS = "11111111-2222-4333-8444-555555555555";

/** A recorded namespace holding a live entry, as a racing adopter leaves it. */
async function seedRecordedNamespace(): Promise<string> {
await recordNamespaceKeys(filePath, store, OTHER_NS, [SERVER], []);
const id = oauthSecretServerId(SERVER, OTHER_NS);
await store.set(id, LEGACY_TOKENS_FIELD, JSON.stringify(TOKENS));
return id;
}

it("a mint-only adoption does not purge recorded namespaces", async () => {
// Unlocked, a recorded-but-unstamped namespace may be a concurrent
// adopter's, so its entries must survive.
const id = await seedRecordedNamespace();
await writeOAuthSections(filePath, snapshotFor("fresh"), undefined, store);
await flushStoreFileWrites(filePath);
expect(await store.get(id, LEGACY_TOKENS_FIELD)).toBe(
JSON.stringify(TOKENS),
);
});

it("an unlocked removal does not purge recorded namespaces", async () => {
const id = await seedRecordedNamespace();
await removeOAuthStore(filePath, store);
expect(await store.get(id, LEGACY_TOKENS_FIELD)).toBe(
JSON.stringify(TOKENS),
);
});
});
Loading
Loading