chore: remove old SNMP tests after consolidation
This commit is contained in:
parent
5a4017f5ed
commit
0adda0bc3e
@ -1,78 +0,0 @@
|
||||
const { describe, test } = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
const snmp = require("net-snmp");
|
||||
const { SNMPMonitorType } = require("../../server/monitor-types/snmp");
|
||||
|
||||
/**
|
||||
* SNMPv3 unit test
|
||||
*
|
||||
* This test intentionally focuses only on verifying SNMPv3 session setup
|
||||
* (noAuthNoPriv → createV3Session with correct options).
|
||||
*
|
||||
* SNMPv3 integration tests require engineID discovery and persistent USM
|
||||
* state, which makes them timing- and environment-sensitive in CI.
|
||||
* To keep CI stable, end-to-end integration coverage is provided via SNMPv2c,
|
||||
* while SNMPv3 behavior is validated here at the decision-path level.
|
||||
*/
|
||||
|
||||
describe("SNMPv3 unit test", () => {
|
||||
test("SNMPv3 noAuthNoPriv uses createV3Session", async () => {
|
||||
const originalCreateV3Session = snmp.createV3Session;
|
||||
const originalCreateSession = snmp.createSession;
|
||||
|
||||
let createV3Called = false;
|
||||
let createSessionCalled = false;
|
||||
let receivedOptions = null;
|
||||
|
||||
// Stub createV3Session
|
||||
snmp.createV3Session = function (_host, _username, options) {
|
||||
createV3Called = true;
|
||||
receivedOptions = options;
|
||||
|
||||
return {
|
||||
on: () => {},
|
||||
close: () => {},
|
||||
// Stop execution after session creation to avoid real network I/O.
|
||||
// This keeps the test deterministic and non-brittle.
|
||||
get: (_oids, cb) => cb(new Error("stop test here"))
|
||||
};
|
||||
};
|
||||
|
||||
// Stub createSession (should NOT be used)
|
||||
snmp.createSession = function () {
|
||||
createSessionCalled = true;
|
||||
return {};
|
||||
};
|
||||
|
||||
const monitor = {
|
||||
type: "snmp",
|
||||
hostname: "127.0.0.1",
|
||||
port: 161,
|
||||
timeout: 5,
|
||||
maxretries: 1,
|
||||
snmpVersion: "3",
|
||||
snmp_v3_username: "testuser",
|
||||
snmpOid: "1.3.6.1.2.1.1.1.0",
|
||||
};
|
||||
|
||||
const snmpMonitor = new SNMPMonitorType();
|
||||
const heartbeat = {};
|
||||
|
||||
await assert.rejects(
|
||||
() => snmpMonitor.check(monitor, heartbeat),
|
||||
/stop test here/
|
||||
);
|
||||
|
||||
// Assertions
|
||||
assert.strictEqual(createV3Called, true);
|
||||
assert.strictEqual(createSessionCalled, false);
|
||||
assert.strictEqual(
|
||||
receivedOptions.securityLevel,
|
||||
snmp.SecurityLevel.noAuthNoPriv
|
||||
);
|
||||
|
||||
// Restore originals
|
||||
snmp.createV3Session = originalCreateV3Session;
|
||||
snmp.createSession = originalCreateSession;
|
||||
});
|
||||
});
|
||||
@ -1,70 +0,0 @@
|
||||
const { describe, test } = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
const { GenericContainer } = require("testcontainers");
|
||||
const { SNMPMonitorType } = require("../../server/monitor-types/snmp");
|
||||
const { UP } = require("../../src/util");
|
||||
|
||||
/**
|
||||
* SNMPv2c integration test
|
||||
*
|
||||
* This test provides CI-safe, end-to-end coverage of the SNMP monitor pipeline:
|
||||
* containerized SNMP agent → net-snmp client → OID query → heartbeat update.
|
||||
*
|
||||
* While SNMPv3 (noAuthNoPriv) uses a different session setup, it shares the same
|
||||
* execution path after session creation (request handling, varbind parsing,
|
||||
* JSON evaluation, and heartbeat updates). Verifying this flow with SNMPv2c
|
||||
* ensures the core SNMP logic works reliably in CI, while SNMPv3-specific
|
||||
* behavior is covered separately by unit tests.
|
||||
*
|
||||
* The test is skipped on Windows due to Docker/Testcontainers UDP port
|
||||
* limitations, not due to SNMP protocol support.
|
||||
*/
|
||||
|
||||
describe("SNMPv2c integration test", () => {
|
||||
test(
|
||||
"SNMPv2c agent responds and heartbeat is UP",
|
||||
{
|
||||
// Reason for why it is Skipped
|
||||
skip: process.platform === "win32" ? "SNMP UDP binding is restricted on native Windows runners" : false,
|
||||
},
|
||||
async () => {
|
||||
// Expose 161/udp. Testcontainers will map it to a random free high-port on the host.
|
||||
const container = await new GenericContainer("polinux/snmpd")
|
||||
.withExposedPorts("161/udp")
|
||||
.start();
|
||||
|
||||
try {
|
||||
// Dynamically retrieve the assigned host port and IP
|
||||
const hostPort = container.getMappedPort(161);
|
||||
const hostIp = container.getHost();
|
||||
|
||||
// UDP service small wait to ensure snmpd is ready inside container
|
||||
await new Promise(r => setTimeout(r, 1500));
|
||||
|
||||
const monitor = {
|
||||
type: "snmp",
|
||||
hostname: hostIp,
|
||||
port: hostPort,
|
||||
snmpVersion: "2c",
|
||||
radiusPassword: "public",
|
||||
snmpOid: "1.3.6.1.2.1.1.1.0",
|
||||
timeout: 5,
|
||||
maxretries: 1,
|
||||
jsonPath: "$",
|
||||
jsonPathOperator: "exists",
|
||||
expectedValue: null,
|
||||
};
|
||||
|
||||
const snmpMonitor = new SNMPMonitorType();
|
||||
const heartbeat = {};
|
||||
|
||||
await snmpMonitor.check(monitor, heartbeat);
|
||||
|
||||
assert.strictEqual(heartbeat.status, UP);
|
||||
} finally {
|
||||
|
||||
await container.stop();
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user