testing/auth_apps.ts

Auth test app factories for adversarial testing.

Creates Hono test apps at each auth level (public, authenticated, keeper, per-role) for use in adversarial auth enforcement and input validation tests.

view source

Declarations
#

6 declarations

AuthTestApps
#

testing/auth_apps.ts view source

AuthTestApps import type {AuthTestApps} from '@fuzdev/fuz_app/testing/auth_apps.js';

Pre-built Hono apps for each auth level, shared across adversarial test suites.

public

type Hono<BlankEnv, BlankSchema, "/">

authed

type Hono<BlankEnv, BlankSchema, "/">

keeper

type Hono<BlankEnv, BlankSchema, "/">

by_credential_type

One authenticated app per builtin credential type, each holding the keeper role — the channel axis, where by_role is the authority axis.

A credential gate is pre-authorization, so probing it needs an app on a channel the route refuses, and proving a gated route still works needs one on a channel it admits. keeper is the 'daemon_token' entry of this map, not a second app.

type Map<BuiltinCredentialType, Hono<BlankEnv, BlankSchema, "/">>

by_role

type Map<string, Hono<BlankEnv, BlankSchema, "/">>

create_auth_test_apps
#

testing/auth_apps.ts view source

(route_specs: RouteSpec[], roles: string[]): AuthTestApps import {create_auth_test_apps} from '@fuzdev/fuz_app/testing/auth_apps.js';

Create one Hono test app per auth level.

route_specs

the route specs to register

type RouteSpec[]

roles

all roles in the app

type string[]

returns

AuthTestApps

create_route_skip_filter
#

testing/auth_apps.ts view source

(skip_routes: string[] | undefined): (route: { method: string; path: string; }) => boolean import {create_route_skip_filter} from '@fuzdev/fuz_app/testing/auth_apps.js';

Build the skip predicate an adversarial suite applies from its skip_routes option — routes named in 'METHOD /path' form, the surface key. undefined skips nothing.

skip_routes

type string[] | undefined

returns

(route: { method: string; path: string; }) => boolean

create_test_app_from_specs
#

testing/auth_apps.ts view source

(route_specs: RouteSpec[], auth_ctx?: RequestContext | undefined, credential_type?: "session" | "api_token" | "daemon_token" | undefined): Hono<BlankEnv, BlankSchema, "/"> import {create_test_app_from_specs} from '@fuzdev/fuz_app/testing/auth_apps.js';

Create a Hono test app from route specs with optional auth context.

route_specs

the route specs to register

type RouteSpec[]

auth_ctx?

optional request context to inject via middleware

optional

credential_type?

optional credential type (default: 'session' when auth_ctx provided)

optional

returns

Hono<BlankEnv, BlankSchema, "/">

create_test_request_context
#

testing/auth_apps.ts view source

(role?: string | undefined): RequestContext import {create_test_request_context} from '@fuzdev/fuz_app/testing/auth_apps.js';

Create a mock RequestContext with optional role role_grant.

role?

type string
optional

returns

RequestContext

select_auth_app
#

testing/auth_apps.ts view source

(apps: AuthTestApps, auth: RouteAuth): Hono<BlankEnv, BlankSchema, "/"> import {select_auth_app} from '@fuzdev/fuz_app/testing/auth_apps.js';

Select the Hono test app with correct auth for a route.

The credential channel is decided first, because the channel gate is pre-authorization: an app whose credential the route refuses never reaches the role gate, so a role-correct app on the wrong channel answers credential_type_required, and a "correct auth passes guard" case reads it as a failure of the role gate that never ran.

A gate admitting 'session' falls through to the by_role / authed apps, which carry that channel. Any other gate leaves the by_credential_type app as the only candidate — those hold the keeper role, which is why a route pairing a non-session channel with some *other* role has no app and says so.

apps

auth

returns

Hono<BlankEnv, BlankSchema, "/">

throws

  • Error - if `auth.roles` names a role not present in `apps.by_role` — surfaces a missing entry in the `roles` array passed to `create_auth_test_apps`.
  • Error - if the route pairs a non-session channel with a role the channel apps don't hold. Silently handing back a session app would turn every case on the route into a misattributed 403.

Depends on
#

Imported by
#