Test/testing security headers#216
Merged
mikewheeleer merged 2 commits intoJun 29, 2026
Merged
Conversation
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.
Contributor
Author
|
@mikewheeleer |
Contributor
|
tidy — in it goes 👍 |
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.
test(lib): cover buildCsp, originOf, and defaultSecurityHeaders
Closes #145
What's covered
originOf— returns the origin for a fully-qualified URL (incl. ports) andfalls back to the
http://localhost:3001default for unparseable inputbuildCsp—connect-src 'self' <apiOrigin>,frame-ancestors 'none',object-src 'none',base-uri 'self',form-action 'self';'unsafe-eval'added to
script-srconly whenisDev; nonavigate-to; and the value is asingle
;-joined directive listdefaultSecurityHeaders—X-Content-Type-Options,Referrer-Policy,X-Frame-Options,Permissions-Policy, andStrict-Transport-Securitypresentonly when not dev; plus the broad disabled-features Permissions-Policy
Coverage of
securityHeaders.ts: 100% (statements / branches / functions /lines) — exceeds the requirement.