Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion server/src/controllers/controllerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ type SSLCheckerType = typeof sslChecker;
export const fetchMonitorCertificate = async (checker: SSLCheckerType, monitor: Monitor): Promise<SSLDetails> => {
const monitorUrl = new URL(monitor.url);
const hostname = monitorUrl.hostname;
const cert = await checker(hostname);
const port = monitorUrl.port ? Number(monitorUrl.port) : undefined;
const cert = await checker(hostname, port ? { port } : undefined);
if (cert?.validTo === null || cert?.validTo === undefined) {
throw new Error("Certificate not found");
}
Expand Down
34 changes: 34 additions & 0 deletions server/test/unit/controllers/controllerUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { describe, expect, it, jest } from "@jest/globals";
import { fetchMonitorCertificate } from "../../../src/controllers/controllerUtils.ts";
import type { Monitor } from "../../../src/types/monitor.ts";

const certificate = {
daysRemaining: 30,
valid: true,
validFrom: "2026-01-01T00:00:00.000Z",
validTo: "2026-02-01T00:00:00.000Z",
validFor: ["checkmate.example.org"],
};

const makeMonitor = (url: string) =>
({
url,
}) as Monitor;

describe("fetchMonitorCertificate", () => {
it("passes a custom HTTPS port to the SSL checker", async () => {
const checker = jest.fn().mockResolvedValue(certificate);

await fetchMonitorCertificate(checker, makeMonitor("https://checkmate.example.org:54321/status"));

expect(checker).toHaveBeenCalledWith("checkmate.example.org", { port: 54321 });
});

it("uses the SSL checker's default port when the URL does not include one", async () => {
const checker = jest.fn().mockResolvedValue(certificate);

await fetchMonitorCertificate(checker, makeMonitor("https://checkmate.example.org/status"));

expect(checker).toHaveBeenCalledWith("checkmate.example.org", undefined);
});
});
Loading