Skip to content

Commit 5b43e18

Browse files
committed
AUT-4248: call sendMfaCode with retrieved activeMfaMethod
- Retrieve and set activeMfaMethodId to that of default mfa method wip to squash
1 parent 49c8fae commit 5b43e18

5 files changed

Lines changed: 42 additions & 6 deletions

File tree

src/components/reset-password-2fa-sms/reset-password-2fa-sms-controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export function resetPassword2FASmsGet(
6363
false,
6464
xss(req.cookies.lng as string),
6565
req,
66+
req.session.user.activeMfaMethodId,
6667
JOURNEY_TYPE.PASSWORD_RESET_MFA
6768
);
6869

src/components/reset-password-2fa-sms/tests/reset-password-2fa-sms-controller.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import { createMockRequest } from "../../../../test/helpers/mock-request-helper.
1818
import { buildMfaMethods } from "../../../../test/helpers/mfa-helper.js";
1919

2020
const TEST_REDACTED_PHONE_NUMBER = "777";
21+
const TEST_ACTIVE_MFA_METHOD_ID = "active-mfa-method-id";
2122

22-
describe("reset password 2fa auth app controller", () => {
23+
describe("reset password 2fa SMS controller", () => {
2324
let req: RequestOutput;
2425
let res: ResponseOutput;
2526

@@ -34,21 +35,34 @@ describe("reset password 2fa auth app controller", () => {
3435
});
3536

3637
describe("resetPassword2FASmsGet", () => {
37-
it("should render reset password auth app view", async () => {
38+
it("should render reset password SMS view", async () => {
3839
const fakeService: MfaServiceInterface = {
3940
sendMfaCode: sinon.fake.returns({
4041
success: true,
4142
}),
4243
} as unknown as MfaServiceInterface;
4344
req.session.user = {
4445
email: "joe.bloggs@test.com",
46+
activeMfaMethodId: "active-mfa-method-id",
4547
};
4648

4749
await resetPassword2FASmsGet(fakeService)(
4850
req as Request,
4951
res as Response
5052
);
5153

54+
expect(fakeService.sendMfaCode).to.have.been.calledOnceWithExactly(
55+
sinon.match.any,
56+
sinon.match.any,
57+
sinon.match.any,
58+
sinon.match.any,
59+
sinon.match.any,
60+
sinon.match.any,
61+
sinon.match.any,
62+
TEST_ACTIVE_MFA_METHOD_ID,
63+
sinon.match.any
64+
);
65+
5266
expect(res.render).to.have.calledWith("reset-password-2fa-sms/index.njk");
5367
});
5468

src/components/reset-password-check-email/reset-password-check-email-controller.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Request, Response } from "express";
2-
import type { ExpressRouteFunc } from "../../types.js";
2+
import type { ExpressRouteFunc, MfaMethod } from "../../types.js";
3+
import { MfaMethodPriority } from "../../types.js";
34
import type { ResetPasswordCheckEmailServiceInterface } from "./types.js";
45
import { resetPasswordCheckEmailService } from "./reset-password-check-email-service.js";
56
import { BadRequestError } from "../../utils/error.js";
@@ -51,6 +52,9 @@ export function resetPasswordCheckEmailGet(
5152
}
5253

5354
if (result.success) {
55+
req.session.user.activeMfaMethodId = result.data.mfaMethods.find(
56+
(method: MfaMethod) => method.priority === MfaMethodPriority.DEFAULT
57+
)?.id;
5458
req.session.user.mfaMethods = result.data.mfaMethods;
5559

5660
req.session.user.enterEmailMfaType = result.data.mfaMethodType;

src/components/reset-password-check-email/tests/reset-password-check-email-controller.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import type { PartialMfaMethod } from "../../../../test/helpers/mfa-helper.js";
2626
import { buildMfaMethods } from "../../../../test/helpers/mfa-helper.js";
2727
import type { MfaMethod } from "../../../types.js";
2828

29+
const TEST_DEFAULT_MFA_METHOD_ID = "TEST_DEFAULT_MFA_METHOD_ID";
30+
2931
describe("reset password check email controller", () => {
3032
let req: RequestOutput;
3133
let res: ResponseOutput;
@@ -47,7 +49,7 @@ describe("reset password check email controller", () => {
4749
describe("resetPasswordCheckEmailGet", () => {
4850
it("should render reset password check email view", async () => {
4951
const expectedMfaMethods: MfaMethod[] = buildMfaMethods([
50-
{ redactedPhoneNumber: "123" },
52+
{ redactedPhoneNumber: "123", id: TEST_DEFAULT_MFA_METHOD_ID },
5153
]);
5254
const fakeService: ResetPasswordCheckEmailServiceInterface = {
5355
resetPasswordRequest: sinon.fake.returns({
@@ -67,6 +69,9 @@ describe("reset password check email controller", () => {
6769

6870
expect(req.session.user.enterEmailMfaType).to.eq("SMS");
6971
expect(req.session.user.mfaMethods).to.deep.eq(expectedMfaMethods);
72+
expect(req.session.user.activeMfaMethodId).to.equal(
73+
TEST_DEFAULT_MFA_METHOD_ID
74+
);
7075
expect(
7176
getDefaultSmsMfaMethod(req.session.user.mfaMethods).redactedPhoneNumber
7277
).to.eq("123");

src/components/reset-password-check-email/tests/reset-password-check-email-integration.test.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ERROR_CODES } from "../../common/constants.js";
1111
import type { NextFunction, Request, Response } from "express";
1212
import { getPermittedJourneyForPath } from "../../../../test/helpers/session-helper.js";
1313
import esmock from "esmock";
14+
import { buildMfaMethods } from "../../../../test/helpers/mfa-helper.js";
1415

1516
describe("Integration::reset password check email ", () => {
1617
let app: any;
@@ -50,7 +51,10 @@ describe("Integration::reset password check email ", () => {
5051
app = await createApp();
5152
baseApi = process.env.FRONTEND_API_BASE_URL;
5253

53-
nock(baseApi).post(API_ENDPOINTS.RESET_PASSWORD_REQUEST).once().reply(204);
54+
nock(baseApi)
55+
.post(API_ENDPOINTS.RESET_PASSWORD_REQUEST)
56+
.once()
57+
.reply(200, { mfaMethods: [] });
5458

5559
await request(
5660
app,
@@ -73,7 +77,15 @@ describe("Integration::reset password check email ", () => {
7377
});
7478

7579
it("should return reset password check email page", async () => {
76-
nock(baseApi).post(API_ENDPOINTS.RESET_PASSWORD_REQUEST).once().reply(200);
80+
nock(baseApi)
81+
.post(API_ENDPOINTS.RESET_PASSWORD_REQUEST)
82+
.once()
83+
.reply(200, {
84+
mfaMethods: buildMfaMethods({
85+
redactedPhoneNumber: "123",
86+
id: "test-id",
87+
}),
88+
});
7789
await request(app, (test) =>
7890
test.get(PATH_NAMES.RESET_PASSWORD_CHECK_EMAIL).expect(200)
7991
);

0 commit comments

Comments
 (0)