Skip to content

Commit b457c8a

Browse files
authored
Merge pull request #19538 from mozilla/FXA-12631
bug(settings): Make sure session is verified before starting key stretching upgrade
2 parents 330a6f7 + 7f39670 commit b457c8a

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

packages/fxa-settings/src/pages/Signin/SigninTotpCode/container.test.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ import { renderWithLocalizationProvider } from 'fxa-react/lib/test-utils/localiz
2020
import SigninTotpCodeContainer from './container';
2121
import { MozServices } from '../../../lib/types';
2222
import { createMockWebIntegration } from '../SigninTokenCode/mocks';
23-
import { Integration, useSensitiveDataClient } from '../../../models';
23+
import {
24+
Integration,
25+
useSensitiveDataClient,
26+
useSession,
27+
} from '../../../models';
2428
import { mockSensitiveDataClient as createMockSensitiveDataClient } from '../../../models/mocks';
2529

2630
import {
@@ -72,6 +76,7 @@ jest.mock('../../../models', () => {
7276
...jest.requireActual('../../../models'),
7377
useAuthClient: jest.fn(),
7478
useSensitiveDataClient: jest.fn(),
79+
useSession: jest.fn(),
7580
};
7681
});
7782

@@ -146,6 +151,16 @@ function resetMockSensitiveDataClient() {
146151
);
147152
}
148153

154+
function mockSession() {
155+
(useSession as jest.Mock).mockImplementation(() => {
156+
return {
157+
isSessionVerified: () => {
158+
return Promise.resolve(true);
159+
},
160+
};
161+
});
162+
}
163+
149164
function applyDefaultMocks() {
150165
jest.resetAllMocks();
151166
jest.restoreAllMocks();
@@ -158,6 +173,7 @@ function applyDefaultMocks() {
158173
mockVerifyTotp();
159174
mockWebIntegration();
160175
resetMockSensitiveDataClient();
176+
mockSession();
161177
}
162178

163179
describe('signin totp code container', () => {

packages/fxa-settings/src/pages/Signin/SigninTotpCode/container.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
isWebIntegration,
2424
useAuthClient,
2525
useSensitiveDataClient,
26+
useSession,
2627
} from '../../../models';
2728
import {
2829
useFinishOAuthFlowHandler,
@@ -54,6 +55,8 @@ export const SigninTotpCodeContainer = ({
5455
serviceName,
5556
}: SigninTotpCodeContainerProps & RouteComponentProps) => {
5657
const authClient = useAuthClient();
58+
const session = useSession();
59+
5760
const { finishOAuthFlowHandler, oAuthDataError } = useFinishOAuthFlowHandler(
5861
authClient,
5962
integration
@@ -133,7 +136,7 @@ export const SigninTotpCodeContainer = ({
133136
// can only be finished after the account has been verified on accounts that
134137
// require totp.
135138
const sessionToken = signinState?.sessionToken;
136-
if (sessionToken) {
139+
if (sessionToken && (await session.isSessionVerified())) {
137140
await tryFinalizeUpgrade(
138141
sessionToken,
139142
sensitiveDataClient,

0 commit comments

Comments
 (0)