Enforce UP status for non-custom status monitors (#6433)

Co-authored-by: Frank Elsinga <frank@elsinga.de>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Louis Lam
2025-11-28 20:25:06 +08:00
committed by GitHub
co-authored by Frank Elsinga Copilot
parent 70329cc259
commit 6e49601eed
12 changed files with 90 additions and 61 deletions
+8 -3
View File
@@ -2,7 +2,7 @@ const { describe, test } = require("node:test");
const assert = require("node:assert");
const { RabbitMQContainer } = require("@testcontainers/rabbitmq");
const { RabbitMqMonitorType } = require("../../server/monitor-types/rabbitmq");
const { UP, DOWN, PENDING } = require("../../src/util");
const { UP, PENDING } = require("../../src/util");
describe("RabbitMQ Single Node", {
skip: !!process.env.CI && (process.platform !== "linux" || process.arch !== "x64"),
@@ -46,8 +46,13 @@ describe("RabbitMQ Single Node", {
status: PENDING,
};
await rabbitMQMonitor.check(monitor, heartbeat, {});
assert.strictEqual(heartbeat.status, DOWN);
// regex match any string
const regex = /.+/;
await assert.rejects(
rabbitMQMonitor.check(monitor, heartbeat, {}),
regex
);
});
});
+16 -10
View File
@@ -1,7 +1,7 @@
const { describe, test } = require("node:test");
const assert = require("node:assert");
const { TCPMonitorType } = require("../../server/monitor-types/tcp");
const { UP, DOWN, PENDING } = require("../../src/util");
const { UP, PENDING } = require("../../src/util");
const net = require("net");
/**
@@ -77,9 +77,10 @@ describe("TCP Monitor", () => {
status: PENDING,
};
await tcpMonitor.check(monitor, heartbeat, {});
assert.strictEqual(heartbeat.status, DOWN);
await assert.rejects(
tcpMonitor.check(monitor, heartbeat, {}),
new Error("Connection failed")
);
});
/**
@@ -104,10 +105,13 @@ describe("TCP Monitor", () => {
status: PENDING,
};
await tcpMonitor.check(monitor, heartbeat, {});
// Regex: contains with "TLS Connection failed:" or "Certificate is invalid"
const regex = /TLS Connection failed:|Certificate is invalid/;
assert.strictEqual(heartbeat.status, DOWN);
assert([ "Certificate is invalid", "TLS Connection failed:" ].some(prefix => heartbeat.msg.startsWith(prefix)));
await assert.rejects(
tcpMonitor.check(monitor, heartbeat, {}),
regex
);
});
test("TCP server with valid TLS certificate (SSL)", async t => {
@@ -174,9 +178,11 @@ describe("TCP Monitor", () => {
status: PENDING,
};
await tcpMonitor.check(monitor, heartbeat, {});
const regex = /does not match certificate/;
assert.strictEqual(heartbeat.status, DOWN);
assert([ "does not match certificate" ].some(msg => heartbeat.msg.includes(msg)));
await assert.rejects(
tcpMonitor.check(monitor, heartbeat, {}),
regex
);
});
});
+17 -29
View File
@@ -2,7 +2,7 @@ const { WebSocketServer } = require("ws");
const { describe, test } = require("node:test");
const assert = require("node:assert");
const { WebSocketMonitorType } = require("../../server/monitor-types/websocket-upgrade");
const { UP, DOWN, PENDING } = require("../../src/util");
const { UP, PENDING } = require("../../src/util");
describe("Websocket Test", {
}, () => {
@@ -19,13 +19,10 @@ describe("Websocket Test", {
status: PENDING,
};
const expected = {
msg: "Unexpected server response: 200",
status: DOWN,
};
await websocketMonitor.check(monitor, heartbeat, {});
assert.deepStrictEqual(heartbeat, expected);
await assert.rejects(
websocketMonitor.check(monitor, heartbeat, {}),
new Error("Unexpected server response: 200")
);
});
test("Secure Websocket", async () => {
@@ -87,13 +84,10 @@ describe("Websocket Test", {
status: PENDING,
};
const expected = {
msg: "Invalid Sec-WebSocket-Accept header",
status: DOWN,
};
await websocketMonitor.check(monitor, heartbeat, {});
assert.deepStrictEqual(heartbeat, expected);
await assert.rejects(
websocketMonitor.check(monitor, heartbeat, {}),
new Error("Invalid Sec-WebSocket-Accept header")
);
});
test("Non compliant WS server with IgnoreSecWebsocket", async () => {
@@ -153,13 +147,10 @@ describe("Websocket Test", {
status: PENDING,
};
const expected = {
msg: "Unexpected server response: 200",
status: DOWN,
};
await websocketMonitor.check(monitor, heartbeat, {});
assert.deepStrictEqual(heartbeat, expected);
await assert.rejects(
websocketMonitor.check(monitor, heartbeat, {}),
new Error("Unexpected server response: 200")
);
});
test("Secure Websocket with Subprotocol", async () => {
@@ -176,12 +167,9 @@ describe("Websocket Test", {
status: PENDING,
};
const expected = {
msg: "Server sent no subprotocol",
status: DOWN,
};
await websocketMonitor.check(monitor, heartbeat, {});
assert.deepStrictEqual(heartbeat, expected);
await assert.rejects(
websocketMonitor.check(monitor, heartbeat, {}),
new Error("Server sent no subprotocol")
);
});
});