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
- e0db0d1bHM60 report: tracker#60 packed short-ID ownersmre
- e822524bstatus wordingmre
- 1c7f0480log: HM60/HM61 startedmre
- 2841d215missions HM60 HM61mre
- 289c6ce4HM1 report: heap object breakdownmre
- 2e7d6257log: HM1 startedmre
- 2f790465mission HM1: heap object breakdownmre
- a18957falog: evening re-measure after CBmre
- aac9a98dlog: evening re-measure startmre
- 45163bd4log: person/tmdb error hypothesismre
- cb38de2blog: swap 503 causemre
- fd10c3d5log: CB livemre
- 7557c025log: CB deploy try 2mre
- 06a7534aMerge branch 'cb'mre
- 2f8030d6log: CB gates greenmre
- 498bf644log: CB gates startmre
- f59c2847gc1: bound the five request caches (shows.hl cacheLimit)mre
- 6ea2c6d6log: morning re-measure 11-04mre
- 446290f0log: GC1 livemre
- 8e6aa91dlog: GC1 deploy retrymre