Changeset 679924e in Klonkt
- Timestamp:
- 08/02/2026 08:06:21 AM (5 weeks ago)
- Branches:
- main
- Children:
- af035e6
- Parents:
- 26c5f71
- Files:
-
- 2 edited
-
src/routes/activitypub.js (modified) (2 diffs)
-
test/webfinger-bare-host.test.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/routes/activitypub.js
r26c5f71 r679924e 20 20 import OAuth from '../services/OAuthService.js'; 21 21 import * as Guardianship from '../services/guardianship/index.js'; 22 import { getPrimarySite } from '../middleware/site.js'; 22 23 import multer from 'multer'; 23 24 import path from 'path'; … … 43 44 const hostOf = (req) => { try { return new URL(baseUrl(req)).host; } catch { return req.get('host'); } }; 44 45 const publicSite = (slug) => db.prepare('SELECT * FROM sites WHERE slug = ? AND (is_public IS NULL OR is_public = 1)').get(slug); 45 const primarySlug = () => { const r = db.prepare('SELECT slug FROM sites WHERE is_primary = 1').get(); return r && r.slug; }; 46 // The primary site, via the one source of truth in middleware/site.js — which 47 // falls back to the oldest site when nothing carries the is_primary flag. This 48 // route used to keep its own is_primary-only copy, so a fresh instance whose 49 // site was never flagged served its HTML at / (that resolver falls back) while 50 // WebFinger and the actor route insisted it had no primary at all. 51 const primarySlug = () => { const s = getPrimarySite(); return s && s.slug; }; 46 52 // A hostname as a human types it and as DNS stores it are the same host: 47 53 // `🩵.is.wildenvrij.nl` IS `xn--zz9h.is.wildenvrij.nl`. WHATWG URL does the IDNA, -
test/webfinger-bare-host.test.js
r26c5f71 r679924e 28 28 // `kid` is the primary site; `oma` is a second public site that must NOT be 29 29 // 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. 32 db.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'); 34 db.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'); 32 36 33 37 const app = express(); … … 86 90 }); 87 91 92 test('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 88 108 test('an unknown user is still a 404', async () => { 89 109 // The fallback must not turn every miss into the primary actor, or a typo
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)