-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1535 from govuk-one-login/AUT-2602/fix-lockout-units
Aut 2602/fix lockout units
- Loading branch information
Showing
4 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import { | |
enterEmailGet, | ||
enterEmailPost, | ||
} from "../enter-email-controller"; | ||
import { EnterEmailServiceInterface } from "../types"; | ||
import { EnterEmailServiceInterface, LockoutInformation } from "../types"; | ||
import { JOURNEY_TYPE, ERROR_CODES } from "../../common/constants"; | ||
import { PATH_NAMES } from "../../../app.constants"; | ||
import { SendNotificationServiceInterface } from "../../common/send-notification/types"; | ||
|
@@ -24,6 +24,8 @@ import { CheckReauthServiceInterface } from "../../check-reauth-users/types"; | |
describe("enter email controller", () => { | ||
let req: RequestOutput; | ||
let res: ResponseOutput; | ||
let clock: sinon.SinonFakeTimers; | ||
const date = new Date(2024, 1, 1); | ||
|
||
beforeEach(() => { | ||
req = mockRequest({ | ||
|
@@ -32,9 +34,13 @@ describe("enter email controller", () => { | |
i18n: { language: "en" }, | ||
}); | ||
res = mockResponse(); | ||
clock = sinon.useFakeTimers({ | ||
now: date.valueOf(), | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
clock.restore(); | ||
sinon.restore(); | ||
}); | ||
|
||
|
@@ -163,6 +169,41 @@ describe("enter email controller", () => { | |
expect(fakeService.userExists).to.have.been.calledOnce; | ||
}); | ||
|
||
it("should set a lock with the correct timestamp when the response contains lockout information", async () => { | ||
const lockTTlInSeconds = 60; | ||
|
||
const lockoutInformation: LockoutInformation = { | ||
lockType: "codeBlock", | ||
lockTTL: lockTTlInSeconds.toString(), | ||
journeyType: "SIGN_IN", | ||
mfaMethodType: "SMS", | ||
}; | ||
const fakeService: EnterEmailServiceInterface = { | ||
userExists: sinon.fake.returns({ | ||
success: true, | ||
data: { | ||
doesUserExist: true, | ||
lockoutInformation: [lockoutInformation], | ||
}, | ||
}), | ||
} as unknown as EnterEmailServiceInterface; | ||
|
||
req.body.email = "[email protected]"; | ||
res.locals.sessionId = "sadl990asdald"; | ||
req.path = PATH_NAMES.ENTER_EMAIL_SIGN_IN; | ||
|
||
await enterEmailPost(fakeService)(req as Request, res as Response); | ||
|
||
const expectedLockTime = new Date( | ||
date.getTime() + lockTTlInSeconds * 1000 | ||
).toUTCString(); | ||
|
||
expect(req.session.user.wrongCodeEnteredLock).to.eq(expectedLockTime); | ||
|
||
expect(res.redirect).to.have.calledWith("/enter-password"); | ||
expect(fakeService.userExists).to.have.been.calledOnce; | ||
}); | ||
|
||
it("should throw error when API call throws error", async () => { | ||
const error = new Error("Internal server error"); | ||
const fakeService: EnterEmailServiceInterface = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters