Skip to content

Commit

Permalink
Merge pull request #1354 from govuk-one-login/AUT-2093-part-1
Browse files Browse the repository at this point in the history
AUT-2093-part-1: Remove previous implementation of reauth landing screen
  • Loading branch information
ayoshebby authored Feb 9, 2024
2 parents db1392a + 247df00 commit 95455d3
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 134 deletions.
2 changes: 1 addition & 1 deletion src/components/common/state-machine/state-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const authStateMachine = createMachine(
cond: "isConsentRequired",
},
{
target: [PATH_NAMES.ENTER_PASSWORD],
target: [PATH_NAMES.ENTER_EMAIL_SIGN_IN],
cond: "isReauthenticationRequired",
},
{ target: [PATH_NAMES.AUTH_CODE], cond: "isAuthenticated" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe("state-machine", () => {
USER_JOURNEY_EVENTS.EXISTING_SESSION,
{ isAuthenticated: true, isReauthenticationRequired: true }
);
expect(nextState.value).to.equal(PATH_NAMES.ENTER_PASSWORD);
expect(nextState.value).to.equal(PATH_NAMES.ENTER_EMAIL_SIGN_IN);
});

it("should move from authorize to sign or create when reauthentication is requested and the user is not logged in", () => {
Expand Down
36 changes: 3 additions & 33 deletions src/components/enter-password/enter-password-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ import { MFA_METHOD_TYPE } from "../../app.constants";
import xss from "xss";
import { EnterEmailServiceInterface } from "../enter-email/types";
import { enterEmailService } from "../enter-email/enter-email-service";
import {
support2FABeforePasswordReset,
supportReauthentication,
} from "../../config";
import { CheckReauthServiceInterface } from "../check-reauth-users/types";
import { checkReauthUsersService } from "../check-reauth-users/check-reauth-users-service";
import { support2FABeforePasswordReset } from "../../config";
import { getJourneyTypeFromUserSession } from "../common/journey/journey";

const ENTER_PASSWORD_TEMPLATE = "enter-password/index.njk";
Expand All @@ -36,33 +31,8 @@ const ENTER_PASSWORD_ACCOUNT_EXISTS_TEMPLATE =
const ENTER_PASSWORD_ACCOUNT_EXISTS_VALIDATION_KEY =
"pages.enterPasswordAccountExists.password.validationError.incorrectPassword";

export function enterPasswordGet(
service: CheckReauthServiceInterface = checkReauthUsersService()
): ExpressRouteFunc {
return async function (req: Request, res: Response) {
const isReauthenticationRequired = req.session.user.reauthenticate;

if (!supportReauthentication() || !isReauthenticationRequired) {
return res.render(ENTER_PASSWORD_TEMPLATE);
}

const email = req.session.user.email.toLowerCase();
const { sessionId, clientSessionId, persistentSessionId } = res.locals;

const checkReauthUserResponse = await service.checkReauthUsers(
sessionId,
email,
req.ip,
clientSessionId,
persistentSessionId
);

if (!checkReauthUserResponse.success) {
return res.render("common/errors/500.njk");
}

return res.render(ENTER_PASSWORD_TEMPLATE);
};
export function enterPasswordGet(req: Request, res: Response): void {
res.render(ENTER_PASSWORD_TEMPLATE);
}

export function enterSignInRetryBlockedGet(
Expand Down
2 changes: 1 addition & 1 deletion src/components/enter-password/enter-password-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ router.get(
PATH_NAMES.ENTER_PASSWORD,
validateSessionMiddleware,
allowUserJourneyMiddleware,
asyncHandler(enterPasswordGet())
enterPasswordGet
);

router.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
} from "mock-req-res";
import { EnterEmailServiceInterface } from "../../enter-email/types";
import { ERROR_CODES } from "../../common/constants";
import { CheckReauthServiceInterface } from "../../check-reauth-users/types";
import * as journey from "../../common/journey/journey";

describe("enter password controller", () => {
Expand All @@ -41,78 +40,11 @@ describe("enter password controller", () => {
});

describe("enterPasswordGet", () => {
const fakeService: CheckReauthServiceInterface = {
checkReauthUsers: sinon.fake.returns({
success: true,
}),
} as unknown as CheckReauthServiceInterface;

it("should render enter password view", async () => {
await enterPasswordGet(fakeService)(req as Request, res as Response);

expect(res.render).to.have.calledWith("enter-password/index.njk");
});

it("should render enter password view when supportReauthentication flag is switched off", async () => {
process.env.SUPPORT_REAUTHENTICATION = "0";

await enterPasswordGet(fakeService)(req as Request, res as Response);

expect(res.render).to.have.calledWith("enter-password/index.njk");
});

it("should render enter password view when isReautheticationRequired is false", async () => {
process.env.SUPPORT_REAUTHENTICATION = "1";
res.locals.sessionId = "123456-djjad";
res.locals.clientSessionId = "00000-djjad";
res.locals.persistentSessionId = "dips-123456-abc";
req.session.user = {
email: "[email protected]",
};

await enterPasswordGet(fakeService)(req as Request, res as Response);

expect(res.render).to.have.calledWith("enter-password/index.njk");
});

it("should render enter password view when isReautheticationRequired is true and check service returns successfully", async () => {
process.env.SUPPORT_REAUTHENTICATION = "1";
res.locals.sessionId = "123456-djjad";
res.locals.clientSessionId = "00000-djjad";
res.locals.persistentSessionId = "dips-123456-abc";
req.session.user = {
email: "[email protected]",
reauthenticate: "12345",
};

await enterPasswordGet(fakeService)(req as Request, res as Response);
enterPasswordGet(req as Request, res as Response);

expect(res.render).to.have.calledWith("enter-password/index.njk");
});

it("should render 500 error view when isReautheticationRequired is true and check service fails", async () => {
const unsuccessfulFakeService: CheckReauthServiceInterface = {
checkReauthUsers: sinon.fake.returns({
success: false,
}),
} as unknown as CheckReauthServiceInterface;

process.env.SUPPORT_REAUTHENTICATION = "1";
res.locals.sessionId = "123456-djjad";
res.locals.clientSessionId = "00000-djjad";
res.locals.persistentSessionId = "dips-123456-abc";
req.session.user = {
email: "[email protected]",
reauthenticate: "12345",
};

await enterPasswordGet(unsuccessfulFakeService)(
req as Request,
res as Response
);

expect(res.render).to.have.calledWith("common/errors/500.njk");
});
});

describe("enterPasswordPost", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@ import { expect, sinon } from "../../../../test/utils/test-utils";
import nock = require("nock");
import * as cheerio from "cheerio";
import decache from "decache";
import {
API_ENDPOINTS,
HTTP_STATUS_CODES,
PATH_NAMES,
} from "../../../app.constants";
import { API_ENDPOINTS, PATH_NAMES } from "../../../app.constants";
import { ERROR_CODES } from "../../common/constants";
import { AxiosResponse } from "axios";
import { createApiResponse } from "../../../utils/http";
import { CheckReauthServiceInterface } from "../../check-reauth-users/types";
import { DefaultApiResponse } from "../../../types";

describe("Integration::enter password", () => {
let token: string | string[];
Expand All @@ -27,7 +19,6 @@ describe("Integration::enter password", () => {
decache("../../../app");
decache("../../../middleware/session-middleware");
const sessionMiddleware = require("../../../middleware/session-middleware");
const checkReauthUsersService = require("../../check-reauth-users/check-reauth-users-service");

sinon
.stub(sessionMiddleware, "validateSessionMiddleware")
Expand All @@ -47,20 +38,6 @@ describe("Integration::enter password", () => {
next();
});

sinon
.stub(checkReauthUsersService, "checkReauthUsersService")
.callsFake((): CheckReauthServiceInterface => {
async function checkReauthUsers() {
const fakeAxiosResponse: AxiosResponse = {
status: HTTP_STATUS_CODES.OK,
} as AxiosResponse;

return createApiResponse<DefaultApiResponse>(fakeAxiosResponse);
}

return { checkReauthUsers };
});

app = await require("../../../app").createApp();
baseApi = process.env.FRONTEND_API_BASE_URL;

Expand All @@ -86,11 +63,6 @@ describe("Integration::enter password", () => {
request(app).get(ENDPOINT).expect(200, done);
});

it("should return enter password page when support reauthentication flag is on and check reauth users api call is successfull", (done) => {
process.env.SUPPORT_REAUTHENTICATION = "1";
request(app).get(ENDPOINT).expect(200, done);
});

it("should return error when csrf not present", (done) => {
request(app)
.post(ENDPOINT)
Expand Down

0 comments on commit 95455d3

Please sign in to comment.