Named revocation-conflict tests on pg-mem, first-create doc line, npm fallback in test-live-pg
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f7a38a7d2a
commit
b6372e5a4f
3 changed files with 40 additions and 3 deletions
|
|
@ -164,7 +164,9 @@ the least stored.
|
|||
holds ids, scopes and a digest: no IP address, no user agent, no page text. A revocation names a
|
||||
receipt of its own account: a composite foreign key `(revokes_receipt_id,
|
||||
account_id)` to `(id, account_id)`, which is why `(id, account_id)` is also a
|
||||
unique key (`checkSchema` counts it). The in-memory store refuses the same.
|
||||
unique key (`checkSchema` counts it). The in-memory store refuses the same. The table is created
|
||||
whole and first-created: no deployed database had an earlier shape, so there
|
||||
is no `ALTER` step.
|
||||
Refusals leave no receipt, only the anonymous audit row.
|
||||
3. **Viewer identity: sign-in, not the cookie.** The binding cookie dies with
|
||||
the state and proves only that a browser launched a flow; it is not an
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@ set -euo pipefail
|
|||
# 2. its npm dependencies installed (the vendor packages build with its tsc),
|
||||
# 3. dist/ built for cultcache-ts, cultnet-ts and cultmesh-ts (package.json
|
||||
# points main at dist/index.js),
|
||||
# 4. this repo's pnpm install.
|
||||
# 4. this repo's pnpm install (npm install if pnpm fails with EACCES).
|
||||
cd "$(dirname "$0")/.."
|
||||
[ -f vendor/CultLib/package.json ] || git submodule update --init vendor/CultLib
|
||||
[ -d vendor/CultLib/node_modules/typescript ] || (cd vendor/CultLib && npm ci)
|
||||
for pkg in cultcache-ts cultnet-ts cultmesh-ts; do
|
||||
[ -f "vendor/CultLib/packages/$pkg/dist/index.js" ] || (cd "vendor/CultLib/packages/$pkg" && npm run build)
|
||||
done
|
||||
[ -d node_modules/vitest ] || pnpm install --frozen-lockfile
|
||||
[ -d node_modules/vitest ] || pnpm install --frozen-lockfile || npm install # pnpm can fail with EACCES on its store; npm does not need it
|
||||
export PATH="${PG_BIN:-/usr/lib/postgresql/16/bin}:$PATH"
|
||||
dir="$(mktemp -d)"
|
||||
port="${PG_PORT:-54329}"
|
||||
|
|
|
|||
|
|
@ -210,6 +210,41 @@ describe("consent_receipts foreign key", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("PostgresStore.createConsentReceipt revocation conflict", () => {
|
||||
async function granted() {
|
||||
const adapter = newDb().adapters.createPg();
|
||||
const store = new PostgresStore(new adapter.Pool());
|
||||
await store.ensureSchema();
|
||||
const now = "2026-11-08T00:00:00.000Z";
|
||||
const account = await store.createAccount({ createdAt: now, lastSeenAt: now, displayName: "Probe" });
|
||||
const base = { accountId: account.id, appSlug: "streampixels" as const, provider: "joystick" as const };
|
||||
const { receipt: grant } = await store.createConsentReceipt({ ...base, kind: "grant", createdAt: now, scopesAsked: ["a"], scopesGranted: ["a"], consentPageDigest: "d", consentText: "t" });
|
||||
return { store, base, grant };
|
||||
}
|
||||
|
||||
it("a second revocation of one grant inserts nothing: created:false, the first row's id", async () => {
|
||||
const { store, base, grant } = await granted();
|
||||
const first = await store.createConsentReceipt({ ...base, kind: "revocation", createdAt: "2026-11-08T01:00:00.000Z", revokesReceiptId: grant.id });
|
||||
const second = await store.createConsentReceipt({ ...base, kind: "revocation", createdAt: "2026-11-08T02:00:00.000Z", revokesReceiptId: grant.id });
|
||||
expect(first.created).toBe(true);
|
||||
expect(second.created).toBe(false);
|
||||
expect(second.receipt.id).toBe(first.receipt.id);
|
||||
expect(second.receipt.createdAt).toBe("2026-11-08T01:00:00.000Z");
|
||||
expect((await store.listConsentReceipts(base.accountId)).filter((r) => r.kind === "revocation")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("the read-back returns the revocation of this grant, not another's or the grant", async () => {
|
||||
const { store, base, grant } = await granted();
|
||||
const other = (await store.createConsentReceipt({ ...base, kind: "grant", createdAt: "2026-11-08T00:30:00.000Z", scopesAsked: [], scopesGranted: [], consentPageDigest: "d2", consentText: "t2" })).receipt;
|
||||
const otherRevocation = await store.createConsentReceipt({ ...base, kind: "revocation", createdAt: "2026-11-08T01:00:00.000Z", revokesReceiptId: other.id });
|
||||
const first = await store.createConsentReceipt({ ...base, kind: "revocation", createdAt: "2026-11-08T01:10:00.000Z", revokesReceiptId: grant.id });
|
||||
const second = await store.createConsentReceipt({ ...base, kind: "revocation", createdAt: "2026-11-08T02:00:00.000Z", revokesReceiptId: grant.id });
|
||||
expect(second.receipt.id).toBe(first.receipt.id);
|
||||
expect(second.receipt.id).not.toBe(otherRevocation.receipt.id);
|
||||
expect(second.receipt.revokesReceiptId).toBe(grant.id);
|
||||
});
|
||||
});
|
||||
|
||||
describe("InMemoryStore.createConsentReceipt", () => {
|
||||
it("writes one revocation per grant: the second names the first and is not created", async () => {
|
||||
const store = new InMemoryStore();
|
||||
|
|
|
|||
Loading…
Reference in a new issue