-
Notifications
You must be signed in to change notification settings - Fork 230
feat(auth): password verification for Sync after passkey signin #20571
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
Open
vbudhram
wants to merge
1
commit into
main
Choose a base branch
from
fxa-13096
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+725
−198
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
190 changes: 190 additions & 0 deletions
190
packages/functional-tests/tests/passkeys/passkeyPasswordFallback.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||
| * 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/. */ | ||
|
|
||
| // Browser-driven Sync passkey signin + password-fallback flow: enroll a | ||
| // passkey, simulate a new-device passkey ceremony via auth-client, seed the | ||
| // resulting session, then drive /signin_passkey_fallback from a fresh browser. | ||
|
|
||
| import { Page } from '@playwright/test'; | ||
| import { FirefoxCommand } from '../../lib/channels'; | ||
| import { expect, test } from '../../lib/fixtures/standard'; | ||
| import { syncDesktopOAuthQueryParams } from '../../lib/query-params'; | ||
| import { | ||
| VirtualAuthenticator, | ||
| VirtualCredential, | ||
| } from '../../../../libs/accounts/passkey/src/lib/virtual-authenticator'; | ||
| import { BaseTarget } from '../../lib/targets/base'; | ||
|
|
||
| async function seedAccountInLocalStorage( | ||
| page: Page, | ||
| args: { uid: string; sessionToken: string; email: string } | ||
| ) { | ||
| await page.evaluate(({ uid, sessionToken, email }) => { | ||
| const account = { uid, sessionToken, email, verified: true }; | ||
| window.localStorage.setItem( | ||
| '__fxa_storage.accounts', | ||
| JSON.stringify({ [uid]: account }) | ||
| ); | ||
| window.localStorage.setItem( | ||
| '__fxa_storage.currentAccountUid', | ||
| JSON.stringify(uid) | ||
| ); | ||
| }, args); | ||
| } | ||
|
|
||
| async function simulateNewDevicePasskeyAuth( | ||
| target: BaseTarget, | ||
| credential: VirtualCredential | ||
| ) { | ||
| const origin = target.contentServerUrl; | ||
| const rpId = new URL(target.contentServerUrl).hostname; | ||
| const authStart = await target.authClient.beginPasskeyAuthentication(); | ||
| const assertion = VirtualAuthenticator.createAssertionResponse(credential, { | ||
| challenge: authStart.challenge, | ||
| origin, | ||
| rpId, | ||
| }); | ||
| return target.authClient.completePasskeyAuthentication( | ||
| assertion as any, | ||
| authStart.challenge, | ||
| { service: 'sync' } | ||
| ); | ||
| } | ||
|
|
||
| test.describe('severity-1 #smoke', () => { | ||
| test.describe('Sync passkey signin with password fallback', () => { | ||
| test.beforeEach(async ({ pages: { configPage } }) => { | ||
| const config = await configPage.getConfig(); | ||
| test.skip( | ||
| !config.featureFlags?.passkeysEnabled || | ||
| !config.featureFlags?.passkeyRegistrationEnabled, | ||
| 'Passkey feature flags are not enabled' | ||
| ); | ||
| }); | ||
|
|
||
| test('full flow: enable passkey → fallback page submit signs into Sync', async ({ | ||
| target, | ||
| syncOAuthBrowserPages: { | ||
| page, | ||
| signin, | ||
| signinTokenCode, | ||
| settings, | ||
| settingsPasskeyAdd, | ||
| connectAnotherDevice, | ||
| }, | ||
| testAccountTracker, | ||
| }) => { | ||
| const { email, password } = await testAccountTracker.signUpSync(); | ||
|
|
||
| await signin.goto('/authorization', syncDesktopOAuthQueryParams); | ||
| await signin.fillOutEmailFirstForm(email); | ||
| await signin.fillOutPasswordForm(password); | ||
| await page.waitForURL(/signin_token_code/); | ||
| const tokenCode = await target.emailClient.getVerifyLoginCode(email); | ||
| await signinTokenCode.fillOutCodeForm(tokenCode); | ||
| await expect(connectAnotherDevice.fxaConnected).toBeVisible(); | ||
|
|
||
| await settings.goto(); | ||
| await expect(settings.settingsHeading).toBeVisible(); | ||
| await expect(settings.passkey.status).toHaveText('Not set'); | ||
|
|
||
| await settingsPasskeyAdd.initPasskeys(page); | ||
| await settingsPasskeyAdd.passkeyAuth.success(async () => { | ||
| await settings.passkey.createButton.click(); | ||
| await settings.confirmMfaGuard(email); | ||
| }); | ||
| await expect(settings.passkey.status).toHaveText('Enabled'); | ||
|
|
||
| const [credential] = | ||
| settingsPasskeyAdd.passkeyAuth.getCredentialObjects(); | ||
| const authFinish = await simulateNewDevicePasskeyAuth(target, credential); | ||
| expect(authFinish.requiresPasswordForSync).toBe(true); | ||
|
|
||
| // Simulate a fresh device so the fallback page hydrates from the seeded | ||
| // passkey session, not leftover state from the initial Sync OAuth flow. | ||
| await page.context().clearCookies(); | ||
|
Contributor
Author
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. This will need follow-up, but figured a net positive to have something exercising the flow end to end. The test simulates a verified passkey login, seeds the resulting session into localStorage, then signin_passkey_fallback from the browser. |
||
| await page.evaluate(() => { | ||
| localStorage.clear(); | ||
| sessionStorage.clear(); | ||
| }); | ||
| await seedAccountInLocalStorage(page, { | ||
| uid: authFinish.uid, | ||
| sessionToken: authFinish.sessionToken, | ||
| email, | ||
| }); | ||
|
|
||
| await page.goto( | ||
| `${target.contentServerUrl}/signin_passkey_fallback?${syncDesktopOAuthQueryParams}` | ||
| ); | ||
|
|
||
| await expect(page.getByTestId('passkey-fallback-email')).toHaveText( | ||
| ); | ||
|
|
||
| await page.getByTestId('password-input-field').fill(password); | ||
| await page.getByTestId('continue-button').click(); | ||
|
|
||
| await signin.checkWebChannelMessageScopes( | ||
| FirefoxCommand.OAuthLogin, | ||
| 'https://identity.mozilla.com/apps/oldsync' | ||
| ); | ||
| }); | ||
|
|
||
| test('shows an error banner when the password is wrong', async ({ | ||
| target, | ||
| syncOAuthBrowserPages: { | ||
| page, | ||
| signin, | ||
| signinTokenCode, | ||
| settings, | ||
| settingsPasskeyAdd, | ||
| connectAnotherDevice, | ||
| }, | ||
| testAccountTracker, | ||
| }) => { | ||
| const { email, password } = await testAccountTracker.signUpSync(); | ||
|
|
||
| await signin.goto('/authorization', syncDesktopOAuthQueryParams); | ||
| await signin.fillOutEmailFirstForm(email); | ||
| await signin.fillOutPasswordForm(password); | ||
| await page.waitForURL(/signin_token_code/); | ||
| const tokenCode = await target.emailClient.getVerifyLoginCode(email); | ||
| await signinTokenCode.fillOutCodeForm(tokenCode); | ||
| await expect(connectAnotherDevice.fxaConnected).toBeVisible(); | ||
|
|
||
| await settings.goto(); | ||
| await settingsPasskeyAdd.initPasskeys(page); | ||
| await settingsPasskeyAdd.passkeyAuth.success(async () => { | ||
| await settings.passkey.createButton.click(); | ||
| await settings.confirmMfaGuard(email); | ||
| }); | ||
| await expect(settings.passkey.status).toHaveText('Enabled'); | ||
|
|
||
| const [credential] = | ||
| settingsPasskeyAdd.passkeyAuth.getCredentialObjects(); | ||
| const authFinish = await simulateNewDevicePasskeyAuth(target, credential); | ||
|
|
||
| await page.context().clearCookies(); | ||
| await page.evaluate(() => { | ||
| localStorage.clear(); | ||
| sessionStorage.clear(); | ||
| }); | ||
| await seedAccountInLocalStorage(page, { | ||
| uid: authFinish.uid, | ||
| sessionToken: authFinish.sessionToken, | ||
| email, | ||
| }); | ||
|
|
||
| await page.goto( | ||
| `${target.contentServerUrl}/signin_passkey_fallback?${syncDesktopOAuthQueryParams}` | ||
| ); | ||
| await page | ||
| .getByTestId('password-input-field') | ||
| .fill('definitely-the-wrong-password'); | ||
| await page.getByTestId('continue-button').click(); | ||
|
|
||
| await expect(page.getByText(/password/i).first()).toBeVisible(); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: Could drop
as anyor use the actual typePublicKeyCredentialJSON