Merge branch 'master' into copilot/fix-migration-error-on-text-column

This commit is contained in:
copilot-swe-agent[bot] 2026-01-06 20:27:50 +00:00
commit d4d5216666
3 changed files with 102 additions and 44 deletions

View File

@ -86,19 +86,18 @@ async function getRdapDomainExpiryDate(domain) {
*/ */
async function sendDomainNotificationByTargetDays(domain, daysRemaining, targetDays, notificationList) { async function sendDomainNotificationByTargetDays(domain, daysRemaining, targetDays, notificationList) {
let sent = false; let sent = false;
log.debug("domain", `Send domain expiry notification for ${targetDays} deadline.`); log.debug("domain_expiry", `Send domain expiry notification for ${targetDays} deadline.`);
for (let notification of notificationList) { for (let notification of notificationList) {
try { try {
log.debug("domain", `Sending to ${notification.name}`); log.debug("domain_expiry", `Sending to ${notification.name}`);
await Notification.send( await Notification.send(
JSON.parse(notification.config), JSON.parse(notification.config),
`Domain name ${domain} will expire in ${daysRemaining} days` `Domain name ${domain} will expire in ${daysRemaining} days`
); );
sent = true; sent = true;
} catch (e) { } catch (e) {
log.error("domain", `Cannot send domain notification to ${notification.name}`); log.error("domain_expiry", `Cannot send domain notification to ${notification.name}:`, e);
log.error("domain", e);
} }
} }
@ -152,7 +151,7 @@ class DomainExpiry extends BeanModel {
const tld = parseTld(urlTypes.includes(m.type) ? m.url : m.type === "grpc-keyword" ? m.grpcUrl : m.hostname); const tld = parseTld(urlTypes.includes(m.type) ? m.url : m.type === "grpc-keyword" ? m.grpcUrl : m.hostname);
const rdap = await getRdapServer(tld.publicSuffix); const rdap = await getRdapServer(tld.publicSuffix);
if (!rdap) { if (!rdap) {
log.warn("domain", `Domain expiry unsupported for '.${tld.publicSuffix}' because its RDAP endpoint is not listed in the IANA database.`); log.warn("domain_expiry", `Domain expiry unsupported for '.${tld.publicSuffix}' because its RDAP endpoint is not listed in the IANA database.`);
return false; return false;
} }
const existing = await DomainExpiry.findByName(tld.domain); const existing = await DomainExpiry.findByName(tld.domain);
@ -188,7 +187,7 @@ class DomainExpiry extends BeanModel {
let expiryDate; let expiryDate;
if (bean?.lastCheck && getDaysBetween(new Date(bean.lastCheck), new Date()) < 1) { if (bean?.lastCheck && getDaysBetween(new Date(bean.lastCheck), new Date()) < 1) {
log.debug("domain", `Domain expiry already checked recently for ${bean.domain}, won't re-check.`); log.debug("domain_expiry", `Domain expiry already checked recently for ${bean.domain}, won't re-check.`);
return bean.expiry; return bean.expiry;
} else if (bean) { } else if (bean) {
expiryDate = await bean.getExpiryDate(); expiryDate = await bean.getExpiryDate();
@ -220,13 +219,13 @@ class DomainExpiry extends BeanModel {
if (!notificationList.length > 0) { if (!notificationList.length > 0) {
// fail fast. If no notification is set, all the following checks can be skipped. // fail fast. If no notification is set, all the following checks can be skipped.
log.debug("domain", "No notification, no need to send domain notification"); log.debug("domain_expiry", "No notification, no need to send domain notification");
return; return;
} }
const daysRemaining = getDaysRemaining(new Date(), domain.expiry); const daysRemaining = getDaysRemaining(new Date(), domain.expiry);
const lastSent = domain.lastExpiryNotificationSent; const lastSent = domain.lastExpiryNotificationSent;
log.debug("domain", `${name} expires in ${daysRemaining} days`); log.debug("domain_expiry", `${name} expires in ${daysRemaining} days`);
let notifyDays = await setting("domainExpiryNotifyDays"); let notifyDays = await setting("domainExpiryNotifyDays");
if (notifyDays == null || !Array.isArray(notifyDays)) { if (notifyDays == null || !Array.isArray(notifyDays)) {

View File

@ -53,7 +53,7 @@ class WebSocketMonitorType extends MonitorType {
/** /**
* Uses the ws Node.js library to establish a connection to target server * Uses the ws Node.js library to establish a connection to target server
* @param {object} monitor The monitor object for input parameters. * @param {object} monitor The monitor object for input parameters.
* @returns {[ string, int ]} Array containing a status message and response code * @returns {Promise<[ string, int ]>} Array containing a status message and response code
*/ */
async attemptUpgrade(monitor) { async attemptUpgrade(monitor) {
return new Promise((resolve) => { return new Promise((resolve) => {

View File

@ -4,13 +4,13 @@ const assert = require("node:assert");
const { WebSocketMonitorType } = require("../../../server/monitor-types/websocket-upgrade"); const { WebSocketMonitorType } = require("../../../server/monitor-types/websocket-upgrade");
const { UP, PENDING } = require("../../../src/util"); const { UP, PENDING } = require("../../../src/util");
const net = require("node:net"); const net = require("node:net");
const http = require("node:http");
/** /**
* Simulates non compliant WS Server, doesnt send Sec-WebSocket-Accept header * Simulates non compliant WS Server, doesnt send Sec-WebSocket-Accept header
* @param {number} port Port the server listens on. Defaults to 8080 * @returns {Promise<{server: net.Server, port: number}>} Promise that resolves to the created server and its port
* @returns {Promise} Promise that resolves to the created server once listening
*/ */
function nonCompliantWS(port = 8080) { function nonCompliantWS() {
const srv = net.createServer((socket) => { const srv = net.createServer((socket) => {
socket.once("data", (buf) => { socket.once("data", (buf) => {
socket.write("HTTP/1.1 101 Switching Protocols\r\n" + socket.write("HTTP/1.1 101 Switching Protocols\r\n" +
@ -19,16 +19,56 @@ function nonCompliantWS(port = 8080) {
socket.destroy(); socket.destroy();
}); });
}); });
return new Promise((resolve) => srv.listen(port, () => resolve(srv))); return new Promise((resolve) => {
srv.listen(0, () => {
resolve({ server: srv,
port: srv.address().port });
});
});
}
/**
* Creates a regular HTTP server (non-WebSocket) for testing WebSocket rejection
* @returns {Promise<{server: http.Server, port: number}>} Promise that resolves to the created server and its port
*/
function httpServer() {
const srv = http.createServer((req, res) => {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("This is not a WebSocket server");
});
return new Promise((resolve) => {
srv.listen(0, () => {
resolve({ server: srv,
port: srv.address().port });
});
});
}
/**
* Creates a WebSocket server for testing
* @param {object} options Options to pass to WebSocketServer
* @returns {Promise<{server: WebSocketServer, port: number}>} Promise that resolves to the created server and its port
*/
function createWebSocketServer(options = {}) {
return new Promise((resolve) => {
const wss = new WebSocketServer({ port: 0,
...options });
wss.on("listening", () => {
resolve({ server: wss,
port: wss.address().port });
});
});
} }
describe("WebSocket Monitor", { describe("WebSocket Monitor", {
}, () => { }, () => {
test("check() rejects with unexpected server response when connecting to non-WebSocket server", {}, async () => { test("check() rejects with unexpected server response when connecting to non-WebSocket server", {}, async (t) => {
const websocketMonitor = new WebSocketMonitorType(); const websocketMonitor = new WebSocketMonitorType();
const { server: srv, port } = await httpServer();
t.after(() => srv.close());
const monitor = { const monitor = {
url: "wss://example.org", url: `ws://localhost:${port}`,
wsIgnoreSecWebsocketAcceptHeader: false, wsIgnoreSecWebsocketAcceptHeader: false,
timeout: 30, timeout: 30,
}; };
@ -44,11 +84,13 @@ describe("WebSocket Monitor", {
); );
}); });
test("check() sets status to UP when connecting to secure WebSocket server", async () => { test("check() sets status to UP when connecting to WebSocket server", async (t) => {
const websocketMonitor = new WebSocketMonitorType(); const websocketMonitor = new WebSocketMonitorType();
const { server: wss, port } = await createWebSocketServer();
t.after(() => wss.close());
const monitor = { const monitor = {
url: "wss://echo.websocket.org", url: `ws://localhost:${port}`,
wsIgnoreSecWebsocketAcceptHeader: false, wsIgnoreSecWebsocketAcceptHeader: false,
accepted_statuscodes_json: JSON.stringify([ "1000" ]), accepted_statuscodes_json: JSON.stringify([ "1000" ]),
timeout: 30, timeout: 30,
@ -69,12 +111,12 @@ describe("WebSocket Monitor", {
}); });
test("check() sets status to UP when connecting to insecure WebSocket server", async (t) => { test("check() sets status to UP when connecting to insecure WebSocket server", async (t) => {
t.after(() => wss.close());
const websocketMonitor = new WebSocketMonitorType(); const websocketMonitor = new WebSocketMonitorType();
const wss = new WebSocketServer({ port: 8080 }); const { server: wss, port } = await createWebSocketServer();
t.after(() => wss.close());
const monitor = { const monitor = {
url: "ws://localhost:8080", url: `ws://localhost:${port}`,
wsIgnoreSecWebsocketAcceptHeader: false, wsIgnoreSecWebsocketAcceptHeader: false,
accepted_statuscodes_json: JSON.stringify([ "1000" ]), accepted_statuscodes_json: JSON.stringify([ "1000" ]),
timeout: 30, timeout: 30,
@ -94,11 +136,13 @@ describe("WebSocket Monitor", {
assert.deepStrictEqual(heartbeat, expected); assert.deepStrictEqual(heartbeat, expected);
}); });
test("check() rejects when status code does not match expected value", async () => { test("check() rejects when status code does not match expected value", async (t) => {
const websocketMonitor = new WebSocketMonitorType(); const websocketMonitor = new WebSocketMonitorType();
const { server: wss, port } = await createWebSocketServer();
t.after(() => wss.close());
const monitor = { const monitor = {
url: "wss://echo.websocket.org", url: `ws://localhost:${port}`,
wsIgnoreSecWebsocketAcceptHeader: false, wsIgnoreSecWebsocketAcceptHeader: false,
accepted_statuscodes_json: JSON.stringify([ "1001" ]), accepted_statuscodes_json: JSON.stringify([ "1001" ]),
timeout: 30, timeout: 30,
@ -115,11 +159,13 @@ describe("WebSocket Monitor", {
); );
}); });
test("check() rejects when expected status code is empty", async () => { test("check() rejects when expected status code is empty", async (t) => {
const websocketMonitor = new WebSocketMonitorType(); const websocketMonitor = new WebSocketMonitorType();
const { server: wss, port } = await createWebSocketServer();
t.after(() => wss.close());
const monitor = { const monitor = {
url: "wss://echo.websocket.org", url: `ws://localhost:${port}`,
wsIgnoreSecWebsocketAcceptHeader: false, wsIgnoreSecWebsocketAcceptHeader: false,
accepted_statuscodes_json: JSON.stringify([ "" ]), accepted_statuscodes_json: JSON.stringify([ "" ]),
timeout: 30, timeout: 30,
@ -137,12 +183,12 @@ describe("WebSocket Monitor", {
}); });
test("check() rejects when Sec-WebSocket-Accept header is invalid", async (t) => { test("check() rejects when Sec-WebSocket-Accept header is invalid", async (t) => {
t.after(() => wss.close());
const websocketMonitor = new WebSocketMonitorType(); const websocketMonitor = new WebSocketMonitorType();
const wss = await nonCompliantWS(); const { server: wss, port } = await nonCompliantWS();
t.after(() => wss.close());
const monitor = { const monitor = {
url: "ws://localhost:8080", url: `ws://localhost:${port}`,
wsIgnoreSecWebsocketAcceptHeader: false, wsIgnoreSecWebsocketAcceptHeader: false,
accepted_statuscodes_json: JSON.stringify([ "1000" ]), accepted_statuscodes_json: JSON.stringify([ "1000" ]),
timeout: 30, timeout: 30,
@ -160,12 +206,12 @@ describe("WebSocket Monitor", {
}); });
test("check() sets status to UP when ignoring invalid Sec-WebSocket-Accept header", async (t) => { test("check() sets status to UP when ignoring invalid Sec-WebSocket-Accept header", async (t) => {
const websocketMonitor = new WebSocketMonitorType();
const { server: wss, port } = await nonCompliantWS();
t.after(() => wss.close()); t.after(() => wss.close());
const websocketMonitor = new WebSocketMonitorType();
const wss = await nonCompliantWS();
const monitor = { const monitor = {
url: "ws://localhost:8080", url: `ws://localhost:${port}`,
wsIgnoreSecWebsocketAcceptHeader: true, wsIgnoreSecWebsocketAcceptHeader: true,
accepted_statuscodes_json: JSON.stringify([ "1000" ]), accepted_statuscodes_json: JSON.stringify([ "1000" ]),
timeout: 30, timeout: 30,
@ -185,11 +231,13 @@ describe("WebSocket Monitor", {
assert.deepStrictEqual(heartbeat, expected); assert.deepStrictEqual(heartbeat, expected);
}); });
test("check() sets status to UP for compliant WebSocket server when ignoring Sec-WebSocket-Accept", async () => { test("check() sets status to UP for compliant WebSocket server when ignoring Sec-WebSocket-Accept", async (t) => {
const websocketMonitor = new WebSocketMonitorType(); const websocketMonitor = new WebSocketMonitorType();
const { server: wss, port } = await createWebSocketServer();
t.after(() => wss.close());
const monitor = { const monitor = {
url: "wss://echo.websocket.org", url: `ws://localhost:${port}`,
wsIgnoreSecWebsocketAcceptHeader: true, wsIgnoreSecWebsocketAcceptHeader: true,
accepted_statuscodes_json: JSON.stringify([ "1000" ]), accepted_statuscodes_json: JSON.stringify([ "1000" ]),
timeout: 30, timeout: 30,
@ -209,11 +257,13 @@ describe("WebSocket Monitor", {
assert.deepStrictEqual(heartbeat, expected); assert.deepStrictEqual(heartbeat, expected);
}); });
test("check() rejects non-WebSocket server even when ignoring Sec-WebSocket-Accept", async () => { test("check() rejects non-WebSocket server even when ignoring Sec-WebSocket-Accept", async (t) => {
const websocketMonitor = new WebSocketMonitorType(); const websocketMonitor = new WebSocketMonitorType();
const { server: srv, port } = await httpServer();
t.after(() => srv.close());
const monitor = { const monitor = {
url: "wss://example.org", url: `ws://localhost:${port}`,
wsIgnoreSecWebsocketAcceptHeader: true, wsIgnoreSecWebsocketAcceptHeader: true,
accepted_statuscodes_json: JSON.stringify([ "1000" ]), accepted_statuscodes_json: JSON.stringify([ "1000" ]),
timeout: 30, timeout: 30,
@ -230,11 +280,18 @@ describe("WebSocket Monitor", {
); );
}); });
test("check() rejects when server does not support requested subprotocol", async () => { test("check() rejects when server does not support requested subprotocol", async (t) => {
const websocketMonitor = new WebSocketMonitorType(); const websocketMonitor = new WebSocketMonitorType();
const { server: wss, port } = await createWebSocketServer({
handleProtocols: (protocols) => {
// Explicitly reject all subprotocols
return null;
}
});
t.after(() => wss.close());
const monitor = { const monitor = {
url: "wss://echo.websocket.org", url: `ws://localhost:${port}`,
wsIgnoreSecWebsocketAcceptHeader: false, wsIgnoreSecWebsocketAcceptHeader: false,
wsSubprotocol: "ocpp1.6", wsSubprotocol: "ocpp1.6",
accepted_statuscodes_json: JSON.stringify([ "1000" ]), accepted_statuscodes_json: JSON.stringify([ "1000" ]),
@ -252,11 +309,13 @@ describe("WebSocket Monitor", {
); );
}); });
test("check() rejects when multiple subprotocols contain invalid characters", async () => { test("check() rejects when multiple subprotocols contain invalid characters", async (t) => {
const websocketMonitor = new WebSocketMonitorType(); const websocketMonitor = new WebSocketMonitorType();
const { server: wss, port } = await createWebSocketServer();
t.after(() => wss.close());
const monitor = { const monitor = {
url: "wss://echo.websocket.org", url: `ws://localhost:${port}`,
wsIgnoreSecWebsocketAcceptHeader: false, wsIgnoreSecWebsocketAcceptHeader: false,
wsSubprotocol: " # & ,ocpp2.0 [] , ocpp1.6 , ,, ; ", wsSubprotocol: " # & ,ocpp2.0 [] , ocpp1.6 , ,, ; ",
accepted_statuscodes_json: JSON.stringify([ "1000" ]), accepted_statuscodes_json: JSON.stringify([ "1000" ]),
@ -275,16 +334,16 @@ describe("WebSocket Monitor", {
}); });
test("check() sets status to UP when subprotocol with multiple spaces is accepted", async (t) => { test("check() sets status to UP when subprotocol with multiple spaces is accepted", async (t) => {
t.after(() => wss.close());
const websocketMonitor = new WebSocketMonitorType(); const websocketMonitor = new WebSocketMonitorType();
const wss = new WebSocketServer({ port: 8080, const { server: wss, port } = await createWebSocketServer({
handleProtocols: (protocols) => { handleProtocols: (protocols) => {
return Array.from(protocols).includes("test") ? "test" : null; return Array.from(protocols).includes("test") ? "test" : null;
} }
}); });
t.after(() => wss.close());
const monitor = { const monitor = {
url: "ws://localhost:8080", url: `ws://localhost:${port}`,
wsIgnoreSecWebsocketAcceptHeader: false, wsIgnoreSecWebsocketAcceptHeader: false,
wsSubprotocol: "invalid , test ", wsSubprotocol: "invalid , test ",
accepted_statuscodes_json: JSON.stringify([ "1000" ]), accepted_statuscodes_json: JSON.stringify([ "1000" ]),
@ -306,16 +365,16 @@ describe("WebSocket Monitor", {
}); });
test("check() sets status to UP when server supports requested subprotocol", async (t) => { test("check() sets status to UP when server supports requested subprotocol", async (t) => {
t.after(() => wss.close());
const websocketMonitor = new WebSocketMonitorType(); const websocketMonitor = new WebSocketMonitorType();
const wss = new WebSocketServer({ port: 8080, const { server: wss, port } = await createWebSocketServer({
handleProtocols: (protocols) => { handleProtocols: (protocols) => {
return Array.from(protocols).includes("test") ? "test" : null; return Array.from(protocols).includes("test") ? "test" : null;
} }
}); });
t.after(() => wss.close());
const monitor = { const monitor = {
url: "ws://localhost:8080", url: `ws://localhost:${port}`,
wsIgnoreSecWebsocketAcceptHeader: false, wsIgnoreSecWebsocketAcceptHeader: false,
wsSubprotocol: "invalid,test", wsSubprotocol: "invalid,test",
accepted_statuscodes_json: JSON.stringify([ "1000" ]), accepted_statuscodes_json: JSON.stringify([ "1000" ]),