From 94067cf0005387313301de0e9b8d071a264afbfb Mon Sep 17 00:00:00 2001 From: martbost Date: Mon, 16 Nov 2026 05:06:03 -0600 Subject: [PATCH] networksso hub e2e: the wallet partner takes the hub hook (Marty 2026-11-16) The stand-in wallet partner now runs the real wallet-site hubevents.js (from ../../5xyourteam/app, skipped when absent) behind POST /api/hub/events, and the hub hooks it (HUB_HOOK_EVERY_MS 1 s). New cases: the partner session open in the browser ends after Sign out everywhere on LinkSpin (member.signedout, matched by the member wallet), and a partner session opened before a hub block ends after it (member.blocked). Same file in InstantAdPay and LinkSpin: ALL PASSED from both. Co-Authored-By: Claude Opus 5.5 --- qa/networksso-hub.e2e.mjs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/qa/networksso-hub.e2e.mjs b/qa/networksso-hub.e2e.mjs index d00baee..d2a847d 100644 --- a/qa/networksso-hub.e2e.mjs +++ b/qa/networksso-hub.e2e.mjs @@ -7,6 +7,8 @@ // 3. same browser, the partner's "Sign in with InstantAdPay": the hub answers with a token carrying the wallet // 4. Sign out everywhere on LinkSpin: the hub sign-in ends, a fresh partner check gets "nobody" from the hub // 5. a blocked member: the hub refuses; a replayed hub token is refused; no email-code request by any network sign-in +// The partner takes the hub's hook with the real wallet-site hubevents.js (from ../../5xyourteam/app, 2026-11-16): its session +// open on the partner ends after Sign out everywhere (step 4) and after a hub block (step 5). import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; @@ -23,6 +25,7 @@ const HUB_DIR = [process.env.HUB_DIR, path.resolve(HERE, '../../network-hub')].f if (!PEER || !HUB_DIR) { console.log('SKIP hub sign-in e2e: needs the other site and network-hub (with lib/sso.js) beside this repo.'); process.exit(0); } const IAP_DIR = HERE_IS_IAP ? HERE : PEER, LS_DIR = HERE_IS_IAP ? PEER : HERE; const require = createRequire(import.meta.url); +const WALLET_DIR = [process.env.WALLET_SITE_DIR, path.resolve(HERE, '../../5xyourteam/app')].filter(Boolean).find(d => fs.existsSync(path.join(d, 'hubevents.js'))); const PW = process.env.PW || 'D:/Projects/MarketingAgent/qa-tester/node_modules/playwright'; const { chromium } = (await import(pathToFileURL(PW + '/index.js').href)).default; const { ethers } = require(path.join(IAP_DIR, 'node_modules', 'ethers')); @@ -48,8 +51,8 @@ function boot(name, dir, port, script, extra) { const p = spawn(process.execPath, [script], { cwd: dir, stdio: ['ignore', 'pipe', 'pipe'], env }); p.stdout.on('data', d => logs[name] += d); p.stderr.on('data', d => logs[name] += d); return p; } -const srvH = boot('hub', HUB_DIR, HP, 'server.js', { HUB_URL: '', HUB_SSO: '', HUB_ADMIN_SECRET: ADMIN, - HUB_SITES: JSON.stringify({ iap: { secret: K.iap }, linkspin: { secret: K.linkspin }, fivex: { secret: K.fivex } }), +const srvH = boot('hub', HUB_DIR, HP, 'server.js', { HUB_URL: '', HUB_SSO: '', HUB_ADMIN_SECRET: ADMIN, HUB_HOOK_EVERY_MS: '1000', + HUB_SITES: JSON.stringify({ iap: { secret: K.iap }, linkspin: { secret: K.linkspin }, fivex: Object.assign({ secret: K.fivex }, WALLET_DIR ? { hook: P + '/api/hub/events' } : {}) }), HUB_SSO_SITES: JSON.stringify({ iap: IAP, linkspin: LS, fivex: P }) }); const srvI = boot('iap', IAP_DIR, IP, 'server.js', { LS_URL: LS, HUB_SECRET: K.iap, HUB_SITE: 'iap' }); const srvL = boot('ls', LS_DIR, LP, 'server.js', { IAP_URL: IAP, HUB_SECRET: K.linkspin, HUB_SITE: 'linkspin' }); @@ -62,10 +65,14 @@ const partnerLog = []; const origLog = console.log; console.log = (...a) => { if N.init({ self: 'fivex', peer: 'iap', peerBase: () => IAP, from: { iap: () => IAP, linkspin: () => LS }, isProd: false, dataDir: TMP, defaultPath: '/team', member: async req => { const s = PS.get(sidOf(req)); return s ? { address: s.address } : null; }, accept: async (e, req, v) => (v && v.wallet ? { ok: true } : { fallback: 'no wallet in the token' }), - signIn: async (e, req, v) => { const id = crypto.randomBytes(16).toString('hex'); PS.set(id, { address: v.wallet, via: v.iss }); return 'fx.sid=' + id + '; Path=/; HttpOnly; SameSite=Lax'; }, + signIn: async (e, req, v) => { const id = crypto.randomBytes(16).toString('hex'); PS.set(id, { address: v.wallet, via: v.iss, at: Date.now() }); return 'fx.sid=' + id + '; Path=/; HttpOnly; SameSite=Lax'; }, landing: to => to, signinPath: to => '/signin?to=' + encodeURIComponent(to) }); +// the hub's hook into the partner: the real wallet-site module, ending partner sessions made before the event +const HE = WALLET_DIR ? require(path.join(WALLET_DIR, 'hubevents.js')) : null; +if (HE) HE.init({ dataDir: TMP, site: 'fivex', end: who => { let n = 0; for (const [k, x] of PS) if (x.at <= who.before && who.match(x)) { PS.delete(k); n++; } return n; } }); const partner = http.createServer(async (req, res) => { const u = new URL(req.url, 'http://x'); + if (HE && u.pathname === '/api/hub/events' && req.method === 'POST') { let raw = ''; for await (const c of req) raw += c; const r = await HE.receive(req.headers, raw); res.writeHead(r.status, { 'Content-Type': 'application/json' }); return res.end(JSON.stringify(r.body)); } if (req.method === 'GET' && await N.page(req, res, u)) return; if (await N.handle(req, res, u)) return; if (u.pathname === '/api/whoami') { res.writeHead(200, { 'Content-Type': 'application/json' }); return res.end(JSON.stringify(PS.get(sidOf(req)) || {})); } @@ -126,13 +133,23 @@ try { ok(out.ok && out.everywhere === true && !(await meOf(ctx, LS)).signedIn, '4. Sign out everywhere: signed out on LinkSpin, the hub confirmed', JSON.stringify(out)); const hubNow = await ctx.request.get(HUB + '/sso/check?site=fivex&st=' + crypto.randomBytes(16).toString('hex') + '&to=%2F', { maxRedirects: 0 }); ok(/none=1&hub=1/.test(hubNow.headers()['location'] || ''), '4. the hub sign-in is gone', hubNow.headers()['location']); - ok(/member\.signedout/.test(JSON.stringify((await hubCall('/v1/admin/export', 'admin', ADMIN, {})).json)) || true, '4. (hooked sites get member.signedout; no hooks in this local run)'); + if (HE) { + let gone = false; for (let i = 0; i < 40 && !gone; i++) { await sleep(250); gone = !(await (await ctx.request.get(P + '/api/whoami')).json()).address; } + ok(gone && HE.view().stats.ended >= 1, '4. the wallet partner session ended too (hub hook member.signedout, matched by the member wallet)', JSON.stringify(HE.view().stats)); + } else console.log('SKIP 4. wallet-site hook: no ../../5xyourteam/app/hubevents.js'); // 5. blocked on the hub: no hub sign-in at all const ctx2 = await browser.newContext({ userAgent: UA }); await ctx2.addCookies([{ name: 'iap.sid', value: await codeSignIn(IAP, A), domain: '127.0.0.1', path: '/' }]); const p2 = await ctx2.newPage(); await p2.goto(IAP + '/my'); await p2.waitForTimeout(1500); ok((await ctx2.cookies(HUB)).some(c => c.name === 'hub.sso'), '5. (a fresh browser signs in on the hub again)'); + // a partner session open in this browser before the block + await p2.goto(P + '/sso/start?mode=go&via=iap&to=' + encodeURIComponent('/team')); await p2.waitForURL(u => String(u).startsWith(P + '/team'), { timeout: 15000 }).catch(() => {}); + const open2 = (await (await ctx2.request.get(P + '/api/whoami')).json()).address === wA; await hubCall('/v1/admin/block', 'admin', ADMIN, { email: A, reason: 'e2e' }); + if (HE) { + let gone = false; for (let i = 0; i < 40 && !gone; i++) { await sleep(250); gone = !(await (await ctx2.request.get(P + '/api/whoami')).json()).address; } + ok(open2 && gone, '5. blocked on the hub: the session open on the wallet partner ends (hub hook member.blocked)', JSON.stringify(HE.view().log.slice(-3))); + } const blocked = await ctx2.request.get(HUB + '/sso/check?site=linkspin&st=' + crypto.randomBytes(16).toString('hex') + '&to=%2F', { maxRedirects: 0 }); ok(/none=1/.test(blocked.headers()['location'] || '') && /sign-in ended \(blocked/.test(logs.hub + '') || /none=1/.test(blocked.headers()['location'] || ''), '5. blocked on the hub: the hub answers nobody', blocked.headers()['location']); // a hub token replayed: mint one by hand for LinkSpin, spend it, try again