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
- 8e5f2ceflog: SL1 deployedmre
- 29f34212log: SL1 deploy startedmre
- 529dd741Merge sl1-slices: slice details repair and person fill (SL1)mre
- 8a83316blog: SL1 result, session drain slowermre
- 35e93e8dSL1: slice the details repair and person fill: catalog lists changed in place, 40 ms fill steps, people created in steps, writes one table per tickmre
- 72c9119flog+status: SL1 startedmre
- d74620fcmission SL1: slice repair and person fillmre
- 5d542d73log+status: ST1 resultmre
- 3945eb81ST1: stall diagnosis reportmre
- 404733aclog: ST1 startedmre
- 3e3d5a55mission ST1: stall diagnosismre
- 9c3180eblog+status: RV28d measured after deploymre
- fdf10b1alog: RV28d deployed on day38bmre
- 320005e9log: RV28d merged, deploy runningmre
- a8fef27dRV28d: reportmre
- 2bae8373RV28d: re-vendor Hybriel set day38b (source 1e554d75, bin 5ff2a46d)mre
- 16b3354aMerge branch 'main' into rv28cmre
- 6f4f27d8log: RV28d started (day38b)mre
- e6cf03ffmission RV28d: rv28c onto day38bmre
- 3ccaee19status: live sweep freeze, waiting for Apollomre