testing/cross_backend/fact_serving.ts

Cross-backend fact-serving parity suite — the per-reference (cell-scoped) read model over real HTTP.

Re-proves the D1 fact-access cases (docs/security.md § Fact Access Control) against each backend's real auth resolution, twinning fuz_app's server/serve_fact_route.ts and the Rust fuz_fact_serving routers:

  • cell-scoped admit — anon reads a fact through a viewable (public) referencing cell → 200 + bytes;
  • cross-owner dedup does not leak — A's *private* reference to bytes that B *also* publishes from a *public* cell stays 404 for everyone but A, even though the identical bytes are world-readable via B's cell (one deduped fact row; authz lives on the (cell, hash) edge, never unioned);
  • 404-mask — a missing cell and a viewable cell that doesn't reference the hash both 404 (never 403, never "exists elsewhere"), and every masked 404 is bodyless, so its shape names no branch;
  • unviewable cell hides its refs — for a private cell the caller can't view, a hash it references and one it doesn't answer the same masked 404 (the view check runs first, so the work done is the same too — each spine's own suite pins that order);
  • hardening headers — a served fact carries `X-Content-Type-Options: nosniff, the default-src 'none'; sandbox CSP, and Cache-Control: private, max-age=300`, whatever its content type;
  • bare-hash admin-only — GET /api/facts/:hash is admin (keeper) only: non-admin → 403, anonymous → 401 (gated on fact_serving_admin_hash too);
  • URL bound to hash — a row whose external_url is a well-formed file: URL naming another hash's file is a masked 404 on both routes, refused before any disk read (each spine's unit suite proves the bytes behind such a URL never serve);
  • missing disk file — a row whose file: URL addresses its own hash but whose file isn't on disk is a masked 404 (opened before any 200 commits; needs a backend serving external facts from disk, not by X-Accel);
  • multi-actor fallthrough — a multi-actor caller resolves to a null (anonymous) context on the (acting-less) cell-scoped route, so it can't read its own *private* fact there (admitted only by public cells). Opt-in (needs the multi-actor setup); every spine resolves the acting actor at the dispatcher's authorization phase from account-grain credentials, so the multi-actor account is drivable on TS and Rust alike;
  • narrowed-token downgrade — a scope-narrowed API token on the cell-scoped route is anonymous, not refused: its owner's private fact 404s exactly as for an anonymous caller, while a public cell still serves.

Facts are seeded embedded via _testing_put_fact (the cross-process driver has no DB handle), or as a bare external row through its external_url; the referencing cell via the cell_create RPC (the hash, a whole string value in data, is derived into cell.refs). A non-admin owner's cell may reference only a fact it holds, so a fact a non-admin references is put with that owner as its holder (the keeper is a global admin, whom ref admission doesn't gate). Gated on capabilities.fact_serving (the cell-gated route + the seeder), the bare-hash cases on capabilities.fact_serving_admin_hash as well, so a backend serving only the cell-gated route runs the rest; runs under every cross_backend_* project — the TS spine binary and the Rust testing_spine_stub both mount both routes + the seeder.

view source

Declarations
#

4 declarations

cross_put_fact
#

testing/cross_backend/fact_serving.ts view source

(fixture: Pick<TestFixture, "fresh_transport" | "create_daemon_token_headers">, rpc_path: string, input: CrossPutFactInput): Promise<...> import {cross_put_fact} from '@fuzdev/fuz_app/testing/cross_backend/fact_serving.js';

Seed an embedded fact over the daemon channel via _testing_put_fact; returns its blake3: hash. A holder is recorded in fact_holder (a deduplicated put included), as a real upload records its uploader.

fixture

the test fixture (its daemon token drives the backdoor)

type Pick<TestFixture, "fresh_transport" | "create_daemon_token_headers">

rpc_path

the backend's RPC path

type string

input

the content, optional content type, and optional holder

returns

Promise<string>

the fact hash

CrossPutFactInput
#

testing/cross_backend/fact_serving.ts view source

CrossPutFactInput import type {CrossPutFactInput} from '@fuzdev/fuz_app/testing/cross_backend/fact_serving.js';

Input for cross_put_fact — _testing_put_fact's params.

content

type string

readonly

content_type?

type string

readonly

holder?

The actor the put is on behalf of — recorded as a holder. Omit for a system put.

type string

readonly

external_url?

Store an external row naming this URL, verbatim and with no bytes, instead of an embedded one.

type string

readonly

describe_fact_serving_cross_tests
#

FactServingCrossTestOptions
#

testing/cross_backend/fact_serving.ts view source

FactServingCrossTestOptions import type {FactServingCrossTestOptions} from '@fuzdev/fuz_app/testing/cross_backend/fact_serving.js';

The fact suite adds one optional knob to the shared cell options: a setup variant whose keeper carries a second actor. Only the multi-actor case needs it; the rest of the suite runs single-actor, so wiring it is opt-in. Omit it and the multi-actor case silently skips.

inheritance

setup_test_multi_actor?

type (): Promise<TestFixture>

readonly
returns Promise<TestFixture>

Depends on
#

Imported by
#