tracker
All repositories: gitoria
5.6 KB
// tests/seckit.mjs — the security gate's fixture (mission SK): a throw-away ident, a fake TMDB, the tracker on a fixture storage// (tests/seed-show.hl + tests/seed-adult.hl), two users: alice (the owner: follows + watches in the fixture, the editor) and bob.import { spawn, execFileSync } from 'node:child_process';import { mkdirSync, rmSync, writeFileSync, existsSync } from 'node:fs';import { dirname, join, resolve } from 'node:path';import { fileURLToPath } from 'node:url';import { startIdent } from './identkit.mjs';import { startFakeTmdb } from './faketmdb.mjs';const HERE = dirname(fileURLToPath(import.meta.url));export const APP = process.env.TRACKER_APP_DIR ? resolve(process.env.TRACKER_APP_DIR) : resolve(HERE, '..');export const PORT = Number(process.env.TRACKER_GATE_PORT || 8900);export const IDENT_PORT = Number(process.env.TRACKER_GATE_IDENT_PORT || 8901);export const TMDB_PORT = Number(process.env.TRACKER_GATE_TMDB_PORT || 8902);export const BASE = `http://127.0.0.1:${PORT}`;const IDENT_DIR = process.env.TRACKER_GATE_IDENT_DIR || [resolve(APP, '../ident.worldapi.org'), '/media/STORAGE/projects/WorldAPI/ident.worldapi.org'].find(d => existsSync(join(d, 'project.hl')));export const SCRATCH = join(resolve(HERE, '..'), '.scratch', 'security');export const sleep = (ms) => new Promise(r => setTimeout(r, ms));export const J = JSON.stringify;export async function boot(extra = {}) {const STORE = join(SCRATCH, 'store'), MPACKDB = join(STORE, 'mpackdb'), SESSIONS = join(SCRATCH, 'sessions');rmSync(SCRATCH, { recursive: true, force: true });mkdirSync(MPACKDB, { recursive: true }); mkdirSync(SESSIONS, { recursive: true });const k = { logs: { server: '' }, STORE, MPACKDB, SESSIONS };try { return await bootInner(k, extra, STORE, MPACKDB, SESSIONS); } catch (e) { try { k.server && k.server.kill('SIGTERM'); } catch {} try { k.ident && await k.ident.stop(); } catch {} try { k.tmdb && await k.tmdb.stop(); } catch {} throw e; }}async function bootInner(k, extra, STORE, MPACKDB, SESSIONS) {k.ident = await startIdent({ identDir: IDENT_DIR, workDir: join(STORE, 'ident'), port: IDENT_PORT });const alice = await k.ident.signIn('[email protected]'), bob = await k.ident.signIn('[email protected]');k.app = await k.ident.registerApp(alice, 'tracker (security gate)', [BASE]);k.aliceIdentity = await k.ident.exchange(k.app, await k.ident.selectorCode(alice, k.app, BASE));k.bobIdentity = await k.ident.exchange(k.app, await k.ident.selectorCode(bob, k.app, BASE));k.alice = alice; k.bob = bob;const run = (f, env = {}) => execFileSync(join(APP, 'bin/hybriel'), [f], { cwd: APP, env: { ...process.env, TRACKER_STORAGE: MPACKDB, ...env } }).toString();run('tests/seed-show.hl', { TRACKER_SEED_IDENTITY: k.aliceIdentity });run('tests/seed-adult.hl', { TRACKER_SEED_USER: 'gateu0000000000u1' });run('tests/seed-xss.hl');k.tmdb = await startFakeTmdb({ port: TMDB_PORT, shows: {}, movies: { 5001: { id: 5001, title: 'Imported <b>Movie</b>', poster_path: '/x.png' } }, tvmaze: { imdb: {}, thetvdb: {} }, search: {}, persons: {} });k.server = spawn(join(APP, 'bin/hybriel'), ['project.hl'], { cwd: APP, env: { ...process.env, TRACKER_WARM_SYNC_MS: '600000', TRACKER_PORT: String(PORT), TRACKER_SESSIONS: SESSIONS + '/', TRACKER_STORAGE: MPACKDB, TRACKER_WATCH: '0',TRACKER_URL: BASE, IDENT_URL: k.ident.base, IDENT_EXCHANGE_URL: k.ident.base, TRACKER_KEY: k.app.key, TRACKER_SECRET: k.app.secret,TMDB_READ_TOKEN: 'gate-token', TMDB_BASE_URL: k.tmdb.base + '/3', TMDB_IMAGE_URL: k.tmdb.base + '/t/p', TVMAZE_BASE_URL: k.tmdb.base + '/tvmaze',TRACKER_SYNC: '0', TRACKER_ART: '0', TRACKER_PHOTOS: '0', TRACKER_BACKFILL: '0', TRACKER_KINDS: '0', TRACKER_COLLECTIONS: '0', TRACKER_FRANCHISE_SEED: '0', TRACKER_REPAIR: '0', TRACKER_CREDITS: '0',TRACKER_EDITORS: k.aliceIdentity, ...extra }, stdio: ['ignore', 'pipe', 'pipe'] });k.server.stdout.on('data', d => k.logs.server += d); k.server.stderr.on('data', d => k.logs.server += d);let up = false;for (let i = 0; i < 700 && !up; i++) { try { up = (await fetch(BASE + '/')).ok; } catch { await sleep(250); } }if (!up) throw new Error('tracker did not come up\n' + k.logs.server);// sign in over the login button's return (GET /login/callback?ident_code=…)const login = async (who, headers = {}, cookie = null) => {const code = await k.ident.selectorCode(who, k.app, BASE);const r = await fetch(BASE + '/login/callback?ident_code=' + code, { redirect: 'manual', headers: { 'x-client-ip': '10.9.9.1', ...(cookie ? { cookie } : {}), ...headers } });const sc = r.headers.get('set-cookie');return { cookie: sc ? sc.split(';')[0] : null, setCookie: sc, status: r.status, location: r.headers.get('location') };};k.aliceSession = await login(alice); k.bobSession = await login(bob);k.login = login;let n = 0;k.emit = async (event, args, cookie, raw) => {const r = await fetch(BASE + '/__hl/emit', { method: 'POST', headers: { 'content-type': 'application/json', ...(cookie ? { cookie } : {}) }, body: J({ t: 'emit', i: ++n, event, payload: args }) });const t = await r.text(); let j = null; try { j = JSON.parse(t); } catch {}return { status: r.status, value: j && j.value, raw: t, setCookie: r.headers.get('set-cookie') };};k.get = async (path, cookie, headers = {}) => { const r = await fetch(BASE + path, { redirect: 'manual', headers: { ...(cookie ? { cookie } : {}), ...headers } }); return { status: r.status, headers: r.headers, body: await r.text() }; };k.stop = async () => {try { k.server.kill('SIGTERM'); } catch {}await sleep(500);try { await k.ident.stop(); } catch {}try { await k.tmdb.stop(); } catch {}rmSync(SCRATCH, { recursive: true, force: true });};return k;}
Branches
Latest commits
- 043624b2theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
- 05d89fd0deploy: security gate (tests/security.mjs)mre
- 2ae8a47bMerge branch 'sk-sec'mre
- 8fee5d52sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
- 944ad51eSK: report reports/SK-sec.md, LOGsk
- 415487c1SK: import budget per user + id type check, gate checkssk
- 7b8a4f74security audit SK: nosniff + image sandbox headers, face id checks, adult follow, login budget + new session at login, guest-link budget, tests/security.mjssk
- f0f26c5areports: T18 section (gates, boot-gate, 3x3 table, search + short-id compare)mre
- 2a8682a1deploy.sh GATES: tests/warmstart.mjsmre
- 3761338breports/T17-boot.md: handoff (phase table, fix, numbers so far, open proof)mre
- 52e09eb2boot: sync window 1000 ms (the gates ask for a complete start), README boot-time sectionmre
- c87149e8tests/warmstart.mjs: the progressive start proven over HTTP (note in the window, 503 short id, after: everything); bootBeginmre
- 593a6350boot: resumable start-up scan, the server listens first (T17)mre
- be4890a0reports: H2 hydration audit (no test change needed)mre
- 1f9c8bf4re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
- c1df88eddocker-compose: HL_GC_TABLE_LOAD=62 (tracker mission 048, T16 real-data numbers)mre
- d0a82867mission 048: report, LOG (HL_GC_TABLE_LOAD=62 measured)mre
- 2d4be66fre-vendor Hybriel 5df4eb7e (GC: HL_GC_TABLE_LOAD knob, mission 406)mre
- 99e7c8b9tests: realdata-m035-radii, repro-t38, realdata-060-backfill ports from env (REAL_PORT, REAL_CHROME, REPRO_CHROME), defaults unchangedmre
- 4625aa22re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre