Changeset 679924e in Klonkt for test/webfinger-bare-host.test.js


Ignore:
Timestamp:
08/02/2026 08:06:21 AM (5 weeks ago)
Author:
Bart <bart@…>
Branches:
main
Children:
af035e6
Parents:
26c5f71
Message:

WebFinger: de primaire site via de ene bron van waarheid

Een verse instance heeft geen primaire site: is_primary is 0 by default en de
backfill draait alleen op het moment dat de kolom erbij komt. Een site die
daarna wordt aangemaakt laat de instance dus zonder vlag achter.

De HTML-kant merkte daar niets van, want getPrimarySite() valt terug op de
oudste site. Deze route hield zijn eigen is_primary-only kopie aan, precies het
verspreide gedrag dat middleware/site.js zegt te hebben opgeruimd. Dus / gaf de
site en WebFinger gaf 404, uit dezelfde database, in hetzelfde verzoek.

Gevonden op instance loop (🩵.is.wildenvrij.nl): één site, slug "mee",
is_primary 0. De andere instances kunnen in dezelfde staat staan.

De nieuwe test zet alle vlaggen op 0 en eist dat een kale host dan nog steeds
de oudste site vindt.

Co-Authored-By: Claude Opus 5 <claude@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/webfinger-bare-host.test.js

    r26c5f71 r679924e  
    2828// `kid` is the primary site; `oma` is a second public site that must NOT be
    2929// what a bare host resolves to.
    30 db.prepare('INSERT INTO sites (id, slug, title, owner_id, is_primary) VALUES (?,?,?,?,1)').run('s1', 'kid', 'kid', 'u1');
    31 db.prepare('INSERT INTO sites (id, slug, title, owner_id, is_primary) VALUES (?,?,?,?,0)').run('s2', 'oma', 'oma', 'u1');
     30// Explicit created_at: getPrimarySite() falls back to the OLDEST site, and two
     31// rows inserted in the same second would make that order a coin flip.
     32db.prepare('INSERT INTO sites (id, slug, title, owner_id, is_primary, created_at) VALUES (?,?,?,?,1,?)')
     33  .run('s1', 'kid', 'kid', 'u1', '2026-01-01 00:00:00');
     34db.prepare('INSERT INTO sites (id, slug, title, owner_id, is_primary, created_at) VALUES (?,?,?,?,0,?)')
     35  .run('s2', 'oma', 'oma', 'u1', '2026-06-01 00:00:00');
    3236
    3337const app = express();
     
    8690});
    8791
     92test('a bare host resolves even when no site carries the primary flag', async () => {
     93  // This is the state a fresh instance is actually in: is_primary defaults to 0
     94  // and the backfill only runs when the column is first added, so a site created
     95  // afterwards leaves the instance with no primary at all. The HTML side coped
     96  // (getPrimarySite falls back to the oldest) while this route kept its own
     97  // is_primary-only lookup — so / served the site and WebFinger said 404.
     98  db.prepare('UPDATE sites SET is_primary = 0').run();
     99  try {
     100    const { status, body } = await finger('acct:test.example@test.example');
     101    assert.equal(status, 200, 'an unflagged instance is still discoverable');
     102    assert.equal(actorOf(body), 'https://test.example/ap/users/kid', 'falls back to the oldest site');
     103  } finally {
     104    db.prepare('UPDATE sites SET is_primary = 1 WHERE id = ?').run('s1');
     105  }
     106});
     107
    88108test('an unknown user is still a 404', async () => {
    89109  // The fallback must not turn every miss into the primary actor, or a typo
Note: See TracChangeset for help on using the changeset viewer.