Skip to content

Commit de7c1db

Browse files
committed
real good audit logs tests
1 parent bc1108e commit de7c1db

File tree

4 files changed

+35
-106
lines changed

4 files changed

+35
-106
lines changed

site/e2e/playwright.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export default defineConfig({
6464
timeout: 30_000,
6565
},
6666
],
67+
reporter: [["./reporter.ts"]],
6768
use: {
6869
actionTimeout: 5000,
6970
baseURL: `http://localhost:${coderPort}`,

site/e2e/tests/auditLogs.oldspec.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

site/e2e/tests/auditLogs.spec.ts

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { expect, test } from "@playwright/test";
1+
import { expect, type Page, test } from "@playwright/test";
22
import { users } from "../constants";
33
import {
44
createTemplate,
55
createWorkspace,
6+
currentUser,
67
login,
78
requiresLicense,
89
} from "../helpers";
@@ -13,32 +14,46 @@ test.beforeEach(async ({ page }) => {
1314
await login(page, users.auditor);
1415
});
1516

16-
test.skip("inspecting and filtering audit logs", async ({ page }) => {
17+
async function resetSearch(page: Page) {
18+
const clearButton = page.getByLabel("Clear search");
19+
if (await clearButton.isVisible()) {
20+
await clearButton.click();
21+
}
22+
23+
// Filter by the auditor test user to prevent race conditions
24+
const user = currentUser(page);
25+
await expect(page.getByText("All users")).toBeVisible();
26+
await page.getByPlaceholder("Search...").fill(`username:${user.username}`);
27+
await expect(page.getByText("All users")).not.toBeVisible();
28+
}
29+
30+
test("inspecting and filtering audit logs", async ({ page }) => {
1731
requiresLicense();
1832

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

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

40+
const user = currentUser(page);
41+
const loginMessage = `${user.username} logged in`;
42+
const startedWorkspaceMessage = `${user.username} started workspace ${workspaceName}`;
43+
2744
// Make sure those things we did all actually show up
28-
await expect(page.getByText(`${userName} logged in`)).toBeVisible();
29-
await expect(
30-
page.getByText(`${userName} created template ${templateName}`),
31-
).toBeVisible();
45+
await resetSearch(page);
46+
await expect(page.getByText(loginMessage).first()).toBeVisible();
3247
await expect(
33-
page.getByText(`${userName} created workspace ${workspaceName}`),
48+
page.getByText(`${user.username} created template ${templateName}`),
3449
).toBeVisible();
3550
await expect(
36-
page.getByText(`${userName} started workspace ${workspaceName}`),
51+
page.getByText(`${user.username} created workspace ${workspaceName}`),
3752
).toBeVisible();
3853

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

51-
const startedWorkspaceMessage = `${userName} started workspace ${workspaceName}`;
52-
const loginMessage = `${userName} logged in`;
66+
await expect(page.getByText(startedWorkspaceMessage)).toBeVisible();
5367

5468
// Filter by resource type
69+
await resetSearch(page);
5570
await page.getByText("All resource types").click();
5671
const workspaceBuildsOption = page.getByText("Workspace Build");
5772
await workspaceBuildsOption.scrollIntoViewIfNeeded({ timeout: 5000 });
@@ -60,19 +75,15 @@ test.skip("inspecting and filtering audit logs", async ({ page }) => {
6075
await expect(page.getByText(startedWorkspaceMessage)).toBeVisible();
6176
// Logins should no longer be visible
6277
await expect(page.getByText(loginMessage)).not.toBeVisible();
63-
64-
// Clear filters, everything should be visible again
6578
await page.getByLabel("Clear search").click();
66-
await expect(page.getByText(startedWorkspaceMessage)).toBeVisible();
67-
await expect(page.getByText(loginMessage)).toBeVisible();
79+
await expect(page.getByText("All resource types")).toBeVisible();
6880

6981
// Filter by action type
82+
await resetSearch(page);
7083
await page.getByText("All actions").click();
71-
const loginOption = page.getByText("Login");
72-
await loginOption.scrollIntoViewIfNeeded({ timeout: 5000 });
73-
await loginOption.click();
84+
await page.getByText("Login", { exact: true }).click();
7485
// Logins should be visible
75-
await expect(page.getByText(loginMessage)).toBeVisible();
86+
await expect(page.getByText(loginMessage).first()).toBeVisible();
7687
// Our workspace build should no longer be visible
7788
await expect(page.getByText(startedWorkspaceMessage)).not.toBeVisible();
7889
});

site/e2e/tests/workspaces/createWorkspace.spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,9 @@ test("create workspace with disable_param search params", async ({ page }) => {
153153
await expect(page.getByLabel(/Second parameter/i)).toBeDisabled();
154154
});
155155

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

0 commit comments

Comments
 (0)