100 lines
5.9 KiB
TypeScript
100 lines
5.9 KiB
TypeScript
import { expect, test } from "./utils/test";
|
|
import { expectNoCriticalA11yViolations } from "./utils/axe";
|
|
import { getTenantCredentials, loginAsTenantUser, tenantSettingsProfilePath } from "./utils/auth";
|
|
import { expectNoHorizontalOverflow, narrowMobileViewport } from "./utils/mobile";
|
|
import { escapeRegExp, interceptCurrentRoutePost, postDataIncludesField, skipIfUnavailable } from "./utils/navigation";
|
|
import { skipOrFailWhenE2eFixtureMissing, skipOrFailWhenE2eInputsMissing } from "./utils/readiness";
|
|
|
|
const credentials = getTenantCredentials();
|
|
const dashboardPath = process.env.E2E_TENANT_DASHBOARD_PATH;
|
|
const profilePath = process.env.E2E_TENANT_SETTINGS_PROFILE_PATH ?? (dashboardPath ? tenantSettingsProfilePath(dashboardPath) : undefined);
|
|
const securityPath = profilePath ? `${profilePath}/security` : undefined;
|
|
|
|
test.describe("profile security mobile a11y", () => {
|
|
test.use({ viewport: narrowMobileViewport, isMobile: true, hasTouch: true });
|
|
|
|
test.beforeEach(() => {
|
|
skipOrFailWhenE2eInputsMissing(
|
|
["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD", "E2E_TENANT_DASHBOARD_PATH"],
|
|
"Tenant profile security E2E inputs not configured"
|
|
);
|
|
if (!profilePath) {
|
|
skipOrFailWhenE2eFixtureMissing("Tenant profile path could not be derived; set E2E_TENANT_SETTINGS_PROFILE_PATH");
|
|
}
|
|
});
|
|
|
|
test("renders profile security dialogs and the dedicated session page on mobile", async ({ page }) => {
|
|
await loginAsTenantUser(page, credentials!);
|
|
|
|
const response = await page.goto(profilePath!, { waitUntil: "domcontentloaded" });
|
|
await skipIfUnavailable(page, response, `Tenant profile path ${profilePath}`);
|
|
|
|
await expect(page).toHaveURL(new RegExp(`${escapeRegExp(profilePath!)}(?:[?#].*)?$`, "u"));
|
|
await expect(page.locator('[data-ui-id="ui.settings.profile.page"]').first()).toBeVisible();
|
|
await expect(page.locator('[data-ui-id="ui.settings.profile.form"]').first()).toBeVisible();
|
|
const passwordOpen = page.locator('[data-ui-id="ui.settings.profile.password.open"]').first();
|
|
const mfaManage = page.locator('[data-ui-id="ui.settings.profile.mfa.manage"]').first();
|
|
await expect(passwordOpen).toBeVisible();
|
|
await expect(mfaManage).toBeVisible();
|
|
await passwordOpen.click();
|
|
await expect(page.locator('[data-ui-id="ui.settings.profile.password.modal"]').first()).toBeVisible();
|
|
await expectNoHorizontalOverflow(page);
|
|
await expectNoCriticalA11yViolations(page);
|
|
await page.locator('[data-ui-id="ui.settings.profile.password.close"]').first().click();
|
|
|
|
const securityResponse = await page.goto(securityPath!, { waitUntil: "domcontentloaded" });
|
|
await skipIfUnavailable(page, securityResponse, `Tenant security path ${securityPath}`);
|
|
await expect(page.locator('[data-ui-id="ui.settings.security.page"]').first()).toBeVisible();
|
|
await expect(page.locator('[data-ui-id="ui.settings.security.sessions"]').first()).toBeVisible();
|
|
await expectNoHorizontalOverflow(page);
|
|
await expectNoCriticalA11yViolations(page);
|
|
});
|
|
|
|
test("submits password change contract with csrf without mutating data", async ({ page }) => {
|
|
await loginAsTenantUser(page, credentials!);
|
|
|
|
const response = await page.goto(profilePath!, { waitUntil: "domcontentloaded" });
|
|
await skipIfUnavailable(page, response, `Tenant profile path ${profilePath}`);
|
|
|
|
await page.locator('[data-ui-id="ui.settings.profile.password.open"]').first().click();
|
|
const form = page.locator('[data-ui-id="ui.settings.profile.password.modal"] form').first();
|
|
await expect(form).toBeVisible();
|
|
await form.locator('[data-ui-id="ui.settings.profile.password.current"]').fill("current-password-for-contract");
|
|
await form.locator('[data-ui-id="ui.settings.profile.password.new"]').fill("NewPassword123!");
|
|
await form.locator('[data-ui-id="ui.settings.profile.password.confirm"]').fill("NewPassword123!");
|
|
|
|
const submitted = await interceptCurrentRoutePost(page, { status: 204 });
|
|
await form.locator('[data-ui-id="ui.settings.profile.password.submit"]').click();
|
|
|
|
await expect.poll(() => submitted.value).not.toBeNull();
|
|
expect(postDataIncludesField(submitted.value, "action", /^password$/u)).toBe(true);
|
|
expect(postDataIncludesField(submitted.value, "csrf", /.+/u)).toBe(true);
|
|
expect(postDataIncludesField(submitted.value, "passwordCurrent", /^current-password-for-contract$/u)).toBe(true);
|
|
expect(postDataIncludesField(submitted.value, "passwordNew", /^NewPassword123!$/u)).toBe(true);
|
|
expect(postDataIncludesField(submitted.value, "passwordNewConfirm", /^NewPassword123!$/u)).toBe(true);
|
|
});
|
|
|
|
test("submits MFA toggle contract with csrf without changing enrollment state", async ({ page }) => {
|
|
await loginAsTenantUser(page, credentials!);
|
|
|
|
const response = await page.goto(profilePath!, { waitUntil: "domcontentloaded" });
|
|
await skipIfUnavailable(page, response, `Tenant profile path ${profilePath}`);
|
|
|
|
await page.locator('[data-ui-id="ui.settings.profile.mfa.manage"]').first().click();
|
|
const form = page.locator('[data-ui-id="ui.settings.profile.mfa.gate"] form').first();
|
|
if ((await form.count()) === 0 || !(await form.isVisible())) {
|
|
skipOrFailWhenE2eFixtureMissing("Profile MFA password gate is not visible for this fixture");
|
|
}
|
|
await expect(form).toBeVisible();
|
|
await form.locator('[data-ui-id="ui.settings.profile.mfa.gatePassword"]').fill("current-password-for-contract");
|
|
|
|
const submitted = await interceptCurrentRoutePost(page, { status: 204 });
|
|
await form.locator('[data-ui-id="ui.settings.profile.mfa.gateSubmit"]').click();
|
|
|
|
await expect.poll(() => submitted.value).not.toBeNull();
|
|
expect(postDataIncludesField(submitted.value, "action", /^startTotpEnrollment$/u)).toBe(true);
|
|
expect(postDataIncludesField(submitted.value, "csrf", /.+/u)).toBe(true);
|
|
expect(postDataIncludesField(submitted.value, "passwordCurrent", /^current-password-for-contract$/u)).toBe(true);
|
|
});
|
|
});
|