mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-05-22 14:52:35 +02:00
fix: linter
This commit is contained in:
parent
0584d949c0
commit
8646f287ff
3 changed files with 28 additions and 4 deletions
|
@ -4,7 +4,7 @@ const { Prometheus } = require("../prometheus");
|
||||||
const { log, UP, DOWN, PENDING, MAINTENANCE, flipStatus, MAX_INTERVAL_SECOND, MIN_INTERVAL_SECOND,
|
const { log, UP, DOWN, PENDING, MAINTENANCE, flipStatus, MAX_INTERVAL_SECOND, MIN_INTERVAL_SECOND,
|
||||||
SQL_DATETIME_FORMAT, evaluateJsonQuery
|
SQL_DATETIME_FORMAT, evaluateJsonQuery
|
||||||
} = require("../../src/util");
|
} = 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
|
redisPingAsync, kafkaProducerAsync, getOidcTokenClientCredentials, rootCertificatesFingerprints, axiosAbortSignal
|
||||||
} = require("../util-server");
|
} = require("../util-server");
|
||||||
const { R } = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
|
@ -24,7 +24,6 @@ const { CookieJar } = require("tough-cookie");
|
||||||
const { HttpsCookieAgent } = require("http-cookie-agent/http");
|
const { HttpsCookieAgent } = require("http-cookie-agent/http");
|
||||||
const https = require("https");
|
const https = require("https");
|
||||||
const http = require("http");
|
const http = require("http");
|
||||||
const tls = require("tls");
|
|
||||||
|
|
||||||
const rootCertificates = rootCertificatesFingerprints();
|
const rootCertificates = rootCertificatesFingerprints();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const { MonitorType } = require("./monitor-type");
|
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 { tcping, checkCertificate } = require("../util-server");
|
||||||
const tls = require("tls");
|
const tls = require("tls");
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,17 @@ const { TCPMonitorType } = require("../../server/monitor-types/tcp");
|
||||||
const { UP, DOWN, PENDING } = require("../../src/util");
|
const { UP, DOWN, PENDING } = require("../../src/util");
|
||||||
const net = require("net");
|
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", () => {
|
describe("TCP Monitor", () => {
|
||||||
|
/**
|
||||||
|
* Creates a TCP server on a specified port
|
||||||
|
* @param {number} port - The port number to listen on
|
||||||
|
* @returns {Promise<net.Server>} A promise that resolves with the created server
|
||||||
|
*/
|
||||||
async function createTCPServer(port) {
|
async function createTCPServer(port) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const server = net.createServer();
|
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 () => {
|
test("TCP server is running", async () => {
|
||||||
const port = 12345;
|
const port = 12345;
|
||||||
const server = await createTCPServer(port);
|
const server = await createTCPServer(port);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const tcpMonitor = new TCPMonitorType();
|
const tcpMonitor = new TCPMonitorType();
|
||||||
|
|
||||||
const monitor = {
|
const monitor = {
|
||||||
hostname: "localhost",
|
hostname: "localhost",
|
||||||
port: port,
|
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 () => {
|
test("TCP server is not running", async () => {
|
||||||
const tcpMonitor = new TCPMonitorType();
|
const tcpMonitor = new TCPMonitorType();
|
||||||
|
|
||||||
const monitor = {
|
const monitor = {
|
||||||
hostname: "localhost",
|
hostname: "localhost",
|
||||||
port: 54321,
|
port: 54321,
|
||||||
|
@ -63,8 +83,13 @@ describe("TCP Monitor", () => {
|
||||||
assert.strictEqual(heartbeat.status, DOWN);
|
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) => {
|
test("TCP server with expired or invalid TLS certificate", async (t) => {
|
||||||
const tcpMonitor = new TCPMonitorType();
|
const tcpMonitor = new TCPMonitorType();
|
||||||
|
|
||||||
const monitor = {
|
const monitor = {
|
||||||
hostname: "expired.badssl.com",
|
hostname: "expired.badssl.com",
|
||||||
port: 443,
|
port: 443,
|
||||||
|
@ -82,6 +107,6 @@ describe("TCP Monitor", () => {
|
||||||
await tcpMonitor.check(monitor, heartbeat, {});
|
await tcpMonitor.check(monitor, heartbeat, {});
|
||||||
|
|
||||||
assert.strictEqual(heartbeat.status, DOWN);
|
assert.strictEqual(heartbeat.status, DOWN);
|
||||||
assert(["Certificate is invalid", "Connection failed"].includes(heartbeat.msg));
|
assert([ "Certificate is invalid", "Connection failed" ].includes(heartbeat.msg));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue