CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 28s
CI / Dependency audit (push) Successful in 16s
CI / Tests (Linux, race detector) (push) Successful in 1m3s
Release / Plan (reuse the published image?) (push) Successful in 4s
Release / ci (push) Skipped
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Successful in 13s
Release / Gitea release (push) Successful in 3s
Optional second firewall (URUTAU_ENFORCE off/observe/on) through the host fail2ban, outbound traffic analysis (beaconing, mining, spam, DNS bypass, unauthorised scans) with authorised scanner workloads, host kit in deploy/host and a printable HTML report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
92 lines
5.3 KiB
JavaScript
92 lines
5.3 KiB
JavaScript
#!/usr/bin/env node
|
|
// Layout regression test: starts the real binary with synthetic logs, opens every
|
|
// route at 1440/1024/768/390 px in both themes and fails when the page scrolls
|
|
// horizontally or a card is wider than its box.
|
|
//
|
|
// Usage: node scripts/ui-overflow.mjs <path-to-urutau-binary> [port]
|
|
// Skips (exit 0) when Chrome or puppeteer-core is not available, so CI never
|
|
// breaks on a machine without a browser.
|
|
|
|
import { spawn, execSync } from 'node:child_process';
|
|
import { createRequire } from 'node:module';
|
|
import { mkdtempSync, writeFileSync, existsSync } from 'node:fs';
|
|
import { tmpdir, homedir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
|
|
const bin = process.argv[2];
|
|
const port = Number(process.argv[3] || 18793);
|
|
if (!bin || !existsSync(bin)) { console.error('usage: ui-overflow.mjs <urutau-binary> [port]'); process.exit(2); }
|
|
|
|
function loadPuppeteer() {
|
|
for (const base of [process.cwd() + '/', homedir() + '/.claude/tools/']) {
|
|
try { return createRequire(base + 'x.js')('puppeteer-core'); } catch { /* next */ }
|
|
}
|
|
return null;
|
|
}
|
|
function findChrome() {
|
|
if (process.env.CHROME_PATH && existsSync(process.env.CHROME_PATH)) return process.env.CHROME_PATH;
|
|
try { const p = execSync('ls -1d ~/.cache/puppeteer/chrome/*/chrome-linux64/chrome 2>/dev/null | sort -V | tail -1', { shell: '/bin/bash' }).toString().trim(); if (p) return p; } catch { /* none */ }
|
|
for (const c of ['google-chrome', 'chromium', 'chromium-browser']) { try { return execSync('command -v ' + c, { shell: '/bin/bash' }).toString().trim(); } catch { /* next */ } }
|
|
return null;
|
|
}
|
|
const puppeteer = loadPuppeteer();
|
|
const chrome = findChrome();
|
|
if (!puppeteer || !chrome) { console.log('ui-overflow: skipped (needs puppeteer-core and Chrome)'); process.exit(0); }
|
|
|
|
// synthetic logs
|
|
const dir = mkdtempSync(join(tmpdir(), 'urutau-ui-'));
|
|
const now = Date.now();
|
|
const lines = [];
|
|
const bad = ['45.94.31.244', '185.220.101.4', '103.77.192.18', '222.186.30.57'];
|
|
for (let i = 0; i < 1500; i++) {
|
|
const t = new Date(now - Math.random() * 3 * 86400e3).toISOString();
|
|
const atk = Math.random() < 0.5;
|
|
lines.push(JSON.stringify({ ClientHost: atk ? bad[i % bad.length] : '200.17.1.' + (i % 200 + 1), ClientPort: '1', DownstreamContentSize: 900, DownstreamStatus: atk ? 404 : 200, Duration: 5e6, RequestHost: 'example.org', RequestMethod: 'GET', RequestPath: atk ? '/wp-login.php' : '/', StartUTC: t, time: t, 'request_User-Agent': atk ? 'zgrab/0.x' : 'Mozilla/5.0 (X11; Linux x86_64) Chrome/130.0' }));
|
|
}
|
|
lines.sort();
|
|
writeFileSync(join(dir, 'access.log'), lines.join('\n') + '\n');
|
|
writeFileSync(join(dir, 'auth.log'), '');
|
|
writeFileSync(join(dir, 'fail2ban.log'), '');
|
|
|
|
const srv = spawn(bin, ['serve', '--bind', `127.0.0.1:${port}`, '--insecure-no-auth', '--name', 'ui', '--data-dir', dir, '--traefik-log', join(dir, 'access.log'), '--auth-log', '', '--fail2ban-log', '', '--geo-update', '0'], { stdio: 'ignore' });
|
|
const stop = () => { try { srv.kill(); } catch { /* gone */ } };
|
|
process.on('exit', stop);
|
|
const base = `http://127.0.0.1:${port}`;
|
|
for (let i = 0; i < 50; i++) { try { if ((await fetch(base + '/api/health')).ok) break; } catch { /* wait */ } await new Promise((r) => setTimeout(r, 200)); }
|
|
|
|
let ip = bad[0];
|
|
try { const j = await (await fetch(base + '/api/v1/ips?per=1')).json(); if (j.items?.[0]) ip = j.items[0].ip; } catch { /* default */ }
|
|
const routes = ['overview', 'threats', 'geo', 'live', 'replay', 'traffic', 'ips', 'sources', 'ip/' + ip, 'sessions', 'campaigns', 'search', 'mitre', 'defense', 'egress', 'evolution', 'concentration', 'survival', 'errors', 'slo', 'protocol', 'integrity', 'reports'];
|
|
const sizes = [[1440, 900], [1024, 768], [768, 1024], [390, 844]];
|
|
const failures = [];
|
|
const browser = await puppeteer.launch({ executablePath: chrome, args: ['--no-sandbox'] });
|
|
for (const [w, hh] of sizes) {
|
|
for (const theme of ['dark', 'light']) {
|
|
const page = await browser.newPage();
|
|
await page.setViewport({ width: w, height: hh });
|
|
await page.evaluateOnNewDocument((th) => { localStorage.setItem('urutau.theme', th); }, theme);
|
|
for (const r of routes) {
|
|
if (page.url() === 'about:blank') await page.goto(`${base}/#/${r}?r=24h`, { waitUntil: 'domcontentloaded' });
|
|
else await page.evaluate((x) => { location.hash = '#/' + x + '?r=24h'; }, r);
|
|
await new Promise((res) => setTimeout(res, 1100));
|
|
const res = await page.evaluate((route) => {
|
|
const want = route.split('/')[0];
|
|
if (location.hash.indexOf('#/' + want) !== 0) return { skipped: true };
|
|
const bad = [];
|
|
document.querySelectorAll('.panel, .card-metric, .session-card, .ip-verdict').forEach((n) => {
|
|
if (n.scrollWidth > n.clientWidth + 1) bad.push((n.className || n.tagName) + ' ' + n.scrollWidth + '>' + n.clientWidth);
|
|
});
|
|
return { page: document.documentElement.scrollWidth - window.innerWidth, bad };
|
|
}, r);
|
|
if (res.skipped) { console.log(`skip ${r} (page not registered)`); continue; }
|
|
if (res.page > 0) failures.push(`${w}px ${theme} #/${r}: page scrolls horizontally by ${res.page}px`);
|
|
for (const b of res.bad.slice(0, 3)) failures.push(`${w}px ${theme} #/${r}: ${b}`);
|
|
}
|
|
await page.close();
|
|
}
|
|
}
|
|
await browser.close();
|
|
stop();
|
|
if (failures.length) { console.error('ui-overflow FAILED:\n ' + [...new Set(failures)].join('\n ')); process.exit(1); }
|
|
console.log('ui-overflow ok');
|