Skip to content

refactor(site): verify deployment config flags in e2e tests #12986

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 4 commits into from
Apr 17, 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
Next Next commit
done
  • Loading branch information
mtojek committed Apr 17, 2024
commit f4f081427d6b5265df008d7049cbe1a8532df01d
23 changes: 5 additions & 18 deletions site/e2e/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ export async function verifyConfigFlagNumber(
flag: string,
) {
const opt = findConfigOption(config, flag);
const type = "option-value-number";

const configOption = page.locator(
`div.options-table .option-${flag} .${type}`,
`div.options-table .option-${flag} .option-value-number`,
);
await expect(configOption).toHaveText(String(opt.value));
}
Expand All @@ -85,16 +83,9 @@ export async function verifyConfigFlagString(
flag: string,
) {
const opt = findConfigOption(config, flag);
const type = "option-value-string";

// Special cases
/*if (opt.flag === "strict-transport-security" && opt.value === 0) {
type = "option-value-string";
value = "Disabled"; // Display "Disabled" instead of zero seconds.
}*/

const configOption = page.locator(
`div.options-table .option-${flag} .${type}`,
`div.options-table .option-${flag} .option-value-string`,
);
await expect(configOption).toHaveText(opt.value);
}
Expand All @@ -105,10 +96,8 @@ export async function verifyConfigFlagArray(
flag: string,
) {
const opt = findConfigOption(config, flag);
const type = "option-array";

const configOption = page.locator(
`div.options-table .option-${flag} .${type}`,
`div.options-table .option-${flag} .option-array`,
);

// Verify array of options with simple dots
Expand All @@ -123,10 +112,8 @@ export async function verifyConfigFlagEntries(
flag: string,
) {
const opt = findConfigOption(config, flag);
const type = "option-array";

const configOption = page.locator(
`div.options-table .option-${flag} .${type}`,
`div.options-table .option-${flag} .option-array`,
);

// Verify array of options with green marks.
Expand All @@ -141,7 +128,7 @@ export async function verifyConfigFlagEntries(
});
}

function findConfigOption(
export function findConfigOption(
config: API.DeploymentConfig,
flag: string,
): SerpentOption {
Expand Down
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"]],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this part of the change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I had to remove it.

use: {
baseURL: `http://localhost:${coderPort}`,
video: "retain-on-failure",
Expand Down
53 changes: 36 additions & 17 deletions site/e2e/tests/deployment/security.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
import { test } from "@playwright/test";
import type { Page } from "@playwright/test";
import { expect, test } from "@playwright/test";
import type * as API from "api/api";
import { getDeploymentConfig } from "api/api";
import { setupApiCalls, verifyConfigFlag } from "../../api";
import {
findConfigOption,
setupApiCalls,
verifyConfigFlagBoolean,
verifyConfigFlagNumber,
verifyConfigFlagString,
} from "../../api";

test("enabled security settings", async ({ page }) => {
await setupApiCalls(page);
const config = await getDeploymentConfig();

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

const flags = [
"ssh-keygen-algorithm",
"secure-auth-cookie",
"disable-owner-workspace-access",
await verifyConfigFlagString(page, config, "ssh-keygen-algorithm");
await verifyConfigFlagBoolean(page, config, "secure-auth-cookie");
await verifyConfigFlagBoolean(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 verifyConfigFlagBoolean(page, config, "tls-redirect-http-to-https");
await verifyStrictTransportSecurity(page, config);
await verifyConfigFlagString(page, config, "tls-address");
await verifyConfigFlagBoolean(page, config, "tls-allow-insecure-ciphers");
await verifyConfigFlagString(page, config, "tls-client-auth");
await verifyConfigFlagBoolean(page, config, "tls-enable");
await verifyConfigFlagString(page, config, "tls-min-version");
});

for (const flag of flags) {
await verifyConfigFlag(page, config, flag);
async function verifyStrictTransportSecurity(
page: Page,
config: API.DeploymentConfig,
) {
const flag = "strict-transport-security";
const opt = findConfigOption(config, flag);
if (opt.value !== 0) {
await verifyConfigFlagNumber(page, config, flag);
return; // Make sure the return statement is inside the if block
}
});

const configOption = page.locator(
`div.options-table .option-${flag} .option-value-string`,
);
await expect(configOption).toHaveText("Disabled");
}