SPB Git

Repository Public

site.spec.ts 5.2 KB 116 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : agentilab-web8 * File             : tests/e2e/site.spec.ts9 * Module           : Tests10 * Repository       : https://git.spboucher.ai/agentilab-web11 * Project Website  : Not specified12 * Created          : 2026-12-0513 * Last Modified    : 2026-12-0514 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : Proprietary34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import { expect, test } from '@playwright/test';44import { pages } from './helpers';4546test('404 personnalisée : vrai code 404, dans la bonne langue, non indexable', async ({ page }) => {47  const fr = await page.goto('/cette-page-n-existe-pas');48  expect(fr?.status()).toBe(404);49  await expect(page.getByRole('heading', { level: 1 })).toHaveText('Page introuvable');50  await expect(page.locator('html')).toHaveAttribute('lang', 'fr-CA');51  await expect(page.locator('meta[name="robots"]').first()).toHaveAttribute('content', /noindex/);52  await page.getByRole('link', { name: 'Retour à l’accueil' }).click();53  await expect(page).toHaveURL('/');5455  const en = await page.goto('/en/no-such-page/deeper');56  expect(en?.status()).toBe(404);57  await expect(page.getByRole('heading', { level: 1 })).toHaveText('Page not found');58  await expect(page.locator('html')).toHaveAttribute('lang', 'en-CA');59});6061test('sitemap : toutes les URL canoniques, chacune répond 200', async ({ request }) => {62  const xml = await (await request.get('/sitemap.xml')).text();63  const urls = [...xml.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => m[1] as string);64  expect(urls).toHaveLength(pages.length);65  expect(xml).toContain('hreflang="fr-CA"');66  expect(xml).toContain('hreflang="en-CA"');67  for (const url of urls) {68    expect(url).toMatch(/^https:\/\/www\.agentilab\.ai/);69    const local = url.replace('https://www.agentilab.ai', '') || '/';70    expect((await request.get(local)).status(), local).toBe(200);71  }72});7374test('robots.txt de production : ouvert, avec le sitemap', async ({ request }) => {75  const body = await (await request.get('/robots.txt')).text();76  expect(body).toMatch(/Allow: \//);77  expect(body).not.toMatch(/Disallow: \/\s*$/m);78  expect(body).toContain('Sitemap: https://www.agentilab.ai/sitemap.xml');79});8081test('en-têtes de sécurité sur les pages, les 404 et les fichiers', async ({ request }) => {82  for (const path of ['/', '/en/company', '/introuvable', '/og.png']) {83    const headers = (await request.get(path)).headers();84    expect(headers['content-security-policy'], path).toContain("default-src 'self'");85    expect(headers['content-security-policy']).toContain("frame-ancestors 'none'");86    expect(headers['x-content-type-options']).toBe('nosniff');87    expect(headers['x-frame-options']).toBe('DENY');88    expect(headers['referrer-policy']).toBe('strict-origin-when-cross-origin');89    expect(headers['permissions-policy']).toContain('geolocation=()');90    expect(headers['x-powered-by']).toBeUndefined();91    // En production sans HSTS_MAX_AGE, pas de HSTS ; jamais de noindex.92    expect(headers['strict-transport-security']).toBeUndefined();93    expect(headers['x-robots-tag']).toBeUndefined();94  }95});9697test('healthz : répond sans rien révéler', async ({ request }) => {98  const response = await request.get('/healthz');99  expect(response.status()).toBe(200);100  expect(await response.text()).toBe('ok\n');101});102103test('aucun fichier privé ni document interne n’est servi', async ({ request }) => {104  for (const path of ['/.env', '/.git/config', '/CLAUDE.md', '/docs/AUDIT.md', '/package.json', '/content/public/legal.ts', '/registre.pdf', '/internal/']) {105    expect((await request.get(path)).status(), path).toBe(404);106  }107});108109test('favicon, icônes et image sociale sont servis', async ({ request }) => {110  for (const [path, type] of [['/favicon.ico', 'image'], ['/icon.svg', 'image/svg+xml'], ['/apple-touch-icon.png', 'image/png'], ['/og.png', 'image/png']] as const) {111    const response = await request.get(path);112    expect(response.status(), path).toBe(200);113    expect(response.headers()['content-type']).toContain(type);114  }115});116
Files main
Menu

Theme