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
- eee0b513|||PR ident#34 part: test-hook classes replaced by name/element/attribute selectors (tests adjusted), the shared lead/message/notice looks are statics in styles.hlmre
- ccd6d0c4ident#34: browser gate: rowButton finds the row's button by namemre
- 24dd414eident#34: the shared lead, message and notice looks are statics in components/styles.hl, imported by the components (lib/looks.hl gone)mre
- 03ed26c7ident#34: access.hl: the remaining lead classes droppedmre
- 1d066c42ident#34: access.hl drops its unstyled lead class (the shared lead rule would otherwise mute it)mre
- 1e1dd7b4ident#34: the access page keeps its lead class string (the page has no ident-card, so its lead line was never muted; a shared rule would change the look)mre
- 89ac6553ident#34: the lead, message and notice lines are named with Style.pLead / pMessage / pNotice (shared bodies in lib/looks.hl) instead of class stringsmre
- e84be3deident#34: browser gate lists the Edit/Delete buttons by namemre
- fb7111faident#34: access page: unstyled test-hook classes (idrow, never, who, whoname, appname, neverrevoke) dropped; the tests use element/name selectorsmre
- 9f2ad803ident#34: notification switches: push/email by name=..., locked by aria-disabled, the switch look is the role=switch button (no switch/push/email/locked classes)mre
- e0f0ddaaident#34: inbox: the Mark read/unread button is styled as the button of its note-foot, the icon is found as the row's img (no toggle/icon classes)mre
- 16b49756ident#34: unused row classes (choice, usedrow, kind, shortid) droppedmre
- f9d6fb38ident#34: apps and identity rows: the Edit/New secret/Delete buttons carry name=..., the API key is found by its element; unused row classes (app, identity, shortid) droppedmre
- b323265aMerge branch 'f5-styles' into mainIdent
- 9ced53c3|||PR ident#33 ident#35 every component's styles live in its own Style block; styles.hl keeps the page-wide rest; the account bar is phone first (min-width: 60rem block); the avatar preview is hidden with the hidden attribute (ident#34 in part)mre
- f28333e4ident#33 ident#35: styles.hl keeps only the accent, the page column and the shared patterns; the account bar is written phone first (base rule + one min-width: 60rem block) instead of a max-width overridemre
- 5b4541fcident#33: the selector sign-in frame's rules move into embed.hl's Stylemre
- 00235f21ident#33: the per-app notification switches move into appsettings.hl's Stylemre
- 2249945cident#33: the inbox and connection list rules move into inbox.hl's Stylemre
- f2d9f79fident#33: the apps list and the secret box move into apps.hl's Stylemre