gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchf2-shellc3a40ff6|||PR ident#40 one shell for the app and /start (account part off on /start, #40.1); startshell.hl removed; unused signOut faces gone (#40.4)mref2-shell/tests/gitoria-origin.mjs

7.7 KB

  1. // tests/gitoria-origin.mjs — GATE G48: gitoria's registration in ident answers every repo address.
  2. // gitoria serves its selector on <repo>.gitoria.worldapi.org with the one API key of its main address. The September registration holds the main
  3. // address only, so ident refused the repo addresses ("ident does not answer this site"). At load ident now adds the wildcard origin
  4. // 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
  5. // 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
  6. // main address still is, a lookalike / a sub-sub-domain / another app's key are still refused, and a second restart changes nothing.
  7. // Own server (NEVER the dev server, NEVER real mail): ident on G48_PORT (default 8780), storage .scratch/gitoria-origin-gate (wiped at start).
  8. // Run: node tests/gitoria-origin.mjs (G48_APP=<checkout> runs it against that code)
  9. import { spawn } from 'node:child_process';
  10. import { readFileSync, readdirSync, rmSync, mkdirSync, writeFileSync } from 'node:fs';
  11. import { dirname, join } from 'node:path';
  12. import { fileURLToPath } from 'node:url';
  13. const APP = process.env.G48_APP || join(dirname(fileURLToPath(import.meta.url)), '..');
  14. const G = join(APP, '.scratch/gitoria-origin-gate');
  15. const PORT = Number(process.env.G48_PORT || 8780);
  16. const ID = 'http://127.0.0.1:' + PORT;
  17. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  18. let passed = 0, failed = 0;
  19. const check = (name, ok, detail = '') => { if (ok) { passed++; console.log(' ok ' + name); } else { failed++; console.log(' FAIL ' + name + (detail ? ' — ' + detail : '')); } };
  20. rmSync(G, { recursive: true, force: true });
  21. mkdirSync(G, { recursive: true });
  22. const sessDir = join(G, 'sess');
  23. const mail = join(G, 'mail.txt');
  24. let p = null, out = '', runs = 0;
  25. const start = async () => {
  26. runs++; out = '';
  27. 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'] });
  28. p.stdout.on('data', d => { out += d; }); p.stderr.on('data', d => { out += d; });
  29. const q = p;
  30. q.on('exit', () => writeFileSync(join(G, 'ident-' + runs + '.log'), out));
  31. 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'); } }
  32. };
  33. 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; };
  34. // a visitor: its own cookie jar
  35. const visitor = () => {
  36. const jar = {};
  37. 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); } };
  38. const cookie = () => Object.entries(jar).map(([k, v]) => k + '=' + v).join('; ');
  39. 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() }; };
  40. 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() }; };
  41. let n = 0;
  42. 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) }; } };
  43. return { get, post, face };
  44. };
  45. 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; };
  46. 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') }; };
  47. const MAIN = 'https://gitoria.worldapi.org';
  48. try {
  49. await start();
  50. const a = visitor();
  51. await a.get('/');
  52. const em = '[email protected]';
  53. await a.post('/api/code', { email: em });
  54. const vc = await a.face('verifyCode', [em, lastCode(em), 'Europe/Vienna']);
  55. check('setup: signed in', !!(vc.account && vc.account.email === em), JSON.stringify(vc).slice(0, 160));
  56. const g = await a.face('appCreate', [{ name: 'gitoria.worldapi.org', origins: [MAIN] }]);
  57. const t = await a.face('appCreate', [{ name: 'tickets.worldapi.org', origins: ['https://tickets.worldapi.org'] }]);
  58. const gk = g.app && g.app.apiKey, tk = t.app && t.app.apiKey;
  59. 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));
  60. check('setup: a second app (tickets) is registered', /^pk_/.test(tk || ''), JSON.stringify(t).slice(0, 200));
  61. // BEFORE the load step: a repo address is refused (the bug)
  62. const before = await sel(gk, 'https://calendar.gitoria.worldapi.org');
  63. check('BEFORE: a repo address is refused (403, no CORS) — the reported bug', before.status === 403 && before.acao == null, JSON.stringify(before));
  64. check('BEFORE: the main address is answered', (await sel(gk, MAIN)).status === 200);
  65. // restart on the same storage: the load step adds the wildcard
  66. await stop();
  67. await start();
  68. 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));
  69. for (const sub of ['calendar', 'mpackdb', 'a-b-1']) {
  70. const r = await sel(gk, 'https://' + sub + '.gitoria.worldapi.org');
  71. 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));
  72. }
  73. const m = await sel(gk, MAIN);
  74. check('AFTER: the main address is still answered', m.status === 200 && m.acao === MAIN, JSON.stringify(m));
  75. 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']) {
  76. const r = await sel(gk, bad);
  77. check('AFTER: ' + bad + ' is still refused', r.status === 403 && r.acao == null, JSON.stringify(r));
  78. }
  79. const tr = await sel(tk, 'https://calendar.gitoria.worldapi.org');
  80. check('AFTER: another app\'s key is not opened to gitoria\'s repo addresses', tr.status === 403, JSON.stringify(tr));
  81. const tr2 = await sel(tk, 'https://x.tickets.worldapi.org');
  82. check('AFTER: the tickets app got no wildcard of its own', tr2.status === 403, JSON.stringify(tr2));
  83. // a second load changes nothing
  84. await stop();
  85. await start();
  86. check('a second load adds nothing (0 apps)', /ident: 0 app got the wildcard origin/.test(out), out.slice(0, 300));
  87. const r2 = await sel(gk, 'https://calendar.gitoria.worldapi.org');
  88. check('a second load: the repo address is still answered', r2.status === 200, JSON.stringify(r2));
  89. } catch (err) {
  90. check('gate ran without an exception', false, String(err && err.stack || err));
  91. } finally {
  92. await stop();
  93. }
  94. console.log(`\ngitoria-origin: ${passed} passed, ${failed} failed`);
  95. process.exit(failed ? 1 : 0);

Branches

Latest commits

  • c3a40ff6|||PR ident#40 one shell for the app and /start (account part off on /start, #40.1); startshell.hl removed; unused signOut faces gone (#40.4)mre
  • 060f3870ident#40.4: use the shell sign-out faces in regression gatesmre
  • 9b94aa6aMerge branch 'f1b-cleanup' into mainIdent
  • edcfce3f|||PR ident#41 ident#43 ident#44 login error page as a component (same status codes and text, pixel-identical), declarations and route wiring cleaned upmre
  • 3ac85995ident#43 ident#44: plain declarations for never-reassigned lets, one envString helper, named route functions and audience rule out of project.hlmre
  • c7eef14aMerge branch 'nv1-navigate' into mainIdent
  • 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