mirror of
https://github.com/mileswolfallen2/miles-web.git
synced 2026-12-03 15:43:25 +00:00
- Implement tests for HTTP API endpoints, ensuring correct responses and security headers. - Create configuration tests to validate loading of defaults and environment overrides. - Add tests for FEDL service to verify data handling and snapshot functionality. - Introduce GitHub service tests to check API data normalization and caching behavior. - Develop monitor service tests for network checks and uptime calculations. - Implement persistence tests to ensure database migrations are idempotent and data persists across restarts. - Add vault service tests for session management and brute-force protection mechanisms. - Include helper functions for test context creation and JSON response handling.
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
export function parseCookies(header) {
|
|
const out = {};
|
|
if (!header) return out;
|
|
for (const part of header.split(';')) {
|
|
const eq = part.indexOf('=');
|
|
if (eq === -1) continue;
|
|
const name = part.slice(0, eq).trim();
|
|
if (!name) continue;
|
|
let value = part.slice(eq + 1).trim();
|
|
if (value.startsWith('"') && value.endsWith('"')) value = value.slice(1, -1);
|
|
out[name] = value;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
export function serializeCookie(name, value, options = {}) {
|
|
const {
|
|
path = '/',
|
|
maxAge,
|
|
expires,
|
|
httpOnly = true,
|
|
secure = false,
|
|
sameSite = 'Strict'
|
|
} = options;
|
|
|
|
const parts = [`${name}=${value}`, `Path=${path}`];
|
|
if (maxAge !== undefined) parts.push(`Max-Age=${Math.max(0, Math.floor(maxAge))}`);
|
|
if (expires) parts.push(`Expires=${expires.toUTCString()}`);
|
|
if (httpOnly) parts.push('HttpOnly');
|
|
if (secure) parts.push('Secure');
|
|
if (sameSite) parts.push(`SameSite=${sameSite}`);
|
|
return parts.join('; ');
|
|
}
|
|
|
|
export function clearCookie(name, options = {}) {
|
|
return serializeCookie(name, '', { ...options, maxAge: 0, expires: new Date(0) });
|
|
}
|