| 1 | // Friends get the history (Robins besluit, 30-7). A friends-only post used to
|
|---|
| 2 | // be a moment-snapshot: delivered to the followers of that instant, hidden
|
|---|
| 3 | // from the outbox, so a friend added LATER could never see it in a feed. Now
|
|---|
| 4 | // the outbox answers by audience, and the backfill a fresh follow triggers
|
|---|
| 5 | // identifies itself, so the past comes along with the friendship.
|
|---|
| 6 | //
|
|---|
| 7 | // And the door stays a door: a verified caller this instance BLOCKS gets an
|
|---|
| 8 | // EMPTY collection, not even the public set.
|
|---|
| 9 | import { test } from 'node:test';
|
|---|
| 10 | import assert from 'node:assert/strict';
|
|---|
| 11 |
|
|---|
| 12 | process.env.DATABASE_PATH = ':memory:';
|
|---|
| 13 | process.env.PUBLIC_BASE_URL = 'https://test.example';
|
|---|
| 14 |
|
|---|
| 15 | const dbMod = await import('../src/config/database.js');
|
|---|
| 16 | const db = dbMod.default;
|
|---|
| 17 | dbMod.initializeDatabase();
|
|---|
| 18 | const AP = (await import('../src/services/ActivityPubService.js')).default;
|
|---|
| 19 |
|
|---|
| 20 | db.prepare('INSERT INTO users (id, username, email, password_hash, role) VALUES (?,?,?,?,?)')
|
|---|
| 21 | .run('u1', 'kid', 'u1@t', 'x', 'god');
|
|---|
| 22 | db.prepare('INSERT INTO sites (id, slug, title, owner_id, is_primary) VALUES (?,?,?,?,1)').run('s1', 'kid', 'kid', 'u1');
|
|---|
| 23 |
|
|---|
| 24 | const FRIEND = 'https://vriend.test/u/f';
|
|---|
| 25 | const STRANGER = 'https://vreemde.test/u/x';
|
|---|
| 26 | const BLOCKED = 'https://pest.test/u/b';
|
|---|
| 27 | db.prepare("INSERT INTO ap_followers (slug, actor_uri) VALUES ('kid', ?)").run(FRIEND);
|
|---|
| 28 | db.prepare("INSERT INTO ap_blocks (slug, kind, target) VALUES ('kid', 'actor', ?)").run(BLOCKED);
|
|---|
| 29 |
|
|---|
| 30 | test('the audience decides what the outbox holds', () => {
|
|---|
| 31 | assert.equal(AP.outboxAudience('kid', {}), 'public', 'anonymous stays public');
|
|---|
| 32 | assert.equal(AP.outboxAudience('kid', { verifiedActor: STRANGER }), 'public',
|
|---|
| 33 | 'a signature alone earns nothing: identification is not friendship');
|
|---|
| 34 | assert.equal(AP.outboxAudience('kid', { verifiedActor: FRIEND }), 'friend',
|
|---|
| 35 | 'an accepted follower reads the friends-only history');
|
|---|
| 36 | assert.equal(AP.outboxAudience('kid', { bearerSlug: 'kid' }), 'friend',
|
|---|
| 37 | 'the owner sees their own friends-only posts in their own app');
|
|---|
| 38 | assert.equal(AP.outboxAudience('kid', { bearerSlug: 'someone-else' }), 'public',
|
|---|
| 39 | "another local account's bearer is not this account");
|
|---|
| 40 | });
|
|---|
| 41 |
|
|---|
| 42 | test('a blocked actor who signs their fetch gets an empty set, not the public one', () => {
|
|---|
| 43 | assert.equal(AP.outboxAudience('kid', { verifiedActor: BLOCKED }), 'blocked',
|
|---|
| 44 | 'the block outranks everything: a closed door, and they knocked with their name on it');
|
|---|
| 45 | });
|
|---|
| 46 |
|
|---|
| 47 | test('a blocked FOLLOWER is still blocked: the block outranks the follow', () => {
|
|---|
| 48 | // The row order of checks matters: someone blocked after having followed
|
|---|
| 49 | // must not keep reading through the stale follower row.
|
|---|
| 50 | db.prepare("INSERT INTO ap_followers (slug, actor_uri) VALUES ('kid', ?)").run(BLOCKED);
|
|---|
| 51 | assert.equal(AP.outboxAudience('kid', { verifiedActor: BLOCKED }), 'blocked');
|
|---|
| 52 | });
|
|---|