Show device identity details and resolve hostnames
Build and Deploy Gateway / build-and-push (push) Successful in 19s
Build and Deploy Gateway / deploy (push) Successful in 13s

This commit is contained in:
2026-08-11 12:39:27 +03:00
parent 501c498edf
commit 3566f4bc0b
10 changed files with 256 additions and 82 deletions
+37
View File
@@ -116,6 +116,43 @@ test('malformed persisted devices and remote observations cannot enter canonical
]);
});
test('device inventory resolves hostnames without making reverse lookup a refresh dependency', async (t) => {
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'harbor-device-hostname-'));
t.after(() => fs.rmSync(directory, { recursive: true, force: true }));
const store = createJsonStore({ filePath: path.join(directory, 'devices.json'), defaultValue: {} });
const observedAt = '2026-08-11T12:00:00.000Z';
const mac = '00:11:22:33:44:55';
let ip = '192.168.50.10';
let lookupFails = false;
const lookups = [];
const service = createDeviceInventoryService({
store,
observe: () => ({
observedAt,
error: null,
observations: [{ ip, mac, interface: 'br0', observedAt, active: true }],
}),
resolveHostname: async (address) => {
lookups.push(address);
if (lookupFails) throw new Error('reverse DNS unavailable');
return 'living-room.local.';
},
now: () => new Date(observedAt),
});
let snapshot = await service.refresh();
assert.equal(snapshot.devices[0].hostname, 'living-room.local');
snapshot = await service.refresh();
assert.deepEqual(lookups, ['192.168.50.10']);
ip = '192.168.50.11';
lookupFails = true;
snapshot = await service.refresh();
assert.equal(snapshot.devices[0].ip, ip);
assert.equal(snapshot.devices[0].hostname, 'living-room.local');
assert.deepEqual(lookups, ['192.168.50.10', '192.168.50.11']);
});
test('device inventory discovers, merges, persists metadata and expires devices after 30 days', async (t) => {
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'harbor-devices-'));
t.after(() => fs.rmSync(directory, { recursive: true, force: true }));