From 8646f287ff175abccffe23b16d4a4f1f59a2f130 Mon Sep 17 00:00:00 2001 From: Jacques ROUSSEL Date: Fri, 28 Mar 2025 17:14:19 +0100 Subject: [PATCH] fix: linter --- server/model/monitor.js | 3 +-- server/monitor-types/tcp.js | 2 +- test/backend-test/test-tcp.js | 27 ++++++++++++++++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 2cfafc3ed..dbb70bbde 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -4,7 +4,7 @@ const { Prometheus } = require("../prometheus"); const { log, UP, DOWN, PENDING, MAINTENANCE, flipStatus, MAX_INTERVAL_SECOND, MIN_INTERVAL_SECOND, SQL_DATETIME_FORMAT, evaluateJsonQuery } = require("../../src/util"); -const { tcping, ping, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mssqlQuery, postgresQuery, mysqlQuery, setSetting, httpNtlm, radius, grpcQuery, +const { ping, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mssqlQuery, postgresQuery, mysqlQuery, setSetting, httpNtlm, radius, grpcQuery, redisPingAsync, kafkaProducerAsync, getOidcTokenClientCredentials, rootCertificatesFingerprints, axiosAbortSignal } = require("../util-server"); const { R } = require("redbean-node"); @@ -24,7 +24,6 @@ const { CookieJar } = require("tough-cookie"); const { HttpsCookieAgent } = require("http-cookie-agent/http"); const https = require("https"); const http = require("http"); -const tls = require("tls"); const rootCertificates = rootCertificatesFingerprints(); diff --git a/server/monitor-types/tcp.js b/server/monitor-types/tcp.js index 815be4db2..b822e05d1 100644 --- a/server/monitor-types/tcp.js +++ b/server/monitor-types/tcp.js @@ -1,5 +1,5 @@ const { MonitorType } = require("./monitor-type"); -const { UP, DOWN, log, evaluateJsonQuery } = require("../../src/util"); +const { UP, DOWN } = require("../../src/util"); const { tcping, checkCertificate } = require("../util-server"); const tls = require("tls"); diff --git a/test/backend-test/test-tcp.js b/test/backend-test/test-tcp.js index fd5d7dae9..c7c3bd4ef 100644 --- a/test/backend-test/test-tcp.js +++ b/test/backend-test/test-tcp.js @@ -4,7 +4,17 @@ const { TCPMonitorType } = require("../../server/monitor-types/tcp"); const { UP, DOWN, PENDING } = require("../../src/util"); const net = require("net"); +/** + * Test suite for TCP Monitor functionality + * This test suite checks the behavior of the TCPMonitorType class + * under different network connection scenarios. + */ describe("TCP Monitor", () => { + /** + * Creates a TCP server on a specified port + * @param {number} port - The port number to listen on + * @returns {Promise} A promise that resolves with the created server + */ async function createTCPServer(port) { return new Promise((resolve, reject) => { const server = net.createServer(); @@ -19,12 +29,17 @@ describe("TCP Monitor", () => { }); } + /** + * Test case to verify TCP monitor works when a server is running + * Checks that the monitor correctly identifies an active TCP server + */ test("TCP server is running", async () => { const port = 12345; const server = await createTCPServer(port); try { const tcpMonitor = new TCPMonitorType(); + const monitor = { hostname: "localhost", port: port, @@ -45,8 +60,13 @@ describe("TCP Monitor", () => { } }); + /** + * Test case to verify TCP monitor handles non-running servers + * Checks that the monitor correctly identifies an inactive TCP server + */ test("TCP server is not running", async () => { const tcpMonitor = new TCPMonitorType(); + const monitor = { hostname: "localhost", port: 54321, @@ -63,8 +83,13 @@ describe("TCP Monitor", () => { assert.strictEqual(heartbeat.status, DOWN); }); + /** + * Test case to verify TCP monitor handles servers with expired or invalid TLS certificates + * Checks that the monitor correctly identifies TLS certificate issues + */ test("TCP server with expired or invalid TLS certificate", async (t) => { const tcpMonitor = new TCPMonitorType(); + const monitor = { hostname: "expired.badssl.com", port: 443, @@ -82,6 +107,6 @@ describe("TCP Monitor", () => { await tcpMonitor.check(monitor, heartbeat, {}); assert.strictEqual(heartbeat.status, DOWN); - assert(["Certificate is invalid", "Connection failed"].includes(heartbeat.msg)); + assert([ "Certificate is invalid", "Connection failed" ].includes(heartbeat.msg)); }); });