testing/cross_backend/token_lifetime.ts

Cross-backend parity suite for the API token lifetime axis of account_token_create — the round-trip that keeps a one-sided landing impossible.

Why this suite exists

The action-manifest parity gate captures {method, side_effects, auth} and no param schemas, while the TS spine validates params against a strict object and the Rust spine hand-parses with params.get(...). So a spine that silently ignored the lifetime field would answer the same mint request with a 200 and an eternal token — same method, same status, nothing red anywhere. The forcing function has to observe the *stored* state: mint with a TTL, then read expires_at back off the wire.

What it pins

  • A TTL mint stores a bounded expiry — account_token_create with {kind:'ttl', days} returns a non-null expires_at (create output *and* account_token_list), landing within a generous window around now + days. A spine that dropped the field returns null and fails.
  • An eternal mint stores NULL — the control: {kind:'eternal'} yields expires_at: null on both reads.
  • An omitted lifetime is refused — lifetime is required; a mint without it must 400 invalid_params on both spines. This is the direct pin on the silently-ignoring-unknown-shapes hazard.
  • Out-of-range days are refused — days: 0 400s identically, so the two hand-rolled bounds checks can't drift.
  • The name cap — the same blind spot on another field of the same mint: a name of exactly API_TOKEN_NAME_LENGTH_MAX UTF-16 code units mints and reads back whole, and one unit past it is invalid_params, with an astral-plane name at each side of the boundary so the two spines count the same unit.
  • The scope cap — MAX_TOKEN_SCOPE_BYTES counts UTF-8 bytes of the compact document on both spines, at mint and at read: a two-byte scope at the cap mints, authenticates as a bearer for a method it lists, and lists as N methods, though Postgres prints it past the cap, and so does an ASCII scope under the cap whose printed text is past it; one byte past the cap, far under it in UTF-16 code units, is invalid_params with ERROR_TOKEN_SCOPE_INVALID. A spine counting code units mints the one past the cap, and one measuring the printed scope::text fails the others closed — unreadable in the list, an anonymous bearer.
  • A token sent beside a winning daemon token is never used — the credential legs run daemon token → session cookie → bearer on both spines, the first that authenticates winning, so a request carrying the daemon token and a bearer never validates the bearer: its last_used_at stays null. A spine resolving the bearer first (or both) bumps it. The positive control is a second token used alone, read back with a last_used_at — sent after the first request, so once its touch is visible the first's would be too.
  • An invalid daemon token falls through to the bearer beside it — the daemon leg soft-fails a token that is not the current one, so the bearer leg still runs: the request authenticates on the token, which records its last use. A spine hard-failing the daemon token refuses the request; one stopping at the failed leg leaves the request anonymous.
view source

Declarations
#

2 declarations

describe_token_lifetime_cross_tests
#

TokenLifetimeCrossTestOptions
#

testing/cross_backend/token_lifetime.ts view source

TokenLifetimeCrossTestOptions import type {TokenLifetimeCrossTestOptions} from '@fuzdev/fuz_app/testing/cross_backend/token_lifetime.js';

Options for the token-lifetime parity suite. Ungated — the mint + list pair is on every spine's standard surface, so there is no capability flag (the sibling of identity_parity.ts rather than the cell suites).

setup_test

Per-test fixture-producing function (fresh keeper + db per call).

type (): Promise<TestFixture>

readonly
returns Promise<TestFixture>

rpc_path?

RPC endpoint path the methods are mounted on. Default /api/rpc.

type string

readonly

Depends on
#

Imported by
#