SPB Git

Repository Public

static.test.ts 4.6 KB 68 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : MacLustr Social Engine & Remote Navigator8 * File             : tests/integration/static.test.ts9 * Module           : tests10 * Repository       : https://git.spboucher.ai/maclustr-social11 * Project Website  : https://social.spboucher.ai12 * Created          : 2026-12-0113 * Last Modified    : 2026-12-0114 *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: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import { afterAll, beforeAll, describe, expect, it } from 'vitest';43import { existsSync } from 'node:fs';44import { join } from 'node:path';45import { makeEnv, ROOT, type Env } from '../helpers.ts';46import { startGateway } from '../../services/navigator-gateway/src/gateway.ts';47import { SECURITY_HEADERS } from '../../services/control-api/src/app.ts';48import { freePort } from '../e2e/harness.ts';4950// The built web apps must be served for real (regression: the home page answered 500 on the first deployment).51const built = existsSync(join(ROOT, 'dist/social-web/index.html')) && existsSync(join(ROOT, 'dist/navigator-web/index.html'));52describe.skipIf(!built)('service des applications web construites', () => {53  let env: Env; let gw: Awaited<ReturnType<typeof startGateway>>; let nav = '';54  beforeAll(async () => { const ctl = await freePort(); const g = await freePort(); nav = `http://127.0.0.1:${g}`;55    env = await makeEnv({ MLS_SOCIAL_WEB_DIR: join(ROOT, 'dist/social-web'), MLS_SOCIAL_ORIGIN: `http://127.0.0.1:${ctl}`, MLS_NAVIGATOR_ORIGIN: nav }); await env.app.listen({ host: '127.0.0.1', port: ctl });56    gw = await startGateway({ host: '127.0.0.1', port: g, internalPort: await freePort(), origin: nav, controlUrl: `http://127.0.0.1:${ctl}`, serviceToken: env.ctx.serviceToken, webDir: join(ROOT, 'dist/navigator-web'), cookieName: 'mls', trustProxy: [], securityHeaders: SECURITY_HEADERS }); });57  afterAll(async () => { await gw.close(); await env.close(); });58  for (const which of ['social', 'navigator'] as const) it(`${which} : page d’accueil, routes de l’application, fichiers, en-têtes`, async () => {59    const base = which === 'social' ? env.cfg.socialOrigin : nav;60    for (const path of ['/', '/setup', '/handoff', '/calendar', '/s/00000000-0000-4000-8000-000000000000']) { const r = await fetch(base + path); expect(r.status, path).toBe(200); expect(r.headers.get('content-type')).toMatch(/text\/html/); expect(r.headers.get('content-security-policy')).toMatch(/script-src 'self'/); expect(r.headers.get('cache-control')).toBe('no-cache'); }61    const html = await (await fetch(base + '/')).text(); expect(html).not.toMatch(/<script(?![^>]*\bsrc=)[^>]*>|style="/); // nothing inline: the CSP would block it62    const asset = /(\/assets\/[^"']+\.js)/.exec(html)![1]; const a = await fetch(base + asset); expect(a.status).toBe(200); expect(a.headers.get('cache-control')).toMatch(/immutable/); expect(a.headers.get('x-content-type-options')).toBe('nosniff');63    expect((await fetch(base + '/v1/nope')).status).toBe(404); expect((await fetch(base + '/v1/me')).status).toBe(401); expect((await fetch(base + '/assets/../../package.json')).status).not.toBe(500);64    expect((await fetch(base + '/health/ready')).status).toBe(200);65  });66  it('le CSP de navigator autorise le WebSocket du même hôte, et lui seul', async () => { const csp = (await fetch(nav + '/')).headers.get('content-security-policy')!; expect(csp).toContain(`connect-src 'self' ${nav.replace('http', 'ws')}`); });67});68
Files main
Menu

Theme