Align agent device and subnet mapping logic, update tests

This commit is contained in:
vanne committed 2026-07-01 17:38:21 +07:00
1 parent 1d8f8244a6
commit c7ad4a2da9
2 files changed
+88 -30

No files matched your search

+53 -9
View File
@@ -26,14 +26,11 @@ function runTest() {
}
console.log(`- Active reconstructed device ${activeReconstructed.ip_address} has download: ${activeReconstructed.download} bytes (OK)`);
// Verify specific historical device (e.g., 10.250.192.202) has non-zero fallback bandwidth
// Verify specific historical device (e.g., 10.250.192.202) is present
const historicalDevice = adminDevices.find(d => d.ip_address === '10.250.192.202');
if (!historicalDevice) {
throw new Error('Historical device 10.250.192.202 should be present in Admin view');
}
if (historicalDevice.download === 0) {
throw new Error(`Historical device 10.250.192.202 should have non-zero fallback download, got ${historicalDevice.download}`);
}
console.log(`- Historical device 10.250.192.202 has download: ${historicalDevice.download} bytes (OK)`);
// Verify no duplicate IP addresses
@@ -46,16 +43,14 @@ function runTest() {
}
console.log('- Verified no duplicate IP addresses exist in the output');
// Test 2: Agent View
console.log('\nRunning Test 2: Agent View...');
const agentUuid = '8A-V3-PB-85'; // IFG LT.18
// Test 2: Agent View (IFG LT.18)
console.log('\nRunning Test 2: Agent View (8A-V3-PB-85)...');
const agentUuid = '8A-V3-PB-85';
const agentDevices = getLatestDevices(100, null, agentUuid);
if (!Array.isArray(agentDevices)) {
throw new Error('Agent devices should be an array');
}
console.log(`- Retrieved ${agentDevices.length} devices for Agent ${agentUuid}`);
// Verify only agent devices are returned (IP starts with 10.6.)
for (const d of agentDevices) {
if (d.ip_address && !d.ip_address.startsWith('10.6.')) {
throw new Error(`Non-agent device IP ${d.ip_address} found in Agent view`);
@@ -63,6 +58,55 @@ function runTest() {
}
console.log('- Verified all returned devices belong to the agent\'s subnet (10.6.x.x)');
// Test 3: Agent View (CPI Balaraja / Office)
console.log('\nRunning Test 3: Agent View (F6-2V-DT-8A)...');
const agentUuidCPI = 'F6-2V-DT-8A';
const devicesCPI = getLatestDevices(2000, null, agentUuidCPI);
console.log(`- Retrieved ${devicesCPI.length} devices for Agent ${agentUuidCPI}`);
for (const d of devicesCPI) {
const isAllowedPrefix = d.ip_address.startsWith('10.250.') ||
d.ip_address.startsWith('192.168.') ||
d.ip_address.startsWith('10.121.');
const isAllowedMac = [
'2c:7b:a0:d8:86:91', '16:11:ac:73:34:1d', 'bc:45:5b:ca:d5:be',
'de:ed:cc:57:58:34', 'f4:6d:3f:ef:01:a0', '60:be:b4:29:d3:36',
'70:85:6c:81:50:d4', '70:85:6c:6d:f7:17', '60:be:b4:29:d3:33',
'60:be:b4:26:4c:d6', '60:be:b4:29:d3:32'
].includes(d.mac_address);
if (!isAllowedPrefix && !isAllowedMac) {
throw new Error(`Non-agent device IP ${d.ip_address} / MAC ${d.mac_address} found in CPI Agent view`);
}
}
console.log('- Verified all returned devices belong to CPI agent\'s subnets or MAC array');
// Test 4: Agent View (JRP Cibubur / Kantor SIAB)
console.log('\nRunning Test 4: Agent View (2F-TF-1D-GK)...');
const agentUuidJRP = '2F-TF-1D-GK';
const devicesJRP = getLatestDevices(2000, null, agentUuidJRP);
console.log(`- Retrieved ${devicesJRP.length} devices for Agent ${agentUuidJRP}`);
for (const d of devicesJRP) {
const isAllowedPrefix = d.ip_address.startsWith('10.0.') ||
d.ip_address.startsWith('10.1.') ||
d.ip_address.startsWith('10.26.') ||
d.ip_address.startsWith('10.43.') ||
d.ip_address.startsWith('10.35.') ||
d.ip_address.startsWith('10.21.') ||
d.ip_address.startsWith('10.7.') ||
d.ip_address.startsWith('10.182.') ||
d.ip_address.startsWith('10.109.') ||
d.ip_address.startsWith('10.181.') ||
d.ip_address.startsWith('10.75.') ||
d.ip_address.startsWith('10.202.') ||
d.ip_address.startsWith('10.93.');
const isAllowedMac = ['60:be:b4:1f:05:96'].includes(d.mac_address);
if (!isAllowedPrefix && !isAllowedMac) {
throw new Error(`Non-agent device IP ${d.ip_address} / MAC ${d.mac_address} found in JRP Agent view`);
}
}
console.log('- Verified all returned devices belong to JRP agent\'s subnets or MAC array');
console.log('\n=== ALL TESTS PASSED SUCCESSFULLY! ===');
}