testing/data_exposure.ts

Composable data exposure test suite.

Verifies that sensitive database fields never leak through HTTP responses:

  • Schema-level: walks the JSON Schema of every route, RPC, and WebSocket output (both sides of a transform), the params the server pushes over WebSocket, and every route error schema for sensitive property names, and non-admin route outputs for admin-only ones
  • Runtime: fires real requests and checks response bodies against field blocklists
  • Cross-privilege: verifies admin routes return 403 for non-admin users, and non-admin responses exclude admin-only fields

Cadence: per-describe setup_test() call (see testing/round_trip.ts module docstring). The runtime body manages its own request ordering (auth-free → cross-privilege → 2xx) to avoid session-invalidation contamination between assertions, so per-test fixture re-creation isn't needed.

view source

Declarations
#

5 declarations

assert_non_admin_schemas_no_admin_fields
#

testing/data_exposure.ts view source

(surface_source: AppSurfaceSpec, admin_only_fields?: readonly string[], skip_routes?: readonly string[] | undefined): void import {assert_non_admin_schemas_no_admin_fields} from '@fuzdev/fuz_app/testing/data_exposure.js';

Assert that route output schemas a non-admin can reach — routes without an admin or keeper gate — don't contain admin-only field names. Reads both sides of each output, as assert_output_schemas_no_sensitive_fields does.

Routes only: the default blocklist matches by name (created_by, updated_by), and RPC and WebSocket methods return domain shapes that carry those columns legitimately (cells, invites a member created).

surface_source

the surface with the specs it was generated from

admin_only_fields?

field names no non-admin route output may carry

type readonly string[]
optional default admin_only_field_blocklist

skip_routes?

routes to skip, as 'METHOD /path'

type readonly string[]
optional

returns

void

throws

  • Error - when an output schema can't be written as JSON Schema on either side

assert_output_schemas_no_sensitive_fields
#

testing/data_exposure.ts view source

(surface_source: AppSurfaceSpec, sensitive_fields?: readonly string[], skip_routes?: readonly string[] | undefined): void import {assert_output_schemas_no_sensitive_fields} from '@fuzdev/fuz_app/testing/data_exposure.js';

Assert that no output schema — of a route, an RPC method, or a WebSocket method, or the params of a message the server pushes over WebSocket (a remote_notification, or a request_response the backend initiates) — contains sensitive field names.

Each output is read on both sides (schema_to_surface): the output side the surface records, and the input side, since a transform's output has no JSON Schema form and a field inside a transformed subtree shows only there. The input side is a superset, so a transform that deliberately drops a sensitive field is flagged too; skip that output by its key.

surface_source

the surface with the specs it was generated from

sensitive_fields?

field names no output may carry

type readonly string[]
optional default sensitive_field_blocklist

skip_routes?

outputs to skip: 'METHOD /path' for a route, '/path method_name' for an RPC or WS method, '/path method_name params' for pushed params

type readonly string[]
optional

returns

void

throws

  • Error - when an output schema can't be written as JSON Schema on either side

collect_json_schema_property_names
#

testing/data_exposure.ts view source

(schema: unknown): Set<string> import {collect_json_schema_property_names} from '@fuzdev/fuz_app/testing/data_exposure.js';

Recursively collect all property names from a JSON Schema.

Walks properties, patternProperties, additionalProperties, items, prefixItems, contains, allOf/anyOf/oneOf, not/if/then/else, and the values of $defs/definitions (where a recursive or registered schema's body sits behind a $ref) to find every declared field name at any depth.

schema

type unknown

returns

Set<string>

DataExposureTestOptions
#

testing/data_exposure.ts view source

DataExposureTestOptions import type {DataExposureTestOptions} from '@fuzdev/fuz_app/testing/data_exposure.js';

setup_test

Per-test fixture-producing function (per-describe cadence).

type (): Promise<TestFixture>

returns Promise<TestFixture>

surface_source

App surface for schema-level + route-iteration checks. Constructed in TS by the consumer; same shape for in-process and cross-process tests.

type AppSurfaceSpec

sensitive_fields?

Fields that must never appear in any response. Default: sensitive_field_blocklist.

type readonly string[]

admin_only_fields?

Fields that must not appear in non-admin responses. Default: admin_only_field_blocklist.

type readonly string[]

skip_routes?

Routes to skip, in 'METHOD /path' format, and RPC or WebSocket method outputs to skip in the schema-level checks, as '/path method_name' ('/path method_name params' for params the server pushes over WebSocket).

type string[]

param_values?

Path param values for specific routes ('METHOD /path' → param name → value), used before the generated ones — needed for a {re} param whose pattern refuses the generated value. See RouteParamValues.

type Readonly<Record<string, Readonly<Record<string, string>>>>

describe_data_exposure_tests
#

testing/data_exposure.ts view source

(options: DataExposureTestOptions): void import {describe_data_exposure_tests} from '@fuzdev/fuz_app/testing/data_exposure.js';

Composable data exposure test suite.

Three test groups:

  1. Schema-level — walk route, RPC, and WebSocket output schemas (both sides of a transform), pushed WebSocket params, and route error schemas for sensitive field names, and non-admin route outputs for admin-only ones
  2. Runtime — fire real requests and check response bodies against blocklists
  3. Cross-privilege — admin routes return 403 for non-admin, error responses contain no sensitive fields

options

returns

void

Depends on
#

Imported by
#