From 3fe66a27f4ca7139b8012644eca2f9d1cf225885 Mon Sep 17 00:00:00 2001 From: Lauren Zugai Date: Tue, 8 Oct 2024 09:53:33 -0500 Subject: [PATCH] fix(oauth-desktop): Send canLinkAccount if service=sync Because: * We were only checking for desktopv3 in this case and want to check for desktopv3 and oauth desktop This commit: * Modifies the condition to call firefox.fxaCanLinkAccount, updates tests fixes FXA-10328 --- .../app/scripts/models/reliers/oauth.js | 5 +++- .../src/pages/Signin/container.test.tsx | 26 ++++++++++++++++--- .../src/pages/Signin/container.tsx | 5 ++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/packages/fxa-content-server/app/scripts/models/reliers/oauth.js b/packages/fxa-content-server/app/scripts/models/reliers/oauth.js index 213a91809fa..a41c6870116 100644 --- a/packages/fxa-content-server/app/scripts/models/reliers/oauth.js +++ b/packages/fxa-content-server/app/scripts/models/reliers/oauth.js @@ -218,7 +218,10 @@ var OAuthRelier = Relier.extend({ // OAuth reliers are not allowed to specify a service. `service` // is used in the verification flow, it'll be set to the `client_id`. - if (this.getSearchParam('service')) { + if ( + this.getSearchParam('service') && + this.getSearchParam('service') !== 'sync' + ) { throw OAuthErrors.toInvalidParameterError('service'); } }, diff --git a/packages/fxa-settings/src/pages/Signin/container.test.tsx b/packages/fxa-settings/src/pages/Signin/container.test.tsx index e76c4568463..7494666a2ac 100644 --- a/packages/fxa-settings/src/pages/Signin/container.test.tsx +++ b/packages/fxa-settings/src/pages/Signin/container.test.tsx @@ -71,14 +71,18 @@ function mockSyncDesktopV3Integration() { getService: () => 'sync', isSync: () => true, wantsKeys: () => true, + data: { service: 'sync' }, } as Integration; } -function mockSyncOAuthIntegration() { +function mockSyncOAuthIntegration( + { data }: { data?: { service?: string } } = { data: { service: 'sync' } } +) { integration = { type: IntegrationType.OAuth, getService: () => 'sync', isSync: () => true, wantsKeys: () => true, + data, } as Integration; } @@ -88,6 +92,7 @@ function mockWebIntegration() { getService: () => MozServices.Default, isSync: () => false, wantsKeys: () => false, + data: {}, } as Integration; } @@ -617,9 +622,24 @@ describe('signin container', () => { }); }); it('is not called when conditions are not met (oauth integration)', async () => { + mockSyncOAuthIntegration({ data: {} }); + (firefox.fxaCanLinkAccount as jest.Mock).mockImplementationOnce( + async () => ({ + ok: true, + }) + ); + render([mockGqlAvatarUseQuery()]); + + await waitFor(async () => { + await currentSigninProps?.beginSigninHandler( + MOCK_EMAIL, + MOCK_PASSWORD + ); + expect(firefox.fxaCanLinkAccount).not.toHaveBeenCalled(); + }); + }); + it('calls fxaCanLinkAccount when conditions are met (oauth integration)', async () => { mockSyncOAuthIntegration(); - // TODO: when desktop moves to oauth, we must update this logic and test - mockUseValidateModule(); (firefox.fxaCanLinkAccount as jest.Mock).mockImplementationOnce( async () => ({ ok: true, diff --git a/packages/fxa-settings/src/pages/Signin/container.tsx b/packages/fxa-settings/src/pages/Signin/container.tsx index adbefdd16a8..455abd58cdc 100644 --- a/packages/fxa-settings/src/pages/Signin/container.tsx +++ b/packages/fxa-settings/src/pages/Signin/container.tsx @@ -10,7 +10,6 @@ import { useFtlMsgResolver, useConfig, useSession, - isSyncDesktopV3Integration, useSensitiveDataClient, } from '../../models'; import { MozServices } from '../../lib/types'; @@ -242,7 +241,9 @@ const SigninContainer = ({ // warning. The browser will automatically respond with { ok: true } without // prompting the user if it matches the email the browser has data for. if ( - isSyncDesktopV3Integration(integration) && + // NOTE, SYNC-4408 OAuth desktop needs to add `service=sync` as a query parameter + // for this to work for OAuth desktop + integration.data.service === 'sync' && queryParamModel.hasLinkedAccount === undefined ) { const { ok } = await firefox.fxaCanLinkAccount({ email });