Skip to content

Test/testing security headers#216

Merged
mikewheeleer merged 2 commits into
Agentpay-Org:mainfrom
real-venus:test/testing-security-headers
Jun 29, 2026
Merged

Test/testing security headers#216
mikewheeleer merged 2 commits into
Agentpay-Org:mainfrom
real-venus:test/testing-security-headers

Conversation

@real-venus

Copy link
Copy Markdown
Contributor

test(lib): cover buildCsp, originOf, and defaultSecurityHeaders

Closes #145

What's covered

  • originOf — returns the origin for a fully-qualified URL (incl. ports) and
    falls back to the http://localhost:3001 default for unparseable input
  • buildCspconnect-src 'self' <apiOrigin>, frame-ancestors 'none',
    object-src 'none', base-uri 'self', form-action 'self'; 'unsafe-eval'
    added to script-src only when isDev; no navigate-to; and the value is a
    single ; -joined directive list
  • defaultSecurityHeadersX-Content-Type-Options, Referrer-Policy,
    X-Frame-Options, Permissions-Policy, and Strict-Transport-Security present
    only when not dev; plus the broad disabled-features Permissions-Policy

Coverage of securityHeaders.ts: 100% (statements / branches / functions /
lines) — exceeds the requirement.

Relocate the securityHeaders suite to src/lib/__tests__/securityHeaders.test.ts
(next to the module under test) and import it via the local '../securityHeaders'
path. Coverage is unchanged and the suite locks down:

- originOf: origin for a valid URL (incl. ports) and localhost-default
  fallback for unparseable input
- buildCsp: connect-src 'self' <apiOrigin>, frame-ancestors 'none',
  object-src 'none', base-uri 'self', dev-only 'unsafe-eval', and the
  '; '-joined directive list
- defaultSecurityHeaders: X-Content-Type-Options, Referrer-Policy,
  X-Frame-Options, Permissions-Policy, and HSTS only when not dev

100% coverage of securityHeaders.ts.
These pre-existing failures on main block lint/build/test for any PR branched
from it:

- src/app/docs/page.tsx used resolveApiBase() and <CurlBlock> without
  importing them (react/jsx-no-undef lint error + next build typecheck
  failure). Add the missing imports.
- Two Header tests expected primary links marked aria-current twice
  (desktop + mobile), but the mobile nav panel only renders while open, so
  exactly one link is current at rest. Correct the assertions.
@real-venus

Copy link
Copy Markdown
Contributor Author

@mikewheeleer
Please review this.

@mikewheeleer

Copy link
Copy Markdown
Contributor

tidy — in it goes 👍

@mikewheeleer mikewheeleer merged commit fd47c85 into Agentpay-Org:main Jun 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for the securityHeaders CSP builder and origin extraction

2 participants