Skip to content

Commit

Permalink
Merge pull request #1474 from govuk-one-login/AUT-2613
Browse files Browse the repository at this point in the history
AUT-2613: Include check for max invalid password entered during reauthentication
  • Loading branch information
ayoshebby authored Mar 25, 2024
2 parents ea18d16 + 415227b commit ad80aa6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/components/enter-email/enter-email-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ export function enterEmailPost(
return res.render(BLOCKED_TEMPLATE);
}

if (checkReauth.data.code === ERROR_CODES.ACCOUNT_LOCKED) {
return res.render("enter-password/index-sign-in-retry-blocked.njk", {
support2hrLockout: support2hrLockout(),
});
}

if (
checkReauth.data.code ===
ERROR_CODES.RE_AUTH_SIGN_IN_DETAILS_ENTERED_EXCEEDED
Expand Down
43 changes: 43 additions & 0 deletions src/components/enter-email/tests/enter-email-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,49 @@ describe("enter email controller", () => {
);
});

it("should redirect to /enter-password blocked screen when the user has been blocked for entering max incorrect password during reauth journey", async () => {
process.env.SUPPORT_REAUTHENTICATION = "1";

req.body.email = "test.test.com";
res.locals.sessionId = "dsad.dds";
req.path = PATH_NAMES.ENTER_EMAIL_SIGN_IN;
res.locals.sessionId = "123456-djjad";
res.locals.clientSessionId = "00000-djjad";
res.locals.persistentSessionId = "dips-123456-abc";
req.session.user = {
email: "[email protected]",
reauthenticate: "12345",
};

req.t = sinon.fake.returns("translated string");

const fakeUserExistsService: EnterEmailServiceInterface = {
userExists: sinon.fake.returns({
success: false,
data: { doesUserExist: false },
}),
} as unknown as EnterEmailServiceInterface;

const fakeCheckReauthService: CheckReauthServiceInterface = {
checkReauthUsers: sinon.fake.returns({
success: false,
data: {
code: ERROR_CODES.ACCOUNT_LOCKED,
},
}),
} as unknown as CheckReauthServiceInterface;

await enterEmailPost(fakeUserExistsService, fakeCheckReauthService)(
req as Request,
res as Response
);

expect(fakeCheckReauthService.checkReauthUsers).to.have.been.calledOnce;
expect(res.render).to.have.calledWith(
"enter-password/index-sign-in-retry-blocked.njk"
);
});

it("should redirect to /enter-email when re-authentication is required and re-auth check is unsuccessful", async () => {
process.env.SUPPORT_REAUTHENTICATION = "1";

Expand Down

0 comments on commit ad80aa6

Please sign in to comment.