Skip to content

Commit

Permalink
fix(oauth-desktop): Send canLinkAccount if service=sync
Browse files Browse the repository at this point in the history
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
  • Loading branch information
LZoog committed Oct 9, 2024
1 parent a3c4432 commit 3fe66a2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
},
Expand Down
26 changes: 23 additions & 3 deletions packages/fxa-settings/src/pages/Signin/container.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -88,6 +92,7 @@ function mockWebIntegration() {
getService: () => MozServices.Default,
isSync: () => false,
wantsKeys: () => false,
data: {},
} as Integration;
}

Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions packages/fxa-settings/src/pages/Signin/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
useFtlMsgResolver,
useConfig,
useSession,
isSyncDesktopV3Integration,
useSensitiveDataClient,
} from '../../models';
import { MozServices } from '../../lib/types';
Expand Down Expand Up @@ -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 });
Expand Down

0 comments on commit 3fe66a2

Please sign in to comment.