-
Notifications
You must be signed in to change notification settings - Fork 206
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add E2E tests for silent authentication #5150
base: main
Are you sure you want to change the base?
Changes from 8 commits
f7163a8
8bc9e46
0e6d065
4ae7859
0243bbf
f3f533c
032032f
9efbaec
c1df6ca
431b289
44e5826
93efd14
58453fd
e62b3be
8b4f65d
e9fee2c
7f3feea
66644b6
9769e0a
0d3493d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -71,4 +71,34 @@ | |||||||||||
expect(verificationCode).toBeDefined(); | ||||||||||||
await this.enterVerificationCode(verificationCode as string); | ||||||||||||
} | ||||||||||||
|
||||||||||||
async signInToFxA(email: string, password: string) { | ||||||||||||
await this.page.goto(process.env.FXA_SETTINGS_URL as string); | ||||||||||||
await this.page.context().clearCookies(); | ||||||||||||
await this.page | ||||||||||||
.locator("//input[@type='password'] | //div/input[@type='email']") | ||||||||||||
.waitFor({ state: "visible" }); | ||||||||||||
const visible = await this.useDifferentEmailButton.isVisible(); | ||||||||||||
if (visible) { | ||||||||||||
await this.useDifferentEmailButton.click(); | ||||||||||||
await this.page.waitForURL(/^(?!.*signin).*/); | ||||||||||||
} | ||||||||||||
|
||||||||||||
// enter email | ||||||||||||
await this.emailInputField.fill(email); | ||||||||||||
await this.continueButton.click(); | ||||||||||||
await this.page.waitForURL(/^(?!.*signin).*/); | ||||||||||||
|
||||||||||||
// enter password | ||||||||||||
await this.passwordInputField.fill(password); | ||||||||||||
await this.continue({ waitForURL: process.env.FXA_SETTINGS_URL }); | ||||||||||||
} | ||||||||||||
|
||||||||||||
async initSilentAuth() { | ||||||||||||
await this.page.goto( | ||||||||||||
`${process.env.E2E_TEST_BASE_URL as string}/?feature_flags=PromptNoneAuthFlow&utm_source=moz-account&utm_campaign=settings-promo&utm_content=monitor-free`, | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So as per my other comment, this would be:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Update in 7f3feea. |
||||||||||||
); | ||||||||||||
// FxA can take a while to load on stage: | ||||||||||||
await this.page.waitForURL("**/oauth/**"); | ||||||||||||
Check failure on line 102 in src/e2e/pages/authPage.ts GitHub Actions / e2e-tests-full[chromium] › auth.spec.ts:72:3 › local - Authentication flow verification @smoke › Verify successful silent authentication with existing user
Check failure on line 102 in src/e2e/pages/authPage.ts GitHub Actions / e2e-tests-full[chromium] › auth.spec.ts:72:3 › local - Authentication flow verification @smoke › Verify successful silent authentication with existing user
Check failure on line 102 in src/e2e/pages/authPage.ts GitHub Actions / e2e-tests-full[chromium] › auth.spec.ts:104:3 › local - Authentication flow verification @smoke › Verify failed silent authentication with existing user
Check failure on line 102 in src/e2e/pages/authPage.ts GitHub Actions / e2e-tests-full[chromium] › auth.spec.ts:104:3 › local - Authentication flow verification @smoke › Verify failed silent authentication with existing user
Check failure on line 102 in src/e2e/pages/authPage.ts GitHub Actions / e2e-tests-smoke[chromium] › auth.spec.ts:72:3 › local - Authentication flow verification @smoke › Verify successful silent authentication with existing user
Check failure on line 102 in src/e2e/pages/authPage.ts GitHub Actions / e2e-tests-smoke[chromium] › auth.spec.ts:72:3 › local - Authentication flow verification @smoke › Verify successful silent authentication with existing user
Check failure on line 102 in src/e2e/pages/authPage.ts GitHub Actions / e2e-tests-smoke[chromium] › auth.spec.ts:104:3 › local - Authentication flow verification @smoke › Verify failed silent authentication with existing user
Check failure on line 102 in src/e2e/pages/authPage.ts GitHub Actions / e2e-tests-smoke[chromium] › auth.spec.ts:104:3 › local - Authentication flow verification @smoke › Verify failed silent authentication with existing user
|
||||||||||||
} | ||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
Check failure on line 1 in src/e2e/specs/auth.spec.ts GitHub Actions / e2e-tests-full[chromium] › auth.spec.ts:72:3 › local - Authentication flow verification @smoke › Verify successful silent authentication with existing user
Check failure on line 1 in src/e2e/specs/auth.spec.ts GitHub Actions / e2e-tests-full[chromium] › auth.spec.ts:72:3 › local - Authentication flow verification @smoke › Verify successful silent authentication with existing user
Check failure on line 1 in src/e2e/specs/auth.spec.ts GitHub Actions / e2e-tests-full[chromium] › auth.spec.ts:104:3 › local - Authentication flow verification @smoke › Verify failed silent authentication with existing user
Check failure on line 1 in src/e2e/specs/auth.spec.ts GitHub Actions / e2e-tests-full[chromium] › auth.spec.ts:104:3 › local - Authentication flow verification @smoke › Verify failed silent authentication with existing user
Check failure on line 1 in src/e2e/specs/auth.spec.ts GitHub Actions / e2e-tests-smoke[chromium] › auth.spec.ts:72:3 › local - Authentication flow verification @smoke › Verify successful silent authentication with existing user
Check failure on line 1 in src/e2e/specs/auth.spec.ts GitHub Actions / e2e-tests-smoke[chromium] › auth.spec.ts:72:3 › local - Authentication flow verification @smoke › Verify successful silent authentication with existing user
Check failure on line 1 in src/e2e/specs/auth.spec.ts GitHub Actions / e2e-tests-smoke[chromium] › auth.spec.ts:104:3 › local - Authentication flow verification @smoke › Verify failed silent authentication with existing user
Check failure on line 1 in src/e2e/specs/auth.spec.ts GitHub Actions / e2e-tests-smoke[chromium] › auth.spec.ts:104:3 › local - Authentication flow verification @smoke › Verify failed silent authentication with existing user
|
||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
|
@@ -45,7 +45,7 @@ | |
landingPage, | ||
dashboardPage, | ||
}, testInfo) => { | ||
// speed up test by ignore non necessary requests | ||
// speed up test by ignoring non-necessary requests | ||
await page.route(/(analytics)/, async (route) => { | ||
await route.abort(); | ||
}); | ||
|
@@ -57,7 +57,7 @@ | |
await authPage.signIn(process.env.E2E_TEST_ACCOUNT_EMAIL as string); | ||
|
||
// assert successful login | ||
await expect(dashboardPage.fixedTab).toBeVisible(); | ||
Check failure on line 60 in src/e2e/specs/auth.spec.ts GitHub Actions / e2e-tests-full[chromium] › auth.spec.ts:42:3 › local - Authentication flow verification @smoke › Verify sign in with existing user
Check failure on line 60 in src/e2e/specs/auth.spec.ts GitHub Actions / e2e-tests-full[chromium] › auth.spec.ts:42:3 › local - Authentication flow verification @smoke › Verify sign in with existing user
Check failure on line 60 in src/e2e/specs/auth.spec.ts GitHub Actions / e2e-tests-smoke[chromium] › auth.spec.ts:42:3 › local - Authentication flow verification @smoke › Verify sign in with existing user
Check failure on line 60 in src/e2e/specs/auth.spec.ts GitHub Actions / e2e-tests-smoke[chromium] › auth.spec.ts:42:3 › local - Authentication flow verification @smoke › Verify sign in with existing user
|
||
await expect(dashboardPage.actionNeededTab).toBeVisible(); | ||
|
||
await testInfo.attach( | ||
|
@@ -68,4 +68,65 @@ | |
}, | ||
); | ||
}); | ||
|
||
test("Verify successful silent authentication with existing user", async ({ | ||
page, | ||
authPage, | ||
dashboardPage, | ||
}, testInfo) => { | ||
// speed up test by ignoring non-necessary requests | ||
await page.route(/(analytics)/, async (route) => { | ||
await route.abort(); | ||
}); | ||
|
||
// login to FxA | ||
await authPage.signInToFxA( | ||
process.env.E2E_TEST_ACCOUNT_EMAIL as string, | ||
process.env.E2E_TEST_ACCOUNT_PASSWORD as string, | ||
); | ||
|
||
// start authentication flow | ||
await authPage.initSilentAuth(); | ||
|
||
// assert successful login | ||
await expect(dashboardPage.fixedTab).toBeVisible(); | ||
await expect(dashboardPage.actionNeededTab).toBeVisible(); | ||
|
||
await testInfo.attach( | ||
`${process.env.E2E_TEST_ENV}-silent-authentication-monitor-dashboard.png`, | ||
{ | ||
body: await page.screenshot(), | ||
contentType: "image/png", | ||
}, | ||
); | ||
}); | ||
|
||
test("Verify failed silent authentication with existing user", async ({ | ||
page, | ||
authPage, | ||
dashboardPage, | ||
}, testInfo) => { | ||
// speed up test by ignoring non-necessary requests | ||
await page.route(/(analytics)/, async (route) => { | ||
await route.abort(); | ||
}); | ||
|
||
// start authentication flow | ||
await authPage.initSilentAuth(); | ||
|
||
// sign in | ||
await authPage.signIn(process.env.E2E_TEST_ACCOUNT_EMAIL as string); | ||
|
||
// assert successful login | ||
await expect(dashboardPage.fixedTab).toBeVisible(); | ||
await expect(dashboardPage.actionNeededTab).toBeVisible(); | ||
|
||
await testInfo.attach( | ||
`${process.env.E2E_TEST_ENV}-silent-authentication-monitor-dashboard.png`, | ||
{ | ||
body: await page.screenshot(), | ||
contentType: "image/png", | ||
}, | ||
); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,13 @@ export function middleware(request: NextRequest) { | |
|
||
const requestHeaders = new Headers(request.headers); | ||
requestHeaders.set("x-nonce", nonce); | ||
|
||
if (process.env.E2E_TEST_ENV === "local") { | ||
const forcedFeatureFlags = | ||
request.nextUrl.searchParams.get("feature_flags"); | ||
requestHeaders.set("x-forced-feature-flags", forcedFeatureFlags ?? ""); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of adding runtime middleware code, we could also skip that and just directly call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah — a lot better: 7f3feea. |
||
// Add the CSP to the request headers - that will make Next.js detect it and | ||
// add it to the inline `<script>` tags that it injects itself, as per | ||
// https://github.com/vercel/next.js/discussions/51039#discussioncomment-6596642 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me (because I'm not terribly familiar with our existing e2e tests) why this extra method is needed - don't we already have methods to sign in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is for logging explicitly in to the Monitor Accounts application and not Monitor.