-
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 #1310 from govuk-one-login/AUT-2231/fix-interventi…
…ons-with-change-security-codes AUT-2231: Fixed Account Interventions/Change MFA Method Journeys
- Loading branch information
Showing
11 changed files
with
175 additions
and
31 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 |
---|---|---|
|
@@ -17,6 +17,7 @@ import { | |
RequestOutput, | ||
ResponseOutput, | ||
} from "mock-req-res"; | ||
import { AccountInterventionsInterface } from "../../../account-intervention/types"; | ||
|
||
describe("check your email change security codes controller", () => { | ||
let req: RequestOutput; | ||
|
@@ -48,22 +49,70 @@ describe("check your email change security codes controller", () => { | |
}); | ||
|
||
describe("checkYourEmailChangeSecurityCodesPost", () => { | ||
it("should redirect to /get-security-codes when valid code entered", async () => { | ||
const fakeService: VerifyCodeInterface = { | ||
it("should redirect to /get-security-codes and not call AIS when valid code entered and account interventions is turned on", async () => { | ||
const fakeVerifyCodeService: VerifyCodeInterface = { | ||
verifyCode: sinon.fake.returns({ | ||
success: true, | ||
}), | ||
} as unknown as VerifyCodeInterface; | ||
|
||
const fakeAccountInterventionsService: AccountInterventionsInterface = { | ||
accountInterventionStatus: sinon.fake.returns({ | ||
data: { | ||
email: "[email protected]", | ||
passwordResetRequired: false, | ||
blocked: false, | ||
temporarilySuspended: false, | ||
}, | ||
}), | ||
} as unknown as AccountInterventionsInterface; | ||
|
||
req.body.code = "123456"; | ||
req.session.id = "123456-djjad"; | ||
req.session.user.email = "[email protected]"; | ||
|
||
await checkYourEmailSecurityCodesPost(fakeService)( | ||
req as Request, | ||
res as Response | ||
); | ||
await checkYourEmailSecurityCodesPost( | ||
fakeVerifyCodeService, | ||
fakeAccountInterventionsService | ||
)(req as Request, res as Response); | ||
|
||
expect(fakeService.verifyCode).to.have.been.calledOnce; | ||
expect(fakeAccountInterventionsService.accountInterventionStatus).to.not | ||
.have.been.calledOnce; | ||
expect(fakeVerifyCodeService.verifyCode).to.have.been.calledOnce; | ||
expect(res.redirect).to.have.calledWith(PATH_NAMES.GET_SECURITY_CODES); | ||
}); | ||
|
||
it("should redirect to /get-security-codes when valid code entered and there are no interventions in place and account interventions is turned on", async () => { | ||
process.env.SUPPORT_ACCOUNT_INTERVENTIONS = "1"; | ||
const fakeVerifyCodeService: VerifyCodeInterface = { | ||
verifyCode: sinon.fake.returns({ | ||
success: true, | ||
}), | ||
} as unknown as VerifyCodeInterface; | ||
|
||
const fakeAccountInterventionsService: AccountInterventionsInterface = { | ||
accountInterventionStatus: sinon.fake.returns({ | ||
data: { | ||
email: "[email protected]", | ||
passwordResetRequired: false, | ||
blocked: false, | ||
temporarilySuspended: false, | ||
}, | ||
}), | ||
} as unknown as AccountInterventionsInterface; | ||
|
||
req.body.code = "123456"; | ||
req.session.id = "123456-djjad"; | ||
req.session.user.email = "[email protected]"; | ||
|
||
await checkYourEmailSecurityCodesPost( | ||
fakeVerifyCodeService, | ||
fakeAccountInterventionsService | ||
)(req as Request, res as Response); | ||
|
||
expect(fakeAccountInterventionsService.accountInterventionStatus).to.have | ||
.been.calledOnce; | ||
expect(fakeVerifyCodeService.verifyCode).to.have.been.calledOnce; | ||
expect(res.redirect).to.have.calledWith(PATH_NAMES.GET_SECURITY_CODES); | ||
}); | ||
|
||
|
@@ -77,11 +126,21 @@ describe("check your email change security codes controller", () => { | |
|
||
req.body.code = "678988"; | ||
req.session.id = "123456-djjad"; | ||
req.session.user.email = "[email protected]"; | ||
|
||
await checkYourEmailSecurityCodesPost(fakeService)( | ||
req as Request, | ||
res as Response | ||
); | ||
const fakeAccountInterventionsService: AccountInterventionsInterface = { | ||
accountInterventionStatus: sinon.fake.returns({ | ||
email: "[email protected]", | ||
passwordResetRequired: false, | ||
blocked: false, | ||
temporarilySuspended: false, | ||
}), | ||
} as unknown as AccountInterventionsInterface; | ||
|
||
await checkYourEmailSecurityCodesPost( | ||
fakeService, | ||
fakeAccountInterventionsService | ||
)(req as Request, res as Response); | ||
|
||
expect(fakeService.verifyCode).to.have.been.calledOnce; | ||
expect(res.render).to.have.been.calledWith( | ||
|
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
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 |
---|---|---|
|
@@ -55,6 +55,7 @@ describe("check your email controller", () => { | |
|
||
req.body.code = "123456"; | ||
req.session.id = "123456-djjad"; | ||
req.session.user.email = "[email protected]"; | ||
|
||
await checkYourEmailPost(fakeService)(req as Request, res as Response); | ||
|
||
|
@@ -74,6 +75,7 @@ describe("check your email controller", () => { | |
|
||
req.body.code = "678988"; | ||
req.session.id = "123456-djjad"; | ||
req.session.user.email = "[email protected]"; | ||
|
||
await checkYourEmailPost(fakeService)(req as Request, res as Response); | ||
|
||
|
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
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 |
---|---|---|
|
@@ -150,6 +150,7 @@ describe("enter mfa controller", () => { | |
req.body.code = "123456"; | ||
res.locals.sessionId = "123456-djjad"; | ||
req.session.user.reauthenticate = "test_data"; | ||
req.session.user.email = "[email protected]"; | ||
|
||
await enterMfaPost(fakeService)(req as Request, res as Response); | ||
|
||
|
@@ -181,6 +182,7 @@ describe("enter mfa controller", () => { | |
|
||
req.body.code = "123456"; | ||
res.locals.sessionId = "123456-djjad"; | ||
req.session.user.email = "[email protected]"; | ||
|
||
await enterMfaPost(fakeService)(req as Request, res as Response); | ||
|
||
|
@@ -201,6 +203,7 @@ describe("enter mfa controller", () => { | |
req.t = sinon.fake.returns("translated string"); | ||
req.body.code = "678988"; | ||
res.locals.sessionId = "123456-djjad"; | ||
req.session.user.email = "[email protected]"; | ||
|
||
await enterMfaPost(fakeService)(req as Request, res as Response); | ||
|
||
|
@@ -222,6 +225,7 @@ describe("enter mfa controller", () => { | |
req.t = sinon.fake.returns("translated string"); | ||
req.body.code = "678988"; | ||
res.locals.sessionId = "123456-djjad"; | ||
req.session.user.email = "[email protected]"; | ||
|
||
await enterMfaPost(fakeService)(req as Request, res as Response); | ||
|
||
|
Oops, something went wrong.