Add device diagnostics and P2P access controls

This commit is contained in:
Jonathan Sykes
2026-10-14 02:45:33 +08:00
parent e9a597c415
commit 5177a4d441
11 changed files with 147 additions and 8 deletions

View File

@@ -40,6 +40,22 @@ test('content upsert/get/known/revoke', async () => {
expect([...(await P.knownCids([CID2]))]).toEqual([]);
});
test('admin device inventory, ban state, and holding revocation', async () => {
const id = 'dev_00000000000000b1';
await P.createDevice({ deviceId: id, secretHash: 'hash', fingerprint: 'phone-fp', profile: 'family', userAgent: 'iPhone', now: T0 });
const adminCid = 'c'.repeat(64);
await P.upsertContent({ cid: adminCid, videoId: 'dQw4w9WgXcQ', size: 4096, origin: 'server', now: T0 });
await P.upsertHolder({ cid: adminCid, deviceId: id, now: T0 });
let [device] = await P.listAdminDevices();
expect(device).toMatchObject({ device_id: id, user_agent: 'iPhone', holdings: 1, holding_bytes: 4096 });
expect(await P.setDeviceBanned(id, true, T0 + 100)).toBe(true);
[device] = await P.listAdminDevices(); expect(device.banned_at).toBe(T0 + 100);
expect(await P.removeDeviceHolders(id, T0 + 200)).toBe(1);
[device] = await P.listAdminDevices(); expect(device.holdings).toBe(0);
expect(await P.setDeviceBanned(id, false, T0 + 300)).toBe(true);
[device] = await P.listAdminDevices(); expect(device.banned_at).toBeNull();
});
test('holders persist, never expire, and a full report removes missing ones', async () => {
await P.createDevice({ deviceId: 'dev_1', secretHash: 'h', fingerprint: 'fp', now: T0 });
await P.upsertHolder({ cid: CID, deviceId: 'dev_1', now: T0 });
@@ -66,8 +82,8 @@ test('views per day and window sums', async () => {
expect(await P.viewsSince('vid00000001', T0 - 30 * 86400_000)).toBe(2);
expect(await P.viewsSince('vid00000001', T0 - 50 * 86400_000)).toBe(3);
const s = await P.p2pStats();
expect(s.content).toBe(1);
expect(s.devices).toBe(1);
expect(s.content).toBe(2);
expect(s.devices).toBe(2);
});
test('listSharedContent: newest verified file per video, only with sharing holders counted', async () => {