-
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 #2460 from govuk-one-login/AUT-3920/return-to-otp
AUT-3920: Redirect back to enter mfa pages
- Loading branch information
Showing
7 changed files
with
203 additions
and
74 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
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 |
---|---|---|
@@ -1,45 +1,32 @@ | ||
import { describe } from "mocha"; | ||
import decache from "decache"; | ||
import { expect, request, sinon } from "../../../../test/utils/test-utils"; | ||
import { API_ENDPOINTS, PATH_NAMES } from "../../../app.constants"; | ||
import { | ||
API_ENDPOINTS, | ||
CANNOT_CHANGE_HOW_GET_SECURITY_CODES_ACTION, | ||
MFA_METHOD_TYPE, | ||
PATH_NAMES, | ||
} from "../../../app.constants"; | ||
import express from "express"; | ||
import nock from "nock"; | ||
import * as cheerio from "cheerio"; | ||
|
||
describe("Integration:: ipv callback", () => { | ||
let app: express.Application; | ||
let baseApi: string; | ||
let sessionMiddleware: any; | ||
|
||
before(async () => { | ||
process.env.SUPPORT_MFA_RESET_WITH_IPV = "1"; | ||
}); | ||
|
||
after(() => { | ||
delete process.env.SUPPORT_MFA_RESET_WITH_IPV; | ||
}); | ||
|
||
describe("ipv callback", () => { | ||
before(async () => { | ||
decache("../../../app"); | ||
decache("../../../middleware/session-middleware"); | ||
process.env.SUPPORT_MFA_RESET_WITH_IPV = "1"; | ||
baseApi = process.env.FRONTEND_API_BASE_URL; | ||
sessionMiddleware = require("../../../middleware/session-middleware"); | ||
|
||
sinon | ||
.stub(sessionMiddleware, "validateSessionMiddleware") | ||
.callsFake(function (req: any, res: any, next: any): void { | ||
res.locals.sessionId = "tDy103saszhcxbQq0-mjdzU854"; | ||
|
||
req.session.user = { | ||
email: "[email protected]", | ||
phoneNumber: "7867", | ||
journey: { | ||
nextPath: PATH_NAMES.IPV_CALLBACK, | ||
}, | ||
}; | ||
|
||
next(); | ||
}); | ||
|
||
app = await require("../../../app").createApp(); | ||
app = await stubSessionMiddlewareAndCreateApp(PATH_NAMES.IPV_CALLBACK); | ||
}); | ||
|
||
after(() => { | ||
|
@@ -92,53 +79,18 @@ describe("Integration:: ipv callback", () => { | |
}); | ||
|
||
describe("cannot change how get security codes", () => { | ||
let token: string | string[]; | ||
let cookies: string; | ||
|
||
before(async () => { | ||
decache("../../../app"); | ||
decache("../../../middleware/session-middleware"); | ||
process.env.SUPPORT_MFA_RESET_WITH_IPV = "1"; | ||
sessionMiddleware = require("../../../middleware/session-middleware"); | ||
|
||
sinon | ||
.stub(sessionMiddleware, "validateSessionMiddleware") | ||
.callsFake(function (req: any, res: any, next: any): void { | ||
res.locals.sessionId = "tDy103saszhcxbQq0-mjdzU854"; | ||
|
||
req.session.user = { | ||
email: "[email protected]", | ||
phoneNumber: "7867", | ||
journey: { | ||
nextPath: PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES, | ||
}, | ||
}; | ||
|
||
next(); | ||
}); | ||
|
||
app = await require("../../../app").createApp(); | ||
|
||
await request( | ||
app, | ||
(test) => test.get(PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES), | ||
{ | ||
expectAnalyticsPropertiesMatchSnapshot: false, | ||
} | ||
).then((res) => { | ||
const $ = cheerio.load(res.text); | ||
token = $("[name=_csrf]").val(); | ||
cookies = res.headers["set-cookie"]; | ||
}); | ||
}); | ||
|
||
after(() => { | ||
afterEach(() => { | ||
app = undefined; | ||
nock.cleanAll(); | ||
sinon.restore(); | ||
}); | ||
|
||
it("returns a dummy page when an option is selected", async () => { | ||
const app = await stubSessionMiddlewareAndCreateApp( | ||
PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES | ||
); | ||
const { token, cookies } = | ||
await getCannotChangeSecurityCodesAndReturnTokenAndCookies(app); | ||
|
||
await request( | ||
app, | ||
(test) => test.post(PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES), | ||
|
@@ -150,7 +102,8 @@ describe("Integration:: ipv callback", () => { | |
.set("Cookie", cookies) | ||
.send({ | ||
_csrf: token, | ||
cannotChangeHowGetSecurityCodeAction: "help-to-delete-account", | ||
cannotChangeHowGetSecurityCodeAction: | ||
CANNOT_CHANGE_HOW_GET_SECURITY_CODES_ACTION.HELP_DELETE_ACCOUNT, | ||
}) | ||
.expect(function (res) { | ||
expect(res.text).to.equals("In development"); | ||
|
@@ -159,6 +112,12 @@ describe("Integration:: ipv callback", () => { | |
}); | ||
|
||
it("returns a validation error when no option is selected", async () => { | ||
const app = await stubSessionMiddlewareAndCreateApp( | ||
PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES | ||
); | ||
const { token, cookies } = | ||
await getCannotChangeSecurityCodesAndReturnTokenAndCookies(app); | ||
|
||
await request( | ||
app, | ||
(test) => test.post(PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES), | ||
|
@@ -180,5 +139,103 @@ describe("Integration:: ipv callback", () => { | |
}) | ||
.expect(400); | ||
}); | ||
|
||
it("goes to /enter-code when user selects retry security code radio button and their mfaMethodType is SMS", async () => { | ||
const app = await stubSessionMiddlewareAndCreateApp( | ||
PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES, | ||
MFA_METHOD_TYPE.SMS | ||
); | ||
const { token, cookies } = | ||
await getCannotChangeSecurityCodesAndReturnTokenAndCookies(app); | ||
|
||
await request( | ||
app, | ||
(test) => test.post(PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES), | ||
{ | ||
expectAnalyticsPropertiesMatchSnapshot: false, | ||
} | ||
) | ||
.type("form") | ||
.set("Cookie", cookies) | ||
.send({ | ||
_csrf: token, | ||
cannotChangeHowGetSecurityCodeAction: | ||
CANNOT_CHANGE_HOW_GET_SECURITY_CODES_ACTION.RETRY_SECURITY_CODE, | ||
}) | ||
.expect("Location", PATH_NAMES.ENTER_MFA) | ||
.expect(302); | ||
}); | ||
|
||
it("goes to /enter-authenticator-app-code when user selects retry security code radio button and their mfaMethodType is AUTH_APP", async () => { | ||
const app = await stubSessionMiddlewareAndCreateApp( | ||
PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES, | ||
MFA_METHOD_TYPE.AUTH_APP | ||
); | ||
const { token, cookies } = | ||
await getCannotChangeSecurityCodesAndReturnTokenAndCookies(app); | ||
|
||
await request( | ||
app, | ||
(test) => test.post(PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES), | ||
{ | ||
expectAnalyticsPropertiesMatchSnapshot: false, | ||
} | ||
) | ||
.type("form") | ||
.set("Cookie", cookies) | ||
.send({ | ||
_csrf: token, | ||
cannotChangeHowGetSecurityCodeAction: | ||
CANNOT_CHANGE_HOW_GET_SECURITY_CODES_ACTION.RETRY_SECURITY_CODE, | ||
}) | ||
.expect("Location", PATH_NAMES.ENTER_AUTHENTICATOR_APP_CODE) | ||
.expect(302); | ||
}); | ||
}); | ||
}); | ||
|
||
const stubSessionMiddlewareAndCreateApp = async ( | ||
nextPath: string, | ||
mfaMethodType?: MFA_METHOD_TYPE | ||
): Promise<express.Application> => { | ||
decache("../../../app"); | ||
decache("../../../middleware/session-middleware"); | ||
const sessionMiddleware = require("../../../middleware/session-middleware"); | ||
|
||
sinon | ||
.stub(sessionMiddleware, "validateSessionMiddleware") | ||
.callsFake(function (req: any, res: any, next: any): void { | ||
res.locals.sessionId = "tDy103saszhcxbQq0-mjdzU854"; | ||
|
||
req.session.user = { | ||
email: "[email protected]", | ||
phoneNumber: "7867", | ||
journey: { | ||
nextPath: nextPath, | ||
}, | ||
mfaMethodType: mfaMethodType, | ||
}; | ||
|
||
next(); | ||
}); | ||
|
||
return await require("../../../app").createApp(); | ||
}; | ||
|
||
const getCannotChangeSecurityCodesAndReturnTokenAndCookies = async ( | ||
app: express.Application | ||
) => { | ||
let cookies, token; | ||
await request( | ||
app, | ||
(test) => test.get(PATH_NAMES.CANNOT_CHANGE_SECURITY_CODES), | ||
{ | ||
expectAnalyticsPropertiesMatchSnapshot: false, | ||
} | ||
).then((res) => { | ||
const $ = cheerio.load(res.text); | ||
token = $("[name=_csrf]").val(); | ||
cookies = res.headers["set-cookie"]; | ||
}); | ||
return { token, cookies }; | ||
}; |
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