Skip to content

test(site): add e2e tests for security #12961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Done
  • Loading branch information
mtojek committed Apr 15, 2024
commit 3cc9a085c150cf8740bcb53ae6e964065bc5fced
2 changes: 1 addition & 1 deletion site/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineConfig({
timeout: 50_000,
},
],
//reporter: [["./reporter.ts"]],
reporter: [["./reporter.ts"]],
use: {
baseURL: `http://localhost:${coderPort}`,
video: "retain-on-failure",
Expand Down
33 changes: 21 additions & 12 deletions site/e2e/tests/deployment/security.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,30 @@ import { setupApiCalls } from "../../api";
test("enabled security settings", async ({ page }) => {
await setupApiCalls(page);

const config = await API.getDeploymentConfig();

await page.goto("/deployment/security", { waitUntil: "domcontentloaded" });

// Load deployment settings
const config = await API.getDeploymentConfig();
const flags = [
"ssh-keygen-algorithm",
"secure-auth-cookie",
"disable-owner-workspace-access",

// Check flags
await expectConfigOption(page, config, "ssh-keygen-algorithm");
await expectConfigOption(page, config, "secure-auth-cookie");
await expectConfigOption(page, config, "disable-owner-workspace-access");
"tls-redirect-http-to-https",
"strict-transport-security",
"tls-address",
"tls-allow-insecure-ciphers",
"tls-client-auth",
"tls-enable",
"tls-min-version",
];

await expectConfigOption(page, config, "tls-redirect-http-to-https");
await expectConfigOption(page, config, "strict-transport-security");
await expectConfigOption(page, config, "tls-address");
await expectConfigOption(page, config, "tls-allow-insecure-ciphers");
for (const flag of flags) {
await verifyConfigFlag(page, config, flag);
}
});

const expectConfigOption = async (
const verifyConfigFlag = async (
page: Page,
config: API.DeploymentConfig,
flag: string,
Expand All @@ -31,9 +38,11 @@ const expectConfigOption = async (
throw new Error(`Option with env ${flag} has undefined value.`);
}

// Map option type to test class name.
let type = "",
value = opt.value;
if (typeof value === "boolean") {
// Boolean options map to string (Enabled/Disabled).
type = value ? "option-enabled" : "option-disabled";
value = value ? "Enabled" : "Disabled";
} else if (typeof value === "number") {
Expand All @@ -52,7 +61,7 @@ const expectConfigOption = async (
// Special cases
if (opt.flag === "strict-transport-security" && opt.value === 0) {
type = "option-value-string";
value = "Disabled";
value = "Disabled"; // Display "Disabled" instead of zero seconds.
}

const configOption = page.locator(
Expand Down
Loading