test(coverage): root-contents + email-verify + HMAC gap tests, no-tracking fix, ratchet 73->78 #46

Merged
amiryahaya merged 3 commits from test/coverage-gaps-27 into main 2026-11-04 04:00:40 +01:00
Owner

Closes #44 (found by these tests). Advances #27: coverage floor ratcheted 73 -> 78; measured 78.7% Debug / 79.6% Release on 726 tests (was 74.7/75.7 on 700).

New coverage for three previously-zero surfaces:

  • GET /api/folders/root/contents (5 tests): auto personal-tenant provisioning, root reuse across calls, ownership filtering vs other tenants/users, share-based inclusion with revoked/expired exclusion, tenant isolation. Co-tenant membership is seeded manually — the fixture always mints a fresh tenant per user.
  • POST /api/auth/email/register/verify (9 tests): field validation, wrong OTP, valid OTP + unknown/expired invitation, happy path (user + tenant membership + Email login + TOTP flag), existing-account auto-link (no duplicate user), single-use OTP.
  • HMAC /api/ext/* middleware (12 tests): missing headers, malformed service-id/timestamps, stale/future timestamps, unknown/disabled service, bad signature, wrong-path signature, acceptance (LastUsedAt stamped — no /api/ext endpoints exist yet, accepted requests 404 downstream), replay rejection.

Real bug caught (#44): the tenant-less provisioning test went red — the endpoint mutated accessor.User, which SsdidAuthMiddleware loads AsNoTracking(), so users.tenant_id never persisted and every call minted a duplicate personal tenant. Fixed by resolving a tracked user in the handler.

Remaining gap to the #27 80% exit: OIDC verify/callback (~280 lines, needs a fake-IdP harness).

Closes #44 (found by these tests). Advances #27: coverage floor ratcheted **73 -> 78**; measured **78.7% Debug / 79.6% Release** on 726 tests (was 74.7/75.7 on 700). **New coverage for three previously-zero surfaces:** - `GET /api/folders/root/contents` (5 tests): auto personal-tenant provisioning, root reuse across calls, ownership filtering vs other tenants/users, share-based inclusion with revoked/expired exclusion, tenant isolation. Co-tenant membership is seeded manually — the fixture always mints a fresh tenant per user. - `POST /api/auth/email/register/verify` (9 tests): field validation, wrong OTP, valid OTP + unknown/expired invitation, happy path (user + tenant membership + Email login + TOTP flag), existing-account auto-link (no duplicate user), single-use OTP. - HMAC `/api/ext/*` middleware (12 tests): missing headers, malformed service-id/timestamps, stale/future timestamps, unknown/disabled service, bad signature, wrong-path signature, acceptance (LastUsedAt stamped — no /api/ext endpoints exist yet, accepted requests 404 downstream), replay rejection. **Real bug caught (#44):** the tenant-less provisioning test went red — the endpoint mutated `accessor.User`, which `SsdidAuthMiddleware` loads `AsNoTracking()`, so `users.tenant_id` never persisted and every call minted a duplicate personal tenant. Fixed by resolving a tracked user in the handler. **Remaining gap to the #27 80% exit:** OIDC verify/callback (~280 lines, needs a fake-IdP harness).
Covers three #27 coverage-gap surfaces (previously zero tests):
- GET /api/folders/root/contents: auto personal-tenant provisioning,
  root reuse, ownership filtering, share-based inclusion with
  revoked/expired exclusion (co-tenant seeding)
- POST /api/auth/email/register/verify: validation, OTP rejection,
  invitation expiry, happy-path user+membership+login creation,
  existing-account auto-link, single-use OTP
- HMAC /api/ext/* middleware: header validation, timestamp window,
  unknown/disabled service, signature and path mismatches, acceptance
  (LastUsedAt stamped), replay rejection

The tenant-less auto-provision test exposed a real bug: the endpoint
mutated accessor.User, which SsdidAuthMiddleware loads AsNoTracking —
the personal Tenant + UserTenant rows persisted but users.tenant_id
never did, minting duplicate personal tenants per call. Fixed by
resolving a tracked user (Closes #44).
chore(coverage): ratchet floor 73 -> 78 (root-contents, email-verify, HMAC covered)
Some checks failed
API CI / build-and-test (pull_request) Failing after 1m39s
ad57cb9ce7
Sign in to join this conversation.
No description provided.