Old links: old usernames are matched case-blind (1,044 of the reconcile's 2,147 were mixed case and were skipped); a case clash points nowhere. e2e 124/124

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-17 09:35:10 -06:00
parent a8a1a8eec7
commit 69d8271c61
2 changed files with 7 additions and 5 deletions
+3 -3
View File
@@ -244,8 +244,8 @@ async function main() {
const sf = await (await fetch(BASE + '/api/spotlight-feed')).json(); ok(sf.items.length === 1 && sf.items[0].id === P3, 'the DownlineHydra feed lists the delivering Spotlight');
console.log('\n-- old links and dormant old programs');
r = await admin('/api/admin/oldrefs', { oldrefs: { oldmember: 'memberone', 'bad key!': 'x' } }); ok(r.total === 1 && r.skipped === 1, 'oldrefs loaded (a bad key skipped)', r);
for (const [from, to] of [['/?oldmember', '/memberone'], ['/index.php?oldmember', '/memberone'], ['/splashpg.php?r=oldmember', '/memberone'], ['/lcp.php?r=oldmember', '/memberone'], ['/join.php?r=oldmember', '/memberone'], ['/login.php', '/my'], ['/faq.php', '/guides/faq'], ['/whatever.php', '/'], ['/?nobody', '/']]) {
r = await admin('/api/admin/oldrefs', { oldrefs: { oldmember: 'memberone', OldTwo: 'membertwo', 'bad key!': 'x', Dup: 'memberone', dup: 'membertwo' } }); ok(r.total === 2 && r.skipped === 3 && r.clashes === 1, 'oldrefs loaded: a mixed-case name kept, a bad key and a case clash left out', r);
for (const [from, to] of [['/?oldmember', '/memberone'], ['/index.php?oldmember', '/memberone'], ['/splashpg.php?r=oldmember', '/memberone'], ['/lcp.php?r=oldmember', '/memberone'], ['/join.php?r=oldmember', '/memberone'], ['/login.php', '/my'], ['/faq.php', '/guides/faq'], ['/whatever.php', '/'], ['/?oldtwo', '/membertwo'], ['/?OLDTWO', '/membertwo'], ['/?dup', '/'], ['/?nobody', '/']]) {
const x = await fetch(BASE + from, { redirect: 'manual' }); ok(x.status === 301 && x.headers.get('location') === to, 'old link ' + from + ' -> ' + to, x.headers.get('location'));
}
r = await admin('/api/admin/dormant', { packets: [{ oldId: '10010', oldUsername: 'oldm2', hubId: 'h_' + '2'.repeat(16), name: 'Team Build Machine', url: 'https://teambuildmachine.example.com/oldm2', added: '2022-04-21' }, { oldId: 'x', hubId: 'h_1', name: 'bad', url: 'nope' }] });
@@ -271,7 +271,7 @@ async function main() {
console.log('\n-- staging test switch + admin');
r = await admin('/api/admin/test-member', { address: ethers.Wallet.createRandom().address, username: 'tester1' }); ok(r.ok && r.member.netOk && r.member.testMember, 'staging test switch marks a test network member');
ok((await fetch(BASE + '/api/admin/status')).status === 401, 'admin needs the token');
const st = await admin('/api/admin/status'); ok(st.packets.approved === 1 && st.packets.shown === 3 && st.shop.watching && st.oldrefs === 1, 'admin status', st.packets);
const st = await admin('/api/admin/status'); ok(st.packets.approved === 1 && st.packets.shown === 3 && st.shop.watching && st.oldrefs === 2, 'admin status', st.packets);
console.log('\n' + pass + ' passed, ' + fail + ' failed');
if (fail) { fs.writeFileSync(path.join(OUT, 'e2e-app.log'), log); console.log('app log: qa/out/e2e-app.log'); }
+4 -2
View File
@@ -581,9 +581,11 @@ const server = http.createServer(async (req, res) => {
if (p === '/api/admin/oldrefs' && req.method === 'POST') {
let b; try { b = JSON.parse((await readRaw(req, 4 * 1024 * 1024)).toString('utf8')); } catch (e) { return json(res, 400, { error: 'bad json' }); }
if (!b || !b.oldrefs || typeof b.oldrefs !== 'object') return json(res, 400, { error: 'oldrefs object required' });
const o = {}; for (const [k, v] of Object.entries(b.oldrefs)) if (/^[a-z0-9_.-]{2,40}$/.test(k) && NAME_RE.test(String(v))) o[k] = String(v);
// old usernames are matched case-blind (the lookup lowercases); two old names that differ only in case point nowhere (a clash)
const o = {}, clash = new Set(); for (const [k0, v] of Object.entries(b.oldrefs)) { const k = String(k0).toLowerCase(); if (!/^[a-z0-9_.-]{2,40}$/.test(k) || !NAME_RE.test(String(v))) continue; if (o[k] && o[k] !== String(v)) clash.add(k); o[k] = String(v); }
for (const k of clash) delete o[k];
fs.writeFileSync(path.join(C.dataDir, 'oldrefs.json'), JSON.stringify(o)); oldRefs = { at: 0, map: {} };
return json(res, 200, { ok: true, total: Object.keys(o).length, skipped: Object.keys(b.oldrefs).length - Object.keys(o).length });
return json(res, 200, { ok: true, total: Object.keys(o).length, skipped: Object.keys(b.oldrefs).length - Object.keys(o).length, clashes: clash.size });
}
// old YourProgramBuilder member programs as dormant packets (myheads.csv from the reconcile): {packets: [{oldId, oldUsername, hubId,
// name, url, added}]}. Only people the hub knows (hubId). Nothing shows until the owner confirms it with a {id} link on My packets.