GET /api/admin/member-extra?email= (Marty 2026-11-14, network hub member lookup): read-only, admin Bearer; what the member card leaves out: optedOut (drip unsubscribe), updatesOptIn, tank {inTank, ready {readyAt, holdUntil}, adoptions summary}, fraud {flags, suspended, suspendedReason}. qa/member-extra.mjs in the member run (401 without/with a wrong password, 404 unknown, fields present). iap-qa member: ALL PASSED

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-14 12:57:33 -06:00
parent 4787390e8b
commit 82eab8016b
3 changed files with 37 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
// GET /api/admin/member-extra (2026-11-14): the network hub's member lookup reads opt-out, tank and hold state here. Read-only.
// Runs against LOCAL (bash qa/run.sh member starts it). Admin = Bearer localtest.
const B = process.env.LOCAL || 'http://127.0.0.1:8796';
let pass = 0, fail = 0; const ok = (c, m, x) => { if (c) pass++; else { fail++; console.log('[bug] member-extra ' + m + (x ? ' :: ' + x : '')); } };
const email = 'mx' + Date.now() + '@example.com'; const ip = '198.51.100.' + (20 + Math.floor(Math.random() * 200));
const H = { 'Content-Type': 'application/json', 'X-Forwarded-For': ip, 'User-Agent': 'Mozilla/5.0 MemberExtraQA' };
const post = (p, b) => fetch(B + p, { method: 'POST', headers: H, body: JSON.stringify(b) }).then(r => r.json().catch(() => ({})));
const get = (q, auth) => fetch(B + '/api/admin/member-extra?email=' + encodeURIComponent(q), { headers: auth ? { Authorization: 'Bearer ' + auth } : {} });
try {
ok((await get(email)).status === 401, 'no admin header is refused');
ok((await get(email, 'wrong')).status === 401, 'a wrong admin password is refused');
ok((await get(email, 'localtest')).status === 404, 'an unknown email is 404');
const st = await post('/api/auth/email/start', { email, fts: Date.now() - 8000, fage: 8000 });
if (st.devCode) await post('/api/auth/email/verify', { email, code: st.devCode });
const r = await get(email, 'localtest'); const j = await r.json().catch(() => null);
ok(r.status === 200 && j, 'a known account answers', r.status);
ok(j && j.tank && typeof j.tank.inTank === 'boolean', 'tank.inTank is a boolean', JSON.stringify(j));
ok(j && 'optedOut' in j, 'optedOut is present');
const w = await fetch(B + '/api/admin/member-extra?email=' + encodeURIComponent(email), { method: 'POST', headers: { Authorization: 'Bearer localtest' } });
ok(w.status !== 200 || !(await w.text()).includes('optedOut'), 'POST is not a route (read-only)');
} catch (e) { fail++; console.log('[bug] member-extra crashed :: ' + e.message); }
console.log('member-extra: ' + pass + ' passed, ' + fail + ' failed');
process.exit(fail ? 1 : 0);
+1 -1
View File
@@ -66,7 +66,7 @@ elif [ "$MODE" = "sso" ]; then
node qa/networksso.test.cjs || status=1
node qa/networksso.e2e.mjs || status=1
elif [ "$MODE" = "member" ]; then
start_local 8796 && { LOCAL=http://127.0.0.1:8796 node qa/walk.mjs member || status=1; }; stop_local 8796
start_local 8796 && { LOCAL=http://127.0.0.1:8796 node qa/walk.mjs member || status=1; LOCAL=http://127.0.0.1:8796 node qa/member-extra.mjs || status=1; }; stop_local 8796
node qa/networksso.test.cjs || status=1 # network sign-in with the other site: tokens, replay, open redirects, loop guard
node qa/networksso.e2e.mjs || status=1 # both servers locally, a real browser across them (skips if the other repo is not beside this one)
node qa/tank-hold.mjs || status=1
+13
View File
@@ -3259,6 +3259,19 @@ const server = http.createServer(async (req, res) => {
if (!a) return json(res, 404, { error: 'No member matches "' + q.slice(0, 60) + '".' });
return json(res, 200, Object.assign(await adminMember.view(a.email), { pwPasses: pwPasses.get(String(a.email).toLowerCase()) || null })); // mint passes on the card (2026-10-10)
}
// -- admin: the network hub's member lookup (Marty 2026-11-14, read-only): what the member card leaves out. GET ?email=
if (p === '/api/admin/member-extra' && req.method === 'GET') {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
const e = String(u.searchParams.get('email') || '').trim().toLowerCase();
const a = e ? await accounts.byEmail(e) : null;
if (!a) return json(res, 404, { error: 'no such account' });
const r = tank.readyRec(e);
return json(res, 200, {
optedOut: await drip.isUnsubscribed(e).catch(() => null), updatesOptIn: await updates.optedIn(e).catch(() => null),
tank: { inTank: !a.sponsorRef && !a.memberId, ready: r ? { readyAt: r.readyAt || null, holdUntil: r.readyAt ? r.readyAt + tank.READY_MS : null } : null, adoptions: await tank.summaryFor(e).catch(() => null) },
fraud: await fraud.get(e).then(f => f && { flags: f.flags || [], suspended: !!f.suspended, suspendedReason: f.suspendedReason || null }).catch(() => null)
});
}
if (p === '/api/admin/member' && req.method === 'PATCH') {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
const b = await readBody(req);