Files
carmanagement/apps/homepage/tests/unit/csp.test.ts
T
root 330fc11791
Build & Deploy / Build & Push Docker Image (push) Successful in 3m1s
Test / Type Check (all packages) (push) Successful in 57s
Build & Deploy / Deploy to VPS (push) Successful in 4s
Test / API Unit Tests (push) Successful in 49s
Test / Homepage Unit Tests (push) Successful in 43s
Test / Storefront Unit Tests (push) Successful in 42s
Test / Admin Unit Tests (push) Successful in 42s
Test / Dashboard Unit Tests (push) Successful in 42s
Test / API Integration Tests (push) Successful in 1m0s
Updated the homepage CSP for the new browser error.
2026-07-02 00:30:30 -04:00

22 lines
922 B
TypeScript

import { buildContentSecurityPolicy, createNonce } from '@/lib/security/csp';
import { describe, expect, it } from 'vitest';
describe('CSP foundation', () => {
it('generates unpredictable nonce-shaped values', () => {
const first = createNonce();
const second = createNonce();
expect(first).toMatch(/^[a-f0-9]{32}$/);
expect(second).not.toBe(first);
});
it('allows required runtime evaluation without enabling development-only sources', () => {
expect(buildContentSecurityPolicy('abc', true)).toContain("'unsafe-eval'");
expect(buildContentSecurityPolicy('abc', false)).toContain("'unsafe-eval'");
expect(buildContentSecurityPolicy('abc', false)).toContain("'nonce-abc'");
expect(buildContentSecurityPolicy('abc', false)).toContain(
"style-src 'self' 'unsafe-inline'",
);
expect(buildContentSecurityPolicy('abc', false)).toContain("frame-ancestors 'none'");
});
});