Skip to content
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
real good audit logs tests
  • Loading branch information
aslilac committed Dec 19, 2024
commit de7c1dbbd97aa2da29c021b8df7cac97d2a02340
1 change: 1 addition & 0 deletions site/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default defineConfig({
timeout: 30_000,
},
],
reporter: [["./reporter.ts"]],
use: {
actionTimeout: 5000,
baseURL: `http://localhost:${coderPort}`,
Expand Down
81 changes: 0 additions & 81 deletions site/e2e/tests/auditLogs.oldspec.ts

This file was deleted.

51 changes: 31 additions & 20 deletions site/e2e/tests/auditLogs.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { expect, test } from "@playwright/test";
import { expect, type Page, test } from "@playwright/test";
import { users } from "../constants";
import {
createTemplate,
createWorkspace,
currentUser,
login,
requiresLicense,
} from "../helpers";
Expand All @@ -13,32 +14,46 @@ test.beforeEach(async ({ page }) => {
await login(page, users.auditor);
});

test.skip("inspecting and filtering audit logs", async ({ page }) => {
async function resetSearch(page: Page) {
const clearButton = page.getByLabel("Clear search");
if (await clearButton.isVisible()) {
await clearButton.click();
}

// Filter by the auditor test user to prevent race conditions
const user = currentUser(page);
await expect(page.getByText("All users")).toBeVisible();
await page.getByPlaceholder("Search...").fill(`username:${user.username}`);
await expect(page.getByText("All users")).not.toBeVisible();
}

test("inspecting and filtering audit logs", async ({ page }) => {
requiresLicense();

const userName = "admin";
// Do some stuff that should show up in the audit logs
const templateName = await createTemplate(page);
const workspaceName = await createWorkspace(page, templateName);

// Go to the audit history
await page.goto("/audit");

const user = currentUser(page);
const loginMessage = `${user.username} logged in`;
const startedWorkspaceMessage = `${user.username} started workspace ${workspaceName}`;

// Make sure those things we did all actually show up
await expect(page.getByText(`${userName} logged in`)).toBeVisible();
await expect(
page.getByText(`${userName} created template ${templateName}`),
).toBeVisible();
await resetSearch(page);
await expect(page.getByText(loginMessage).first()).toBeVisible();
await expect(
page.getByText(`${userName} created workspace ${workspaceName}`),
page.getByText(`${user.username} created template ${templateName}`),
).toBeVisible();
await expect(
page.getByText(`${userName} started workspace ${workspaceName}`),
page.getByText(`${user.username} created workspace ${workspaceName}`),
).toBeVisible();

// Make sure we can inspect the details of the log item
const createdWorkspace = page.locator(".MuiTableRow-root", {
hasText: `${userName} created workspace ${workspaceName}`,
hasText: `${user.username} created workspace ${workspaceName}`,
});
await createdWorkspace.getByLabel("open-dropdown").click();
await expect(
Expand All @@ -48,10 +63,10 @@ test.skip("inspecting and filtering audit logs", async ({ page }) => {
createdWorkspace.getByText(`name: "${workspaceName}"`),
).toBeVisible();

const startedWorkspaceMessage = `${userName} started workspace ${workspaceName}`;
const loginMessage = `${userName} logged in`;
await expect(page.getByText(startedWorkspaceMessage)).toBeVisible();

// Filter by resource type
await resetSearch(page);
await page.getByText("All resource types").click();
const workspaceBuildsOption = page.getByText("Workspace Build");
await workspaceBuildsOption.scrollIntoViewIfNeeded({ timeout: 5000 });
Expand All @@ -60,19 +75,15 @@ test.skip("inspecting and filtering audit logs", async ({ page }) => {
await expect(page.getByText(startedWorkspaceMessage)).toBeVisible();
// Logins should no longer be visible
await expect(page.getByText(loginMessage)).not.toBeVisible();

// Clear filters, everything should be visible again
await page.getByLabel("Clear search").click();
await expect(page.getByText(startedWorkspaceMessage)).toBeVisible();
await expect(page.getByText(loginMessage)).toBeVisible();
await expect(page.getByText("All resource types")).toBeVisible();

// Filter by action type
await resetSearch(page);
await page.getByText("All actions").click();
const loginOption = page.getByText("Login");
await loginOption.scrollIntoViewIfNeeded({ timeout: 5000 });
await loginOption.click();
await page.getByText("Login", { exact: true }).click();
// Logins should be visible
await expect(page.getByText(loginMessage)).toBeVisible();
await expect(page.getByText(loginMessage).first()).toBeVisible();
// Our workspace build should no longer be visible
await expect(page.getByText(startedWorkspaceMessage)).not.toBeVisible();
});
8 changes: 3 additions & 5 deletions site/e2e/tests/workspaces/createWorkspace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,9 @@ test("create workspace with disable_param search params", async ({ page }) => {
await expect(page.getByLabel(/Second parameter/i)).toBeDisabled();
});

test("create docker workspace", async ({ context, page }) => {
test.skip(
true,
"creating docker containers is currently leaky. They are not cleaned up when the tests are over.",
);
// Creating docker containers is currently leaky. They are not cleaned up when
// the tests are over.
test.skip("create docker workspace", async ({ context, page }) => {
requireTerraformProvisioner();
const template = await createTemplate(page, StarterTemplates.STARTER_DOCKER);

Expand Down
Loading