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
Next Next commit
WIP
  • Loading branch information
mtojek committed Apr 15, 2024
commit 815691027b2fabfa021e27720dab45c6febd8cf7
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
49 changes: 49 additions & 0 deletions site/e2e/tests/deployment/security.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { expect, test, type Page } from "@playwright/test";
import * as API from "api/api";
import { setupApiCalls } from "../../api";

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

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

// Load deployment settings
const config = await API.getDeploymentConfig();

// Check flags
await expectConfigOption(page, config, "ssh-keygen-algorithm")
await expectConfigOption(page, config, "secure-auth-cookie")
await expectConfigOption(page, config, "disable-owner-workspace-access")

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")
});

const expectConfigOption = async(page :Page, config: API.DeploymentConfig, flag: string) => {
let value = config.options.find(option => option.flag === flag)?.value;
if (value === undefined) {
throw new Error(`Option with env ${flag} has undefined value.`);
}

let type = "";
if (typeof value === "boolean") {
type = value ? "option-enabled" : "option-disabled";
value = value ? "Enabled" : "Disabled";
} else if (typeof value === "number") {
type = "option-value-number";
value = String(value);
} else if (!value || value.length === 0) {
type = "option-value-empty";
} else if (typeof value === "string") {
type = "option-value-string";
} else if (typeof value === "object") {
type = "object-array";
} else {
type = "option-value-json";
}

const configOption = page.locator(`div.options-table .option-${flag} .${type}`);
await expect(configOption).toHaveText(String(value));
}
15 changes: 0 additions & 15 deletions site/e2e/tests/deployment/security.ts

This file was deleted.

8 changes: 6 additions & 2 deletions site/src/pages/DeploySettingsPage/Option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export const OptionValue: FC<OptionValueProps> = (props) => {
const theme = useTheme();

if (typeof value === "boolean") {
return value ? <EnabledBadge /> : <DisabledBadge />;
return (
<div className="option-value-boolean">
{value ? <EnabledBadge /> : <DisabledBadge />}
</div>
);
}

if (typeof value === "number") {
Expand Down Expand Up @@ -106,7 +110,7 @@ export const OptionValue: FC<OptionValueProps> = (props) => {

if (Array.isArray(value)) {
return (
<ul css={{ listStylePosition: "inside" }}>
<ul css={{ listStylePosition: "inside" }} className="option-array">
{value.map((item) => (
<li key={item} css={styles.option}>
{item}
Expand Down
Loading