source: Klonkt/test/authorized-fetch.test.js@ 1a2f206

main
Last change on this file since 1a2f206 was c66cbb4, checked in by Robin <roboburr@…>, 7 weeks ago

Authorized fetch: gecommitte guardian leest ward-outbox gesigneerd (FEP-633c §5.3 noot)

De optionele verfijning uit de spec: een guardian die de outbox van z'n ward met
een HTTP-signature opvraagt, krijgt ook de fan_only (prive) posts mee, zonder als
follower te verschijnen en inclusief historie van voor een eventuele follow.
Ongesigneerde of niet-guardian callers krijgen zoals altijd alleen de publieke
collectie. De verbrede view gaat met Cache-Control private,no-store zodat een
gedeelde cache 'm nooit aan het publiek serveert.

De publieke shaer:guardians-lijst maakt dit mogelijk: de ward-server herkent de
signer als huidige guardian (getRelation) zonder extra coordinatie.

Changed files:
src/routes/activitypub.js

  • outbox GET: signed-fetch check; guardian ziet fan_only; no-store op de verbrede view

src/services/ActivityPubService.js

  • isWardGuardian(wardSlug, actorUri); sendAP krijgt optionele cache-control

test/authorized-fetch.test.js

  • guardian herkend, vreemde niet

remarks: npm test 168/168. verifyRequest deed GET al aan (request-target/host/date,
digest alleen bij body). v1 en niet-guardian-verkeer ongewijzigd.

-robo
Co-Authored-By: Claude Opus 4.8 <noreply@…>

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[c66cbb4]1// FEP-633c §5.3 note: a committed guardian is recognised for authorized fetch.
2import { test } from 'node:test';
3import assert from 'node:assert/strict';
4
5process.env.DATABASE_PATH = ':memory:';
6process.env.PUBLIC_BASE_URL = 'https://test.example';
7
8const dbMod = await import('../src/config/database.js');
9const db = dbMod.default;
10dbMod.initializeDatabase();
11const AP = (await import('../src/services/ActivityPubService.js')).default;
12
13db.prepare('INSERT INTO users (id, username, email, password_hash, role) VALUES (?,?,?,?,?)').run('u1', 'u1', 'u1@t', 'x', 'god');
14db.prepare('INSERT INTO sites (id, slug, title, owner_id, is_primary) VALUES (?,?,?,?,1)').run('s1', 'kid', 'kid', 'u1');
15// Commit a guardian relation: kid (ward) is guarded by mom.
16const MOM = 'https://mom.example/ap/users/mom';
17db.prepare("INSERT INTO ap_guardianships (slug, role, other_uri, status, created_at) VALUES ('kid','ward',?, 'accepted', CURRENT_TIMESTAMP)").run(MOM);
18
19test('a committed guardian is recognised; a stranger is not', () => {
20 assert.equal(AP.isWardGuardian('kid', MOM), true);
21 assert.equal(AP.isWardGuardian('kid', 'https://x.example/ap/users/stranger'), false);
22 assert.equal(AP.isWardGuardian('nosuch', MOM), false);
23});
Note: See TracBrowser for help on using the repository browser.