Skip to content

Commit 2b4662e

Browse files
authored
Merge pull request #2794 from govuk-one-login/AUT-4248/check-your-phone-sms-sms
Aut 4248/check your phone sms sms
2 parents bcab498 + ae08377 commit 2b4662e

33 files changed

Lines changed: 577 additions & 186 deletions

src/components/common/mfa/mfa-service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export function mfaService(axios: Http = http): MfaServiceInterface {
1919
isResendCodeRequest: boolean,
2020
userLanguage: string,
2121
req: Request,
22+
mfaMethodId: string,
2223
journeyType?: JOURNEY_TYPE
2324
): Promise<ApiResponseResult<DefaultApiResponse>> {
2425
const response = await axios.client.post<DefaultApiResponse>(
@@ -27,6 +28,7 @@ export function mfaService(axios: Http = http): MfaServiceInterface {
2728
email: emailAddress,
2829
isResendCodeRequest,
2930
journeyType,
31+
mfaMethodId,
3032
},
3133
getInternalRequestConfigWithSecurityHeaders(
3234
{

src/components/common/mfa/send-mfa-controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function sendMfaGeneric(
6969
mfaCodeService: MfaServiceInterface
7070
): ExpressRouteFunc {
7171
return async function (req: Request, res: Response) {
72-
const { email } = req.session.user;
72+
const { email, activeMfaMethodId } = req.session.user;
7373
const { sessionId, clientSessionId, persistentSessionId } = res.locals;
7474
const isResendCodeRequest: boolean = req.body.isResendCodeRequest;
7575

@@ -81,6 +81,7 @@ export function sendMfaGeneric(
8181
isResendCodeRequest,
8282
xss(req.cookies.lng as string),
8383
req,
84+
activeMfaMethodId,
8485
getJourneyTypeFromUserSession(req.session.user, {
8586
includeReauthentication: true,
8687
})

src/components/common/mfa/tests/mfa-service.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ describe("mfa service", () => {
4949
const userLanguage = "cy";
5050
const journeyType = JOURNEY_TYPE.SIGN_IN;
5151
const isResendCodeRequest = true;
52+
const mfaMethodId = "9b1deb4d-3b7d-4bad-9bdd-2b0d7a3a03d7";
5253

5354
const expectedApiCallDetails = {
5455
expectedPath: API_ENDPOINTS.MFA,
5556
expectedHeaders: {
5657
...expectedHeadersFromCommonVarsWithSecurityHeaders,
5758
"User-Language": userLanguage,
5859
},
59-
expectedBody: { email, isResendCodeRequest, journeyType },
60+
expectedBody: { email, isResendCodeRequest, journeyType, mfaMethodId },
6061
};
6162

6263
const result = await service.sendMfaCode(
@@ -67,6 +68,7 @@ describe("mfa service", () => {
6768
isResendCodeRequest,
6869
userLanguage,
6970
req,
71+
mfaMethodId,
7072
journeyType
7173
);
7274

src/components/common/mfa/tests/send-mfa-controller.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as journey from "../../journey/journey.js";
1212
import { createMockRequest } from "../../../../../test/helpers/mock-request-helper.js";
1313
import esmock from "esmock";
1414
import type { SinonSpy } from "sinon";
15-
import type { ExpressRouteFunc } from "../../../../types";
15+
import type { ExpressRouteFunc } from "../../../../types.js";
1616

1717
describe("send mfa controller", () => {
1818
let req: RequestOutput;
@@ -47,7 +47,7 @@ describe("send mfa controller", () => {
4747
});
4848

4949
describe("sendMfaGeneric", () => {
50-
it("can send the journeyType when requesting the code", async () => {
50+
it("can send the journeyType and activeMfaMethodId when requesting the code", async () => {
5151
const fakeService: MfaServiceInterface = {
5252
sendMfaCode: sinon.fake.returns({
5353
success: true,
@@ -58,6 +58,7 @@ describe("send mfa controller", () => {
5858
req.session.user = {
5959
email: "test@test.com",
6060
reauthenticate: "test_data",
61+
activeMfaMethodId: "active_mfa_method_id",
6162
};
6263
req.path = PATH_NAMES.RESEND_MFA_CODE;
6364

@@ -79,6 +80,7 @@ describe("send mfa controller", () => {
7980
sinon.match.any,
8081
sinon.match.any,
8182
sinon.match.any,
83+
"active_mfa_method_id",
8284
JOURNEY_TYPE.REAUTHENTICATION
8385
);
8486
});
@@ -122,6 +124,7 @@ describe("send mfa controller", () => {
122124
sinon.match.any,
123125
sinon.match.any,
124126
sinon.match.any,
127+
sinon.match.any,
125128
undefined
126129
);
127130
});
@@ -165,6 +168,7 @@ describe("send mfa controller", () => {
165168
sinon.match.any,
166169
sinon.match.any,
167170
sinon.match.any,
171+
sinon.match.any,
168172
JOURNEY_TYPE.REAUTHENTICATION
169173
);
170174
});

src/components/common/mfa/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface MfaServiceInterface {
1111
isResendCodeRequest: boolean,
1212
userLanguage: string,
1313
req: Request,
14+
mfaMethodId: string,
1415
journeyType?: JOURNEY_TYPE
1516
) => Promise<ApiResponseResult<DefaultApiResponse>>;
1617
}

src/components/common/state-machine/state-machine.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const USER_JOURNEY_EVENTS = {
5959
IPV_REVERIFICATION_FAILED_OR_DID_NOT_MATCH:
6060
"IPV_REVERIFICATION_FAILED_OR_DID_NOT_MATCH",
6161
MFA_RESET_ATTEMPTED_VIA_AUTH_APP: "MFA_RESET_ATTEMPTED_VIA_AUTH_APP",
62+
SELECT_SMS_MFA_METHOD: "CHANGE_MFA",
6263
SELECT_AUTH_APP_MFA_METHOD: "SELECT_AUTH_APP_MFA_METHOD",
6364
};
6465

@@ -737,6 +738,7 @@ const authStateMachine = createMachine(
737738
[USER_JOURNEY_EVENTS.SELECT_AUTH_APP_MFA_METHOD]: [
738739
PATH_NAMES.ENTER_AUTHENTICATOR_APP_CODE,
739740
],
741+
[USER_JOURNEY_EVENTS.SELECT_SMS_MFA_METHOD]: [PATH_NAMES.ENTER_MFA],
740742
},
741743
},
742744
},

src/components/common/verify-code/tests/verify-code-service.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe("verify code service", () => {
5050
const code = "1234";
5151
const notificationType = NOTIFICATION_TYPE.VERIFY_EMAIL;
5252
const journeyType = JOURNEY_TYPE.SIGN_IN;
53+
const mfaMethodId = "9b1deb4d-3b7d-4bad-9bdd-2b0d7a3a03d7";
5354

5455
const result = await service.verifyCode(
5556
sessionId,
@@ -58,13 +59,14 @@ describe("verify code service", () => {
5859
clientSessionId,
5960
diPersistentSessionId,
6061
req,
62+
mfaMethodId,
6163
journeyType
6264
);
6365

6466
const expectedApiCallDetails = {
6567
expectedPath: API_ENDPOINTS.VERIFY_CODE,
6668
expectedHeaders: expectedHeadersFromCommonVarsWithSecurityHeaders,
67-
expectedBody: { code, notificationType, journeyType },
69+
expectedBody: { code, notificationType, journeyType, mfaMethodId },
6870
};
6971

7072
checkApiCallMadeWithExpectedBodyAndHeaders(

src/components/common/verify-code/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface VerifyCodeInterface {
1010
clientSessionId: string,
1111
persistentSessionId: string,
1212
req: Request,
13+
mfaMethodId: string,
1314
journeyType: JOURNEY_TYPE
1415
) => Promise<ApiResponseResult<DefaultApiResponse>>;
1516
}

src/components/common/verify-code/verify-code-controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export function verifyCodePost(
4949
clientSessionId,
5050
persistentSessionId,
5151
req,
52+
req.session.user.activeMfaMethodId,
5253
options.journeyType
5354
);
5455

src/components/common/verify-code/verify-code-service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function codeService(axios: Http = http): VerifyCodeInterface {
1717
clientSessionId: string,
1818
persistentSessionId: string,
1919
req: Request,
20+
mfaMethodId: string,
2021
journeyType?: string
2122
): Promise<ApiResponseResult<DefaultApiResponse>> {
2223
const response = await axios.client.post<DefaultApiResponse>(
@@ -25,6 +26,7 @@ export function codeService(axios: Http = http): VerifyCodeInterface {
2526
code,
2627
notificationType,
2728
journeyType,
29+
mfaMethodId,
2830
},
2931
getInternalRequestConfigWithSecurityHeaders(
3032
{

0 commit comments

Comments
 (0)