Skip to content

Commit 7039b06

Browse files
committed
add data-cleanup, exclude-and-sanitize tests
1 parent 732f927 commit 7039b06

File tree

3 files changed

+188
-0
lines changed

3 files changed

+188
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { expect, test } from "@wordpress/e2e-test-utils-playwright";
2+
import {
3+
configureDataManagement,
4+
goToLoggingSettingsPage,
5+
resetPluginSettings,
6+
} from "../utils";
7+
8+
test.describe("Data Management - Configure Automatic Cleanup", () => {
9+
test.beforeEach(async ({ admin }) => {
10+
await resetPluginSettings(admin);
11+
});
12+
13+
test("should configure data deletion settings and verify they are saved", async ({
14+
page,
15+
admin,
16+
}) => {
17+
// Set up logging settings
18+
await goToLoggingSettingsPage(admin);
19+
await expect(page.locator("h1")).toHaveText("WPGraphQL Logging Settings");
20+
21+
await configureDataManagement(page, {
22+
dataDeletionEnabled: true,
23+
dataRetentionDays: "7",
24+
dataSanitizationEnabled: false,
25+
});
26+
27+
await expect(page.locator(".notice.notice-success")).toBeVisible();
28+
29+
// Reload the page to verify settings persisted
30+
await page.reload({ waitUntil: "networkidle" });
31+
32+
await page
33+
.locator("#wpbody-content")
34+
.getByRole("link", { name: "Data Management" })
35+
.click();
36+
37+
const deletionCheckbox = page.locator(
38+
'input[name="wpgraphql_logging_settings[data_management][data_deletion_enabled]"]'
39+
);
40+
await expect(deletionCheckbox).toBeChecked();
41+
42+
const retentionInput = page.locator(
43+
'input[name="wpgraphql_logging_settings[data_management][data_retention_days]"]'
44+
);
45+
await expect(retentionInput).toHaveValue("7");
46+
47+
// Verify cron job is scheduled with wp-crontrol plugin
48+
await admin.visitAdminPage("/tools.php?page=wp-crontrol");
49+
await expect(page.locator("h1")).toContainText("Cron Events");
50+
51+
const cleanupHook = page
52+
.locator(".crontrol_hook")
53+
.filter({ hasText: "wpgraphql_logging_deletion_cleanup" });
54+
55+
await expect(cleanupHook).toBeVisible();
56+
});
57+
});
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { expect, test } from "@wordpress/e2e-test-utils-playwright";
2+
import {
3+
goToLoggingSettingsPage,
4+
goToLogsListPage,
5+
configureLogging,
6+
executeGraphQLQuery,
7+
resetPluginSettings,
8+
} from "../utils";
9+
import { GET_POSTS_QUERY } from "../constants";
10+
11+
test.describe("Exclude Sensitive Queries from Logging", () => {
12+
test.beforeEach(async ({ admin }) => {
13+
await resetPluginSettings(admin);
14+
});
15+
16+
test("should exclude queries from logs when configured", async ({
17+
page,
18+
admin,
19+
request,
20+
}) => {
21+
// Set up logging with GetPosts excluded
22+
await goToLoggingSettingsPage(admin);
23+
await expect(page.locator("h1")).toHaveText("WPGraphQL Logging Settings");
24+
25+
await configureLogging(page, {
26+
enabled: true,
27+
dataSampling: "100",
28+
eventLogSelection: ["graphql_request_results"],
29+
excludeQueries: "GetPosts",
30+
});
31+
32+
await expect(page.locator(".notice.notice-success")).toBeVisible();
33+
34+
// Execute the excluded query
35+
const response = await executeGraphQLQuery(request, GET_POSTS_QUERY);
36+
expect(response.ok()).toBeTruthy();
37+
38+
// Verify query is not logged
39+
await goToLogsListPage(admin);
40+
await expect(page.locator("h1")).toContainText("WPGraphQL Logs");
41+
42+
await expect(
43+
page.locator('td.colspanchange:has-text("No items found.")')
44+
).toBeVisible();
45+
});
46+
47+
test("should log queries when not excluded", async ({
48+
page,
49+
admin,
50+
request,
51+
}) => {
52+
// Set up logging without excluded queries
53+
await goToLoggingSettingsPage(admin);
54+
55+
await configureLogging(page, {
56+
enabled: true,
57+
dataSampling: "100",
58+
eventLogSelection: ["graphql_request_results"],
59+
excludeQueries: "",
60+
});
61+
62+
await expect(page.locator(".notice.notice-success")).toBeVisible();
63+
64+
// Execute query
65+
await executeGraphQLQuery(request, GET_POSTS_QUERY);
66+
67+
// Navigate to logs and verify query is logged
68+
await goToLogsListPage(admin);
69+
await expect(page.locator("h1")).toContainText("WPGraphQL Logs");
70+
71+
// Verify GetPosts query is logged
72+
const getPostsLog = page
73+
.locator("#the-list tr")
74+
.filter({ hasText: "GetPosts" });
75+
await expect(getPostsLog).toBeVisible({ timeout: 10000 });
76+
});
77+
78+
// TODO add sanitization tests here
79+
});

plugins/wpgraphql-logging/tests/e2e/utils.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,55 @@ export async function getLogDetails(page, logId) {
129129

130130
return details;
131131
}
132+
133+
/**
134+
* Configure data management settings
135+
*/
136+
export async function configureDataManagement(page, settings = {}) {
137+
const {
138+
dataDeletionEnabled = false,
139+
dataRetentionDays = "30",
140+
dataSanitizationEnabled = false,
141+
dataSanitizationMethod = "recommended",
142+
} = settings;
143+
144+
// Switch to Data Management tab
145+
await switchToSettingsTab(page, "Data Management");
146+
147+
// Enable/disable data deletion
148+
const deletionCheckbox = page.locator(
149+
'input[name="wpgraphql_logging_settings[data_management][data_deletion_enabled]"]'
150+
);
151+
if (dataDeletionEnabled) {
152+
await deletionCheckbox.check();
153+
} else {
154+
await deletionCheckbox.uncheck();
155+
}
156+
157+
// Set data retention days
158+
await page
159+
.locator(
160+
'input[name="wpgraphql_logging_settings[data_management][data_retention_days]"]'
161+
)
162+
.fill(dataRetentionDays);
163+
164+
// Enable/disable data sanitization
165+
const sanitizationCheckbox = page.locator(
166+
'input[name="wpgraphql_logging_settings[data_management][data_sanitization_enabled]"]'
167+
);
168+
if (dataSanitizationEnabled) {
169+
await sanitizationCheckbox.check();
170+
} else {
171+
await sanitizationCheckbox.uncheck();
172+
}
173+
174+
// Set sanitization method
175+
await page
176+
.locator(
177+
'select[name="wpgraphql_logging_settings[data_management][data_sanitization_method]"]'
178+
)
179+
.selectOption(dataSanitizationMethod);
180+
181+
await page.getByRole("button", { name: "Save Changes" }).click();
182+
await page.waitForSelector(".notice.notice-success");
183+
}

0 commit comments

Comments
 (0)