Reference

Testing

Test Kernia through mounted HTTP routes and real adapter behavior.

Kernia tests should prioritize public behavior: HTTP requests, cookies, database writes, OAuth callbacks, emails, webhooks, and route authorization. Helper unit tests are useful, but they do not prove the auth surface works.

Test layers

LayerPurpose
UnitHashing, token parsing, option normalization, small helpers.
RouteMounted HTTP behavior, cookies, errors, sessions, and payloads.
AdapterReal database behavior for each supported adapter.
ProviderMock OAuth, SAML, Stripe, email, SMS, and passkey flows.
BrowserDemo login, settings, admin, billing, and session flows.

ASGI driver

Use kernia_test_utils.ASGIDriver to call a mounted FastAPI or Starlette app without a live network port.

test_auth.py
from kernia_test_utils import ASGIDriver

async def test_email_sign_in(app):
    driver = ASGIDriver(app)
    response = await driver.post("/api/auth/sign-in/email", json={
        "email": "user@example.com",
        "password": "correct-password",
    })
    assert response.status_code == 200
    assert "set-cookie" in response.headers

Mock providers

Use deterministic provider fakes instead of live credentials in normal CI:

HelperUse
MockIdPOAuth/OIDC redirect and callback tests.
MockSAMLIdPEnterprise SSO tests.
MockSMTPVerification, reset, magic link, and OTP email tests.
MockSMSPhone verification tests.
MockStripeCatalog sync, portal, checkout, webhook, usage tests.
SoftAuthenticatorPasskey registration and assertion tests.

Adapter matrix

Run critical flows against memory, SQLAlchemy, Mongo, Redis-backed secondary storage, and containerized databases when the feature depends on storage semantics.

uv run pytest packages/ e2e/ -q

Browser tests

The SaaS demo should have Playwright tests for login, logout, settings/profile, linked accounts, sessions revoke, API key create/revoke, admin method toggles, email client config, Stripe import, billing checks, and usage display.

cd apps/demo-web
pnpm test:e2e

Assertions that matter

  • HTTP status and stable error code.
  • Cookie name, flags, domain, path, and expiration.
  • Database rows created, updated, or deleted.
  • Secret redaction on reads.
  • Webhook signature verification.
  • Disabled or not-configured provider behavior.
  • Browser-visible state after real route calls.

Test data

Keep test users and organizations explicit. Do not reuse provider secrets or production-like emails. For OAuth and SAML, generate deterministic keys in fixtures and keep them scoped to the test process.