Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

test: add an e2e audit logs test#12868

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
aslilac merged 5 commits intomainfrome2e-audit
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
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
2 changes: 1 addition & 1 deletioncoderd/prometheusmetrics/prometheusmetrics_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@ import (
"testing"
"time"

"github.com/coder/coder/v2/cryptorand"
"github.com/google/uuid"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
Expand All@@ -32,6 +31,7 @@ import (
"github.com/coder/coder/v2/coderd/prometheusmetrics"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/agentsdk"
"github.com/coder/coder/v2/cryptorand"
"github.com/coder/coder/v2/provisioner/echo"
"github.com/coder/coder/v2/provisionersdk/proto"
"github.com/coder/coder/v2/tailnet"
Expand Down
6 changes: 4 additions & 2 deletionsscripts/lib.sh
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -190,6 +190,8 @@ if [[ "${CODER_LIBSH_NO_CHECK_DEPENDENCIES:-}" != *t* ]]; then
if isdarwin; then
log "On darwin:"
log "- brew install bash"
# shellcheck disable=SC2016
log '- Add "$(brew --prefix bash)/bin" to your PATH'
log "- Restart your terminal"
fi
log
Expand All@@ -203,7 +205,7 @@ if [[ "${CODER_LIBSH_NO_CHECK_DEPENDENCIES:-}" != *t* ]]; then
log "On darwin:"
log "- brew install gnu-getopt"
# shellcheck disable=SC2016
log '- Add "$(brew --prefix)/opt/gnu-getopt/bin" to your PATH'
log '- Add "$(brew --prefixgnu-getopt)/bin" to your PATH'
log "- Restart your terminal"
fi
log
Expand All@@ -226,7 +228,7 @@ if [[ "${CODER_LIBSH_NO_CHECK_DEPENDENCIES:-}" != *t* ]]; then
log "On darwin:"
log "- brew install make"
# shellcheck disable=SC2016
log '- Add "$(brew --prefix)/opt/make/libexec/gnubin" to your PATH (you should Google this first)'
log '- Add "$(brew --prefix make)/libexec/gnubin" to your PATH'
log "- Restart your terminal"
fi
log
Expand Down
2 changes: 2 additions & 0 deletionssite/e2e/README.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,8 @@ cd site
# Build the frontend assets. If you are actively changing
# the site to debug an issue, add `--watch`.
pnpm build
# Alternatively, build with debug info and source maps:
NODE_ENV=development pnpm vite build --mode=development
# Install the browsers to `~/.cache/ms-playwright`.
pnpm playwright:install
# Run E2E tests. You can see the configuration of the server
Expand Down
2 changes: 1 addition & 1 deletionsite/e2e/tests/app.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,7 @@ import {
} from "../helpers";
import { beforeCoderTest } from "../hooks";

test.beforeEach(async({ page }) => await beforeCoderTest(page));
test.beforeEach(({ page }) => beforeCoderTest(page));

test("app", async ({ context, page }) => {
const appContent = "Hello World";
Expand Down
69 changes: 69 additions & 0 deletionssite/e2e/tests/auditLogs.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
import { expect, test } from "@playwright/test";
import {
createTemplate,
createWorkspace,
requiresEnterpriseLicense,
} from "../helpers";
import { beforeCoderTest } from "../hooks";

test.beforeEach(({ page }) => beforeCoderTest(page));

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

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

// 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 expect(
page.getByText(`${userName} created workspace ${workspaceName}`),
).toBeVisible();
await expect(
page.getByText(`${userName} started 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}`,
});
Comment on lines +35 to +37
Copy link
Member

Choose a reason for hiding this comment

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

I don't fully understand this code, but I'm a little worried. If I'm understanding it right, the code is basically grabbing an element via the CSS class it gets from MUI, and then asserting it has the specific content?

I don't know how stable MUI class names are, but is there any way we can update this to be a role-based selector? Assuming MUI doesn't mess up their table semantics,this element should have arow role as well

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I'll double check, but I didn't notice a role, and I generally prefer those.

but also MUI's classes names are a documented part of their public API, so it should be safe to depend on.

await createdWorkspace.getByLabel("open-dropdown").click();
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 a label that we're visibly showing in the UI? The hyphen makes it look like an implementation detail

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

It's anaria-label. Which probably still shouldn't have a hyphen, but it is what it is. 😅

await expect(
createdWorkspace.getByText(`automatic_updates: "never"`),
).toBeVisible();
await expect(
createdWorkspace.getByText(`name: "${workspaceName}"`),
).toBeVisible();

const startedWorkspaceMessage = `${userName} started workspace ${workspaceName}`;
const loginMessage = `${userName} logged in`;

// Filter by resource type
await page.getByText("All resource types").click();
Copy link
Member

Choose a reason for hiding this comment

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

Not fully sure what element this is, but could the selector be updated to have alink/button role, since whatever it is, it looks like something that can be interacted with?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

there are multiple buttons on the page though. those roles would be ambiguous.

await page.getByRole("menu").getByText("Workspace Build").click();
Copy link
Member

Choose a reason for hiding this comment

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

Could this be turned into

awaitpage.getByRole("menu",{name:"Workspace Build"}).click();

?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

no, this is descending into the menu, and getting by text inside of it to click a specific option. that would just get the whole menu.

// Our workspace build should be visible
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 filter").click();
await expect(page.getByText(startedWorkspaceMessage)).toBeVisible();
await expect(page.getByText(loginMessage)).toBeVisible();

// Filter by action type
await page.getByText("All actions").click();
Copy link
Member

@ParkreinerParkreinerApr 11, 2024
edited
Loading

Choose a reason for hiding this comment

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

Same comment as above, since this is some kind of interactive element

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

we could addtestids to them, but tbh I kinda hate those 😅 if you'd prefer that tho, we use them all over the place and I cope

await page.getByRole("menu").getByText("Login").click();
// Logins should be visible
await expect(page.getByText(loginMessage)).toBeVisible();
// Our workspace build should no longer be visible
await expect(page.getByText(startedWorkspaceMessage)).not.toBeVisible();
});
2 changes: 1 addition & 1 deletionsite/e2e/tests/createWorkspace.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@ import {
} from "../parameters";
import type { RichParameter } from "../provisionerGenerated";

test.beforeEach(async({ page }) => await beforeCoderTest(page));
test.beforeEach(({ page }) => beforeCoderTest(page));

test("create workspace", async ({ page }) => {
const template = await createTemplate(page, {
Expand Down
2 changes: 1 addition & 1 deletionsite/e2e/tests/externalAuth.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ import { gitAuth } from "../constants";
import { Awaiter, createServer } from "../helpers";
import { beforeCoderTest } from "../hooks";

test.beforeEach(async({ page }) => await beforeCoderTest(page));
test.beforeEach(({ page }) => beforeCoderTest(page));

// Ensures that a Git auth provider with the device flow functions and completes!
test("external auth device", async ({ page }) => {
Expand Down
2 changes: 1 addition & 1 deletionsite/e2e/tests/listTemplates.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import { test, expect } from "@playwright/test";
import { beforeCoderTest } from "../hooks";

test.beforeEach(async({ page }) => await beforeCoderTest(page));
test.beforeEach(({ page }) => beforeCoderTest(page));

test("list templates", async ({ page, baseURL }) => {
await page.goto(`${baseURL}/templates`, { waitUntil: "domcontentloaded" });
Expand Down
2 changes: 1 addition & 1 deletionsite/e2e/tests/outdatedAgent.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ import { beforeCoderTest } from "../hooks";
// we no longer support versions prior to single tailnet: https://github.com/coder/coder/commit/d7cbdbd9c64ad26821e6b35834c59ecf85dcd9d4
const agentVersion = "v0.27.0";

test.beforeEach(async({ page }) => await beforeCoderTest(page));
test.beforeEach(({ page }) => beforeCoderTest(page));

test("ssh with agent " + agentVersion, async ({ page }) => {
const token = randomUUID();
Expand Down
2 changes: 1 addition & 1 deletionsite/e2e/tests/outdatedCLI.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ import { beforeCoderTest } from "../hooks";
// we no longer support versions prior to single tailnet: https://github.com/coder/coder/commit/d7cbdbd9c64ad26821e6b35834c59ecf85dcd9d4
const clientVersion = "v0.27.0";

test.beforeEach(async({ page }) => await beforeCoderTest(page));
test.beforeEach(({ page }) => beforeCoderTest(page));

test("ssh with client " + clientVersion, async ({ page }) => {
const token = randomUUID();
Expand Down
2 changes: 1 addition & 1 deletionsite/e2e/tests/restartWorkspace.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,7 @@ import { beforeCoderTest } from "../hooks";
import { firstBuildOption, secondBuildOption } from "../parameters";
import type { RichParameter } from "../provisionerGenerated";

test.beforeEach(async({ page }) => await beforeCoderTest(page));
test.beforeEach(({ page }) => beforeCoderTest(page));

test("restart workspace with ephemeral parameters", async ({ page }) => {
const richParameters: RichParameter[] = [firstBuildOption, secondBuildOption];
Expand Down
3 changes: 3 additions & 0 deletionssite/e2e/tests/startWorkspace.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,9 +7,12 @@ import {
stopWorkspace,
verifyParameters,
} from "../helpers";
import { beforeCoderTest } from "../hooks";
import { firstBuildOption, secondBuildOption } from "../parameters";
import type { RichParameter } from "../provisionerGenerated";

test.beforeEach(({ page }) => beforeCoderTest(page));

test("start workspace with ephemeral parameters", async ({ page }) => {
const richParameters: RichParameter[] = [firstBuildOption, secondBuildOption];
const template = await createTemplate(
Expand Down
3 changes: 3 additions & 0 deletionssite/e2e/tests/updateTemplate.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,9 @@ import {
requiresEnterpriseLicense,
updateTemplateSettings,
} from "../helpers";
import { beforeCoderTest } from "../hooks";

test.beforeEach(({ page }) => beforeCoderTest(page));

test("template update with new name redirects on successful submit", async ({
page,
Expand Down
2 changes: 1 addition & 1 deletionsite/e2e/tests/updateWorkspace.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@ import {
} from "../parameters";
import type { RichParameter } from "../provisionerGenerated";

test.beforeEach(async({ page }) => await beforeCoderTest(page));
test.beforeEach(({ page }) => beforeCoderTest(page));

test("update workspace, new optional, immutable parameter added", async ({
page,
Expand Down
2 changes: 1 addition & 1 deletionsite/e2e/tests/webTerminal.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ import {
} from "../helpers";
import { beforeCoderTest } from "../hooks";

test.beforeEach(async({ page }) => await beforeCoderTest(page));
test.beforeEach(({ page }) => beforeCoderTest(page));

test("web terminal", async ({ context, page }) => {
const token = randomUUID();
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp