Test sweep: 144 new tests across services + middleware + verifier package (73 → 217)#30
Merged
Conversation
… verifier 73 → 217 tests passing (144 new). Covers every previously-untested service + middleware in the API repo, plus the verifier package which shipped on Day 4 with zero of its own tests. Backend (tests/, +121): - tests/api-keys.ts (16) — generateRawKey shape, SHA-256 hashing (DB stores the hash, never the raw key — verified by digest comparison), authenticateApiKey expiry + revoked rejection, listApiKeys never projects key_hash, revokeApiKey audit row + no-op return, countActiveKeys parses pg's string count. - tests/tenants.ts (18) — scrypt password hashing (salt:hex format verified by regex), distinct salts → distinct hashes, password verification rejects on wrong password / malformed stored hash / missing colon / non-hex / truncated, email lower-case-trim on signup + lookup, PLAN_LIMITS application. - tests/jwt.ts (12) — issueTokens shape, jti uuid v4 verified, refresh token stripped of payload claims, verifyToken throws on wrong secret / wrong issuer / no issuer / garbage, decodeToken no-verify path. - tests/middleware.ts (14) — authenticateJWT happy + 5 reject paths (no header, non-Bearer, invalid jwt, expired, wrong-secret), authenticateAdmin x-api-key matching, errorHandler 500 with stack in dev only / suppressed in prod, notFoundHandler 404, demoAuthOnly 503 unless ENABLE_DEMO_AUTH=true. - tests/session-store.ts (7) — in-memory create/get/delete, auto-expiry on get, getStats prunes + biometricDataStored=false invariant, provider breakdown bumps. - tests/usage.ts (16) — logApiCall fire-and-forget invariant (swallows errors), endpoint→counter routing (zkp_verifications, zkp_registrations, saml_auths, oidc_auths, total_requests), checkQuota allowed/used/limit logic with -1 unlimited fast-path. - tests/platform.ts (18) — recordAuditEvent INSERT shape, AuditActor plumbing (issue #26 F-3): console → actor_type=console + actor_email in metadata, v1 → actor_type=api_key, missing actor → default to api_key+null. Tenant-scoping (A-01) assertions: every listDevices/listTenantUsers/listAuditEvents WHERE clause includes tenant_id AND environment. sanitizeLimit boundaries ([1,100] clamp, default 50, negative clamps to 1). - tests/leads.ts (20) — POST /pilot validation + persist, lower-case + trim, Postgres-unavailable degraded path, DB-error-doesn't-leak, POST /whitepaper download URL, GET /api/leads admin gating + type filter + injection-resistance (invalid ?type ignored). Verifier (verifier/tests/, +23): - groth16.test.ts (9) — initVerifier handles missing vkey path, structural fallback returns structuralFallback=true, rejects wrong protocol / wrong curve / wrong-length pi_a / empty string in pi_a / non-string in pi_c / totally malformed object. - server.test.ts (14) — supertest against the Express app: POST /verify envelope shape (200 + verifierAuditId uuid v4 + latencyMs + circuitVersion + structuralFallback), 400s for missing proof / missing publicSignals / length != 3 / non-array, custom circuitVersion echo, unique verifierAuditId per call, monotonic uptime, GET /health degraded when no vkey, 404 on unknown routes including GET /verify. Infra: - verifier/jest.config.js added (ts-jest preset, tests in verifier/tests/) - verifier/package.json test script wired - verifier/tests/ directory created - All 18 jest devDeps pulled in via npm workspace install Typecheck both packages clean. Lint 0 errors (10 pre-existing warnings unchanged). What's still untested (deferred — lower priority): - src/services/db.ts pg pool wrapper (thin, hard to unit-test meaningfully without spinning up Postgres) - src/services/logger.ts (winston wrapper, no logic) - src/types/ (type declarations only) - src/config/ (env var parsing — exercised via every other test) - src/middleware/tenant-auth.ts unit (already covered by integration via central-api.test.ts + console-proxy.test.ts) - src/server.ts startup (covered by deployment smoke + e2e) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
pulkitpareek18
added a commit
that referenced
this pull request
May 15, 2026
… verifier (#30) 73 → 217 tests passing (144 new). Covers every previously-untested service + middleware in the API repo, plus the verifier package which shipped on Day 4 with zero of its own tests. Backend (tests/, +121): - tests/api-keys.ts (16) — generateRawKey shape, SHA-256 hashing (DB stores the hash, never the raw key — verified by digest comparison), authenticateApiKey expiry + revoked rejection, listApiKeys never projects key_hash, revokeApiKey audit row + no-op return, countActiveKeys parses pg's string count. - tests/tenants.ts (18) — scrypt password hashing (salt:hex format verified by regex), distinct salts → distinct hashes, password verification rejects on wrong password / malformed stored hash / missing colon / non-hex / truncated, email lower-case-trim on signup + lookup, PLAN_LIMITS application. - tests/jwt.ts (12) — issueTokens shape, jti uuid v4 verified, refresh token stripped of payload claims, verifyToken throws on wrong secret / wrong issuer / no issuer / garbage, decodeToken no-verify path. - tests/middleware.ts (14) — authenticateJWT happy + 5 reject paths (no header, non-Bearer, invalid jwt, expired, wrong-secret), authenticateAdmin x-api-key matching, errorHandler 500 with stack in dev only / suppressed in prod, notFoundHandler 404, demoAuthOnly 503 unless ENABLE_DEMO_AUTH=true. - tests/session-store.ts (7) — in-memory create/get/delete, auto-expiry on get, getStats prunes + biometricDataStored=false invariant, provider breakdown bumps. - tests/usage.ts (16) — logApiCall fire-and-forget invariant (swallows errors), endpoint→counter routing (zkp_verifications, zkp_registrations, saml_auths, oidc_auths, total_requests), checkQuota allowed/used/limit logic with -1 unlimited fast-path. - tests/platform.ts (18) — recordAuditEvent INSERT shape, AuditActor plumbing (issue #26 F-3): console → actor_type=console + actor_email in metadata, v1 → actor_type=api_key, missing actor → default to api_key+null. Tenant-scoping (A-01) assertions: every listDevices/listTenantUsers/listAuditEvents WHERE clause includes tenant_id AND environment. sanitizeLimit boundaries ([1,100] clamp, default 50, negative clamps to 1). - tests/leads.ts (20) — POST /pilot validation + persist, lower-case + trim, Postgres-unavailable degraded path, DB-error-doesn't-leak, POST /whitepaper download URL, GET /api/leads admin gating + type filter + injection-resistance (invalid ?type ignored). Verifier (verifier/tests/, +23): - groth16.test.ts (9) — initVerifier handles missing vkey path, structural fallback returns structuralFallback=true, rejects wrong protocol / wrong curve / wrong-length pi_a / empty string in pi_a / non-string in pi_c / totally malformed object. - server.test.ts (14) — supertest against the Express app: POST /verify envelope shape (200 + verifierAuditId uuid v4 + latencyMs + circuitVersion + structuralFallback), 400s for missing proof / missing publicSignals / length != 3 / non-array, custom circuitVersion echo, unique verifierAuditId per call, monotonic uptime, GET /health degraded when no vkey, 404 on unknown routes including GET /verify. Infra: - verifier/jest.config.js added (ts-jest preset, tests in verifier/tests/) - verifier/package.json test script wired - verifier/tests/ directory created - All 18 jest devDeps pulled in via npm workspace install Typecheck both packages clean. Lint 0 errors (10 pre-existing warnings unchanged). What's still untested (deferred — lower priority): - src/services/db.ts pg pool wrapper (thin, hard to unit-test meaningfully without spinning up Postgres) - src/services/logger.ts (winston wrapper, no logic) - src/types/ (type declarations only) - src/config/ (env var parsing — exercised via every other test) - src/middleware/tenant-auth.ts unit (already covered by integration via central-api.test.ts + console-proxy.test.ts) - src/server.ts startup (covered by deployment smoke + e2e)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the long-standing coverage gap on services + middleware that integration tests had been covering indirectly. Plus adds the verifier package's first ever tests (it shipped this morning without any).
What's covered
Backend (8 new test files, +121 tests):
Verifier package (2 new test files, +23 tests):
Numbers
What's deliberately NOT tested
src/services/db.ts— thin pg pool wrapper, hard to unit-test without spinning Postgres in CIsrc/services/logger.ts— winston wrapper, no logicsrc/types/— declarations onlysrc/config/— env-var parsing, exercised through every other testsrc/middleware/tenant-auth.tsdirect unit — already covered by central-api + console-proxy integration testssrc/server.tsstartup — covered by deploy smoke + Playwright e2eTest plan
npx tsc --noEmitclean both packagesnpm test— 194 backendnpm --workspace @zeroauth/verifier test— 23 verifiernpm run lint— 0 errors🤖 Generated with Claude Code