| 1 | // FEP-633c §5.3 note: a committed guardian is recognised for authorized fetch.
|
|---|
| 2 | import { test } from 'node:test';
|
|---|
| 3 | import assert from 'node:assert/strict';
|
|---|
| 4 |
|
|---|
| 5 | process.env.DATABASE_PATH = ':memory:';
|
|---|
| 6 | process.env.PUBLIC_BASE_URL = 'https://test.example';
|
|---|
| 7 |
|
|---|
| 8 | const dbMod = await import('../src/config/database.js');
|
|---|
| 9 | const db = dbMod.default;
|
|---|
| 10 | dbMod.initializeDatabase();
|
|---|
| 11 | const AP = (await import('../src/services/ActivityPubService.js')).default;
|
|---|
| 12 |
|
|---|
| 13 | db.prepare('INSERT INTO users (id, username, email, password_hash, role) VALUES (?,?,?,?,?)').run('u1', 'u1', 'u1@t', 'x', 'god');
|
|---|
| 14 | db.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.
|
|---|
| 16 | const MOM = 'https://mom.example/ap/users/mom';
|
|---|
| 17 | db.prepare("INSERT INTO ap_guardianships (slug, role, other_uri, status, created_at) VALUES ('kid','ward',?, 'accepted', CURRENT_TIMESTAMP)").run(MOM);
|
|---|
| 18 |
|
|---|
| 19 | test('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 | });
|
|---|