Skip to content
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

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft

Add E2E tests for silent authentication #5150

wants to merge 20 commits into from

Conversation

flozia
Copy link
Collaborator

@flozia flozia commented Oct 9, 2024

References:

PR #5104

Description

This PR adds E2E tests for the silent authentication flow.

Copy link

github-actions bot commented Oct 9, 2024

@flozia flozia self-assigned this Oct 9, 2024
@@ -12,6 +12,13 @@ export function middleware(request: NextRequest) {

const requestHeaders = new Headers(request.headers);
requestHeaders.set("x-nonce", nonce);

if (typeof process.env.E2E_TEST_ENV !== "undefined") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm worried that if this env var is set somehow in stage or prod, we would have this feature flag forced?

Would it be better to have more guards like && not in prod && not in stage?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was thinking about this as well and had the condition first only to check for process.env.E2E_TEST_ENV === "local". Now you are mentioning it: Yes, let’s play it safe — changed in 4ae7859.

Base automatically changed from mntor-3492 to main October 10, 2024 13:05
Copy link
Collaborator

@Vinnl Vinnl left a comment

Choose a reason for hiding this comment

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

The feature flag override looks good to me, and overall the code looks good too (just a question and an ignorable suggestion). However... The tests appear to fail now in CI?

@@ -71,4 +71,34 @@ export class AuthPage {
expect(verificationCode).toBeDefined();
await this.enterVerificationCode(verificationCode as string);
}

async signInToFxA(email: string, password: string) {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Comment on lines 15 to 21

if (process.env.E2E_TEST_ENV === "local") {
const forcedFeatureFlags =
request.nextUrl.searchParams.get("feature_flags");
requestHeaders.set("x-forced-feature-flags", forcedFeatureFlags ?? "");
}

Copy link
Collaborator

Choose a reason for hiding this comment

The 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 .setExtraHTTPHeaders, I think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh yeah — a lot better: 7f3feea.

Comment on lines 98 to 99
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`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

So as per my other comment, this would be:

Suggested change
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`,
await this.page.setExtraHTTPHeaders({ "x-forced-feature-flags": "PromptNoneAuthFlow" });
await this.page.goto(
`${process.env.E2E_TEST_BASE_URL as string}/?utm_source=moz-account&utm_campaign=settings-promo&utm_content=monitor-free`,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! Update in 7f3feea.

Copy link

Copy link

Copy link

Copy link

@flozia flozia added the 🛑 Do Not Merge Do not merge this PR, even if approved. label Oct 28, 2024
@flozia
Copy link
Collaborator Author

flozia commented Oct 28, 2024

There seems to be an issue with the test accounts set up for the E2E tests. When attempting to sign-in to FxA directly rather than via OAuth it results in an application error. The issue is filed under FXA-10631.

Copy link

@flozia
Copy link
Collaborator Author

flozia commented Oct 30, 2024

The feature flag override looks good to me, and overall the code looks good too (just a question and an ignorable suggestion). However... The tests appear to fail now in CI?

@Vinnl The tests are were passing again. An issue with the account prevented us from logging into Mozilla Accounts.

@flozia flozia requested review from Vinnl and mansaj October 30, 2024 16:33
@flozia flozia removed the 🛑 Do Not Merge Do not merge this PR, even if approved. label Oct 30, 2024
Copy link

1 similar comment
Copy link

Copy link

Copy link

@flozia flozia added the 🛑 Do Not Merge Do not merge this PR, even if approved. label Oct 31, 2024
@flozia flozia marked this pull request as draft October 31, 2024 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛑 Do Not Merge Do not merge this PR, even if approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants