diff --git a/web/.gitignore b/web/.gitignore index a547bf3..c471c9d 100644 --- a/web/.gitignore +++ b/web/.gitignore @@ -22,3 +22,7 @@ dist-ssr *.njsproj *.sln *.sw? + +# Testdekking en Lighthouse CI +coverage +.lighthouseci diff --git a/web/.prettierignore b/web/.prettierignore index 216d4c5..3df0dc4 100644 --- a/web/.prettierignore +++ b/web/.prettierignore @@ -1,3 +1,12 @@ **/.ai -**/routeTree.gen.ts \ No newline at end of file +**/routeTree.gen.ts +.lighthouseci +coverage +dist +pnpm-lock.yaml +.agents +.claude +.junie +.tanstack +skills-lock.json diff --git a/web/config/securityHeaders.test.ts b/web/config/securityHeaders.test.ts new file mode 100644 index 0000000..69c0024 --- /dev/null +++ b/web/config/securityHeaders.test.ts @@ -0,0 +1,35 @@ +import { describe, expect, it } from 'vitest'; +import { contentSecurityPolicy, securityHeaders } from './securityHeaders'; + +const directive = (csp: string, name: string) => + csp.split('; ').find((d) => d.startsWith(name + ' ')) ?? ''; + +describe('securityHeaders', () => { + it('productie-CSP heeft geen onveilige uitzonderingen voor scripts', () => { + const csp = contentSecurityPolicy('production'); + expect(csp).not.toContain('unsafe-eval'); + expect(directive(csp, 'script-src')).toBe("script-src 'self'"); + expect(csp).not.toContain('ws:'); + expect(directive(csp, 'frame-ancestors')).toBe( + "frame-ancestors 'none'", + ); + }); + + it('dev-CSP voegt alleen toe wat Vite nodig heeft', () => { + const csp = contentSecurityPolicy('development'); + expect(directive(csp, 'script-src')).toBe( + "script-src 'self' 'unsafe-inline'", + ); + expect(directive(csp, 'connect-src')).toBe("connect-src 'self' ws:"); + expect(csp).not.toContain('unsafe-eval'); + }); + + it('zet alle verplichte headers', () => { + expect(securityHeaders('production')).toMatchObject({ + 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains', + 'X-Content-Type-Options': 'nosniff', + 'X-Frame-Options': 'DENY', + 'Referrer-Policy': 'strict-origin-when-cross-origin', + }); + }); +}); diff --git a/web/config/securityHeaders.ts b/web/config/securityHeaders.ts new file mode 100644 index 0000000..3979130 --- /dev/null +++ b/web/config/securityHeaders.ts @@ -0,0 +1,49 @@ +// HTTP-securityheaders voor de Vite dev- en preview-server. De productieset is +// ook het voorschrift voor de toekomstige host (zie NFR-SEC-01/02). + +type Mode = 'production' | 'development'; + +// Chakra/Emotion zetten tijdens runtime diff --git a/web/src/components/AppShell.test.tsx b/web/src/components/AppShell.test.tsx new file mode 100644 index 0000000..423f64c --- /dev/null +++ b/web/src/components/AppShell.test.tsx @@ -0,0 +1,32 @@ +import { screen } from '@testing-library/react'; +import { describe, expect, it } from 'vitest'; +import { axeResults } from '@/test/axe'; +import { renderWithProviders } from '@/test/renderWithProviders'; +import AppShell from './AppShell'; + +describe('AppShell', () => { + it('heeft de landmarks van de shell', async () => { + const { container } = await renderWithProviders(); + expect(screen.getByRole('banner')).toBeInTheDocument(); + expect(screen.getByRole('main')).toHaveAttribute('id', 'main'); + expect(screen.getByRole('contentinfo')).toBeInTheDocument(); + expect( + screen.getByRole('navigation', { name: 'Hoofdmenu' }), + ).toBeInTheDocument(); + expect( + screen.getByRole('navigation', { name: 'Footermenu' }), + ).toBeInTheDocument(); + expect(await axeResults(container)).toHaveNoViolations(); + }); + + it('begint met een skip link naar de inhoud', async () => { + const { container } = await renderWithProviders(); + const skip = screen.getByRole('link', { + name: 'Direct naar de inhoud', + }); + expect(skip).toHaveAttribute('href', '#main'); + // Eerste focusbare element van de pagina + expect(container.querySelector('a, button')).toBe(skip); + expect(screen.getByRole('main')).toHaveAttribute('tabindex', '-1'); + }); +}); diff --git a/web/src/components/AppShell.tsx b/web/src/components/AppShell.tsx index d35d0d1..5c28bd7 100644 --- a/web/src/components/AppShell.tsx +++ b/web/src/components/AppShell.tsx @@ -1,13 +1,27 @@ +import { SkipNavContent, SkipNavLink } from '@chakra-ui/react'; import { Outlet } from '@tanstack/react-router'; +import siteContent from '@/content/siteContent'; +import useRouteFocus from '@/hooks/useRouteFocus'; +import BackToTop from './BackToTop/BackToTop'; +import Footer from './Footer/Footer'; import NavigationBar from './NavigationBar/NavigationBar'; -import Footer from './Footer'; +// Het frame om elke pagina (LAYOUT.md "Shell"): header, inhoud en footer. +// Hier komt de site-brede content binnen; straks uit een loader of de API. export default function AppShell() { + useRouteFocus(); + return ( <> + + Direct naar de inhoud + - -