ident
All repositories: gitoria
7.7 KB
// tests/gitoria-origin.mjs — GATE G48: gitoria's registration in ident answers every repo address.// gitoria serves its selector on <repo>.gitoria.worldapi.org with the one API key of its main address. The September registration holds the main// address only, so ident refused the repo addresses ("ident does not answer this site"). At load ident now adds the wildcard origin// https://*.gitoria.worldapi.org to the app named gitoria.worldapi.org (and to no other app). This gate registers the app the old way (main address// only), proves a repo address is refused, restarts ident on the same storage (the load step), and proves: the repo address is answered with CORS, the// main address still is, a lookalike / a sub-sub-domain / another app's key are still refused, and a second restart changes nothing.// Own server (NEVER the dev server, NEVER real mail): ident on G48_PORT (default 8780), storage .scratch/gitoria-origin-gate (wiped at start).// Run: node tests/gitoria-origin.mjs (G48_APP=<checkout> runs it against that code)import { spawn } from 'node:child_process';import { readFileSync, readdirSync, rmSync, mkdirSync, writeFileSync } from 'node:fs';import { dirname, join } from 'node:path';import { fileURLToPath } from 'node:url';const APP = process.env.G48_APP || join(dirname(fileURLToPath(import.meta.url)), '..');const G = join(APP, '.scratch/gitoria-origin-gate');const PORT = Number(process.env.G48_PORT || 8780);const ID = 'http://127.0.0.1:' + PORT;const sleep = (ms) => new Promise(r => setTimeout(r, ms));let passed = 0, failed = 0;const check = (name, ok, detail = '') => { if (ok) { passed++; console.log(' ok ' + name); } else { failed++; console.log(' FAIL ' + name + (detail ? ' — ' + detail : '')); } };rmSync(G, { recursive: true, force: true });mkdirSync(G, { recursive: true });const sessDir = join(G, 'sess');const mail = join(G, 'mail.txt');let p = null, out = '', runs = 0;const start = async () => {runs++; out = '';p = spawn(join(APP, 'bin/hybriel'), ['project.hl'], { cwd: APP, env: { ...process.env, SMTP_HOST: '', SMTP_USER: '', SMTP_PASSWORD: '', IDENT_PORT: String(PORT), IDENT_STORAGE: join(G, 'ident'), IDENT_SESSIONS: sessDir + '/', IDENT_MAIL_SINK: mail, IDENT_IP_LIMIT: '1000', IDENT_IP_DAY_LIMIT: '1000' }, stdio: ['ignore', 'pipe', 'pipe'] });p.stdout.on('data', d => { out += d; }); p.stderr.on('data', d => { out += d; });const q = p;q.on('exit', () => writeFileSync(join(G, 'ident-' + runs + '.log'), out));for (const end = Date.now() + Number(process.env.IDENT_COLD_MS || 120000); ; await sleep(250)) { try { await fetch(ID + '/', { redirect: 'manual' }); break; } catch { if (Date.now() > end) throw new Error('ident did not come up'); } }};const stop = async () => { if (!p) return; const q = p; p = null; const done = new Promise(r => q.on('exit', r)); try { q.kill(); } catch {} await done; };// a visitor: its own cookie jarconst visitor = () => {const jar = {};const take = (r) => { for (const c of r.headers.getSetCookie()) { const [kv] = c.split(';'); const i = kv.indexOf('='); jar[kv.slice(0, i)] = kv.slice(i + 1); } };const cookie = () => Object.entries(jar).map(([k, v]) => k + '=' + v).join('; ');const get = async (path, headers = {}) => { const r = await fetch(ID + path, { redirect: 'manual', headers: { cookie: cookie(), ...headers } }); take(r); return { status: r.status, location: r.headers.get('location'), text: await r.text() }; };const post = async (path, body, headers = {}) => { const r = await fetch(ID + path, { method: 'POST', redirect: 'manual', headers: { 'content-type': 'application/json', cookie: cookie(), ...headers }, body: JSON.stringify(body) }); take(r); return { status: r.status, text: await r.text() }; };let n = 0;const face = async (event, payload) => { const r = await post('/__hl/emit', { t: 'emit', i: ++n, event, payload }); try { const j = JSON.parse(r.text); return j.ok ? j.value : { transport: r.status, text: r.text.slice(0, 200) }; } catch { return { transport: r.status, text: r.text.slice(0, 200) }; } };return { get, post, face };};const lastCode = (email) => { const l = readFileSync(mail, 'utf8').trim().split('\n').filter(x => x.startsWith(email + ' ')); return l.length ? l[l.length - 1].split(' ')[1] : null; };const sel = async (key, origin) => { const r = await fetch(ID + '/api/selector/identities?key=' + key, { headers: { origin } }); return { status: r.status, acao: r.headers.get('access-control-allow-origin'), cred: r.headers.get('access-control-allow-credentials') }; };const MAIN = 'https://gitoria.worldapi.org';try {await start();const a = visitor();await a.get('/');const em = '[email protected]';await a.post('/api/code', { email: em });const vc = await a.face('verifyCode', [em, lastCode(em), 'Europe/Vienna']);check('setup: signed in', !!(vc.account && vc.account.email === em), JSON.stringify(vc).slice(0, 160));const g = await a.face('appCreate', [{ name: 'gitoria.worldapi.org', origins: [MAIN] }]);const t = await a.face('appCreate', [{ name: 'tickets.worldapi.org', origins: ['https://tickets.worldapi.org'] }]);const gk = g.app && g.app.apiKey, tk = t.app && t.app.apiKey;check('setup: the gitoria app is registered the old way (main address only)', /^pk_/.test(gk || '') && JSON.stringify(g.app.origins) === JSON.stringify([MAIN]), JSON.stringify(g).slice(0, 200));check('setup: a second app (tickets) is registered', /^pk_/.test(tk || ''), JSON.stringify(t).slice(0, 200));// BEFORE the load step: a repo address is refused (the bug)const before = await sel(gk, 'https://calendar.gitoria.worldapi.org');check('BEFORE: a repo address is refused (403, no CORS) — the reported bug', before.status === 403 && before.acao == null, JSON.stringify(before));check('BEFORE: the main address is answered', (await sel(gk, MAIN)).status === 200);// restart on the same storage: the load step adds the wildcardawait stop();await start();check('the load step says it added the wildcard to one app', /ident: 1 app got the wildcard origin/.test(out), out.slice(0, 300));for (const sub of ['calendar', 'mpackdb', 'a-b-1']) {const r = await sel(gk, 'https://' + sub + '.gitoria.worldapi.org');check('AFTER: https://' + sub + '.gitoria.worldapi.org is answered with CORS and credentials', r.status === 200 && r.acao === 'https://' + sub + '.gitoria.worldapi.org' && r.cred === 'true', JSON.stringify(r));}const m = await sel(gk, MAIN);check('AFTER: the main address is still answered', m.status === 200 && m.acao === MAIN, JSON.stringify(m));for (const bad of ['https://evil-gitoria.worldapi.org', 'https://gitoria.worldapi.org.evil.com', 'https://a.b.gitoria.worldapi.org', 'http://calendar.gitoria.worldapi.org', 'https://calendar.worldapi.org']) {const r = await sel(gk, bad);check('AFTER: ' + bad + ' is still refused', r.status === 403 && r.acao == null, JSON.stringify(r));}const tr = await sel(tk, 'https://calendar.gitoria.worldapi.org');check('AFTER: another app\'s key is not opened to gitoria\'s repo addresses', tr.status === 403, JSON.stringify(tr));const tr2 = await sel(tk, 'https://x.tickets.worldapi.org');check('AFTER: the tickets app got no wildcard of its own', tr2.status === 403, JSON.stringify(tr2));// a second load changes nothingawait stop();await start();check('a second load adds nothing (0 apps)', /ident: 0 app got the wildcard origin/.test(out), out.slice(0, 300));const r2 = await sel(gk, 'https://calendar.gitoria.worldapi.org');check('a second load: the repo address is still answered', r2.status === 200, JSON.stringify(r2));} catch (err) {check('gate ran without an exception', false, String(err && err.stack || err));} finally {await stop();}console.log(`\ngitoria-origin: ${passed} passed, ${failed} failed`);process.exit(failed ? 1 : 0);
Branches
Latest commits
- 644f9775|||PR ident#36 navigate() instead of window.location in the shell, start shell and homemre
- 4ca2f921deploy.sh: tar --hard-dereference so backups hold no hard linksmre
- 23971fb7ident#49: media queries in the language's @media formmre
- 73f4f97dident: re-vendor to hybriel day38b (mpackdb store-open fix)mre
- aa056c03ident: a startup error prints its message before exit 1 (hybriel#247)mre
- ee37a861ident#G48: gitoria's registration gets the wildcard origin of its repo addresses at load (gate tests/gitoria-origin.mjs)mre
- dc6d486fident#27: the docs gate expects the new Access entry in the main menumre
- d277633cident#27: README: identity access and the introspect endpointmre
- e999b0d3ident#27: the Access tab — one key per identity for all its apps: give access in three steps, the overview matrix, a cell's sheet (since, last use, level, rotate, revoke), the app's check POST /api/introspect, agent identities hidden from the login picker, an inbox icon in the header's icon style (gate: tests/access.mjs)mre
- 436206fcident#47: deploy.sh runs the sign-in gate on the deploy's own port slot, like the sessionwrites and docs gates (the default 8700 can be taken by another process)mre
- a4887ea3ident#47: the selector's sign-in frame no longer has a Continue button; the identity row itself is the link (gate tests/signin.mjs fails on the old code)mre
- d8ec703dident#45: /docs shows docs/IDENT.md (hl:markdown, vendored from ac1ed9da), one Docs entry in the main menu, README for developers only, gates tests/docs.mjs and tests/sessionwrites.mjs in deploy.shmre
- ec6aad35Merge branch 'a28g-amp-callsites' into d45-docsmre
- 6bfbd3f2ident#45: docs/IDENT.md, what ident is and how it works; CONCEPT.md marks one id per app as droppedmre
- c0edca26ident#28 A28G: write & at every call that hands a session to an &-parameter; gate tests/sessionwrites.mjs pins that sign-in, pending address, embed sign-in and selector land in the session filesmre
- 80965c08ident#28: README says the deploy goes through the standbymre
- 2f41670cident#28: ident-standby service on port 45012 (no background round in the standby) and deploy.sh hands over through standby-swap.shmre
- a544b261ident#28: README names the new vendored Hybrielmre
- 716860b0ident#28: gates follow Hybriel ac1ed9da (lazy sessions, meta attribute order, JSON key order, default X-Frame-Options switched off for the embed page)mre
- 889e00fbident#28: Hybriel master ac1ed9da (sessions reload a newer file, a replayed reconnect carries the server session); a startup fault exits 1 (on Error)mre