|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import { login, restoreSqliteSnapshot, screenshot } from "../util-test"; |
| 3 | + |
| 4 | +/** |
| 5 | + * Create an HTTP monitor via the UI and navigate back to the dashboard. |
| 6 | + * @param {import('@playwright/test').Page} page - Playwright page instance. |
| 7 | + * @param {{ name: string, url: string, ignoreTls?: boolean }} param1 - Monitor parameters. |
| 8 | + * @returns {Promise<void>} Resolves when the monitor has been saved and the dashboard is shown. |
| 9 | + */ |
| 10 | +async function createHttpMonitor(page, { name, url, ignoreTls = false }) { |
| 11 | + await page.goto("./add"); |
| 12 | + await login(page); |
| 13 | + |
| 14 | + await expect(page.getByTestId("monitor-type-select")).toBeVisible(); |
| 15 | + await page.getByTestId("monitor-type-select").selectOption("http"); |
| 16 | + |
| 17 | + await page.getByTestId("friendly-name-input").fill(name); |
| 18 | + await page.getByTestId("url-input").fill(url); |
| 19 | + |
| 20 | + if (ignoreTls) { |
| 21 | + // No data-testid, so select by id |
| 22 | + await page.locator("#ignore-tls").check(); |
| 23 | + } |
| 24 | + |
| 25 | + await page.getByTestId("save-button").click(); |
| 26 | + await page.waitForURL("/dashboard/*"); |
| 27 | +} |
| 28 | + |
| 29 | +/** |
| 30 | + * Wait until the monitor status badge matches the expected value. |
| 31 | + * @param {import('@playwright/test').Page} page - Playwright page instance. |
| 32 | + * @param {string} expected - Expected status text (case-insensitive). One of: up | down | pending | maintenance. |
| 33 | + * @param {number} timeoutMs - Max time to wait in milliseconds. Default: 15000. |
| 34 | + * @returns {Promise<void>} Resolves when the expected status appears or rejects on timeout. |
| 35 | + */ |
| 36 | +async function waitForStatus(page, expected, timeoutMs = 15000) { |
| 37 | + await expect(page.getByTestId("monitor-status")).toHaveText(expected, { |
| 38 | + ignoreCase: true, |
| 39 | + timeout: timeoutMs, |
| 40 | + }); |
| 41 | +} |
| 42 | + |
| 43 | +test.describe("TLS Revocation (Policy: OCSP Mixed with failHard=false)", () => { |
| 44 | + test.beforeEach(async ({ page }) => { |
| 45 | + await restoreSqliteSnapshot(page); |
| 46 | + }); |
| 47 | + |
| 48 | + test("if a domain is not revoked, the monitor should be UP", async ({ page }, testInfo) => { |
| 49 | + await createHttpMonitor(page, { name: "not-revoked", |
| 50 | + url: "https://www.example.com" }); |
| 51 | + await waitForStatus(page, "up"); |
| 52 | + await screenshot(testInfo, page); |
| 53 | + }); |
| 54 | + |
| 55 | + test("if a domain is OCSP-revoked, the monitor should be DOWN", async ({ page }, testInfo) => { |
| 56 | + await createHttpMonitor(page, { name: "ocsp-revoked", |
| 57 | + url: "https://aaacertificateservices.comodoca.com:444" }); |
| 58 | + await waitForStatus(page, "down"); |
| 59 | + await screenshot(testInfo, page); |
| 60 | + }); |
| 61 | + |
| 62 | + // TODO: Modify this test when we support CRLs |
| 63 | + test("if a domain is CRL-only revoked, the monitor should be UP (because we don't support CRLs yet and failHard=false)", async ({ page }, testInfo) => { |
| 64 | + await createHttpMonitor(page, { name: "crl-only-revoked", |
| 65 | + url: "https://revoked.badssl.com" }); |
| 66 | + await waitForStatus(page, "up"); |
| 67 | + await screenshot(testInfo, page); |
| 68 | + }); |
| 69 | + |
| 70 | + // StackOverflow uses Let's Encrypt which recently dropped OCSP support (c.f. https://letsencrypt.org/2025/08/06/ocsp-service-has-reached-end-of-life), making it a reliable test target |
| 71 | + test("if OCSP is unavailable for a domain, the monitor should be UP (because failHard=false)", async ({ page }, testInfo) => { |
| 72 | + await createHttpMonitor(page, { name: "ocsp-unavailable", |
| 73 | + url: "https://stackoverflow.com" }); |
| 74 | + await waitForStatus(page, "up"); |
| 75 | + await screenshot(testInfo, page); |
| 76 | + }); |
| 77 | + |
| 78 | + test("if ignoreTls=true for a domain, the monitor should be UP (regardless of the certificate status)", async ({ page }, testInfo) => { |
| 79 | + await createHttpMonitor(page, { name: "tls-ignored", |
| 80 | + url: "https://aaacertificateservices.comodoca.com:444", |
| 81 | + ignoreTls: true }); |
| 82 | + await waitForStatus(page, "up"); |
| 83 | + await screenshot(testInfo, page); |
| 84 | + }); |
| 85 | +}); |
0 commit comments