Add device diagnostics and P2P access controls
This commit is contained in:
@@ -51,6 +51,21 @@ test('auth on open, hello with opaque peer id, bad secret is closed', async () =
|
||||
expect(hub.isOnline('dev_000000000000000b')).toBe(false);
|
||||
});
|
||||
|
||||
test('banned devices cannot authenticate and admin disconnect closes an online peer', async () => {
|
||||
await p2pDb.setDeviceBanned('dev_000000000000000a', true, NOW);
|
||||
const hub = createP2pHub({ getDevice: p2pDb.getDevice });
|
||||
const banned = fakeWs({ budget: [] });
|
||||
await hub.websocket.message(banned, JSON.stringify({ type: 'auth', device: 'dev_000000000000000a', secret: SECRET_A }));
|
||||
expect(banned.closed).toBe(4403);
|
||||
await p2pDb.setDeviceBanned('dev_000000000000000a', false, NOW + 1);
|
||||
const online = fakeWs({ budget: [] });
|
||||
await hub.websocket.message(online, JSON.stringify({ type: 'auth', device: 'dev_000000000000000a', secret: SECRET_A }));
|
||||
expect(hub.disconnect('dev_000000000000000a')).toBe(true);
|
||||
expect(online.closed).toBe(4403);
|
||||
hub.websocket.close(online);
|
||||
expect(hub.isOnline('dev_000000000000000a')).toBe(false);
|
||||
});
|
||||
|
||||
test('legacy unconfirmed signalling is refused; close drops presence', async () => {
|
||||
const hub = createP2pHub({ getDevice: p2pDb.getDevice });
|
||||
const a = fakeWs({ budget: [] });
|
||||
|
||||
Reference in New Issue
Block a user