|
| 1 | +import { expect, test, type Page } from "@playwright/test"; |
| 2 | +import * as API from "api/api"; |
| 3 | +import { setupApiCalls } from "../../api"; |
| 4 | + |
| 5 | +test("enabled security settings", async ({ page }) => { |
| 6 | + await setupApiCalls(page); |
| 7 | + |
| 8 | + await page.goto("/deployment/security", { waitUntil: "domcontentloaded" }); |
| 9 | + |
| 10 | + // Load deployment settings |
| 11 | + const config = await API.getDeploymentConfig(); |
| 12 | + |
| 13 | + // Check flags |
| 14 | + await expectConfigOption(page, config, "ssh-keygen-algorithm") |
| 15 | + await expectConfigOption(page, config, "secure-auth-cookie") |
| 16 | + await expectConfigOption(page, config, "disable-owner-workspace-access") |
| 17 | + |
| 18 | + await expectConfigOption(page, config, "tls-redirect-http-to-https") |
| 19 | + await expectConfigOption(page, config, "strict-transport-security") |
| 20 | + await expectConfigOption(page, config, "tls-address") |
| 21 | + await expectConfigOption(page, config, "tls-allow-insecure-ciphers") |
| 22 | +}); |
| 23 | + |
| 24 | +const expectConfigOption = async(page :Page, config: API.DeploymentConfig, flag: string) => { |
| 25 | + let value = config.options.find(option => option.flag === flag)?.value; |
| 26 | + if (value === undefined) { |
| 27 | + throw new Error(`Option with env ${flag} has undefined value.`); |
| 28 | + } |
| 29 | + |
| 30 | + let type = ""; |
| 31 | + if (typeof value === "boolean") { |
| 32 | + type = value ? "option-enabled" : "option-disabled"; |
| 33 | + value = value ? "Enabled" : "Disabled"; |
| 34 | + } else if (typeof value === "number") { |
| 35 | + type = "option-value-number"; |
| 36 | + value = String(value); |
| 37 | + } else if (!value || value.length === 0) { |
| 38 | + type = "option-value-empty"; |
| 39 | + } else if (typeof value === "string") { |
| 40 | + type = "option-value-string"; |
| 41 | + } else if (typeof value === "object") { |
| 42 | + type = "object-array"; |
| 43 | + } else { |
| 44 | + type = "option-value-json"; |
| 45 | + } |
| 46 | + |
| 47 | + const configOption = page.locator(`div.options-table .option-${flag} .${type}`); |
| 48 | + await expect(configOption).toHaveText(String(value)); |
| 49 | +} |
0 commit comments