Skip to content

Commit

Permalink
AUT-2760 adding functionality to skip "prove your identity welcome"
Browse files Browse the repository at this point in the history
  • Loading branch information
VladGavrilet committed May 23, 2024
1 parent c516ca2 commit 76cd86d
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 62 deletions.
1 change: 1 addition & 0 deletions src/app.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export enum MFA_METHOD_TYPE {
SMS = "SMS",
AUTH_APP = "AUTH_APP",
}
export const shouldSkipPage = false;

export const PATH_NAMES = {
ROOT: "/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import { Request, Response } from "express";
import { getNextPathAndUpdateJourney } from "../common/constants";
import { USER_JOURNEY_EVENTS } from "../common/state-machine/state-machine";
import { PATH_NAMES } from "../../app.constants";

import { shouldSkipPage } from "../../app.constants";
export function proveIdentityWelcomeGet(req: Request, res: Response): void {
res.render(
req.session.user.isAuthenticated
? "prove-identity-welcome/index-existing-session.njk"
: "prove-identity-welcome/index.njk"
);
if (shouldSkipPage) {
// Redirect to the "/sign-in-or-create" page
res.redirect("/sign-in-or-create");
} else {
// If flag is not enabled, render the page as usual
res.render(
req.session.user.isAuthenticated
? "prove-identity-welcome/index-existing-session.njk"
: "prove-identity-welcome/index.njk"
);
}
}

export async function proveIdentityWelcomePost(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,75 +11,77 @@ import {
proveIdentityWelcomePost,
} from "../prove-identity-welcome-controller";
import { createMockRequest } from "../../../../test/helpers/mock-request-helper";
import { shouldSkipPage } from "../../../app.constants";
if (!shouldSkipPage) {
describe("prove your identity welcome controller", () => {
let req: RequestOutput;
let res: ResponseOutput;

const STATE = "ndhd7d7d";

beforeEach(() => {
req = createMockRequest(PATH_NAMES.PROVE_IDENTITY_WELCOME);
req.session.client = {
redirectUri: "http://someservice.com/auth",
state: STATE,
};
res = mockResponse();
});

describe("prove your identity welcome controller", () => {
let req: RequestOutput;
let res: ResponseOutput;

const STATE = "ndhd7d7d";

beforeEach(() => {
req = createMockRequest(PATH_NAMES.PROVE_IDENTITY_WELCOME);
req.session.client = {
redirectUri: "http://someservice.com/auth",
state: STATE,
};
res = mockResponse();
});

afterEach(() => {
sinon.restore();
});
afterEach(() => {
sinon.restore();
});

describe("proveIdentityWelcomeGet", () => {
it("should render prove your identity welcome page", async () => {
proveIdentityWelcomeGet(req as Request, res as Response);
describe("proveIdentityWelcomeGet", () => {
it("should render prove your identity welcome page", async () => {
proveIdentityWelcomeGet(req as Request, res as Response);

expect(res.render).to.have.been.calledWith(
"prove-identity-welcome/index.njk"
);
});
expect(res.render).to.have.been.calledWith(
"prove-identity-welcome/index.njk"
);
});

it("should render prove identity welcome page for user that already has an active session", async () => {
req.session.user.isAuthenticated = true;
proveIdentityWelcomeGet(req as Request, res as Response);
it("should render prove identity welcome page for user that already has an active session", async () => {
req.session.user.isAuthenticated = true;
proveIdentityWelcomeGet(req as Request, res as Response);

expect(res.render).to.have.been.calledWith(
"prove-identity-welcome/index-existing-session.njk"
);
expect(res.render).to.have.been.calledWith(
"prove-identity-welcome/index-existing-session.njk"
);
});
});
});

describe("proveIdentityWelcomePost", () => {
it("should redirect to sign in or create when user not authenticated", async () => {
await proveIdentityWelcomePost(req as Request, res as Response);
describe("proveIdentityWelcomePost", () => {
it("should redirect to sign in or create when user not authenticated", async () => {
await proveIdentityWelcomePost(req as Request, res as Response);

expect(res.redirect).to.have.been.calledWith(
PATH_NAMES.SIGN_IN_OR_CREATE
);
});
expect(res.redirect).to.have.been.calledWith(
PATH_NAMES.SIGN_IN_OR_CREATE
);
});

it("should redirect to prove your identity when user is authenticated", async () => {
req.session.user.isAuthenticated = true;
await proveIdentityWelcomePost(req as Request, res as Response);
it("should redirect to prove your identity when user is authenticated", async () => {
req.session.user.isAuthenticated = true;
await proveIdentityWelcomePost(req as Request, res as Response);

expect(res.redirect).to.have.been.calledWith(PATH_NAMES.PROVE_IDENTITY);
});
expect(res.redirect).to.have.been.calledWith(PATH_NAMES.PROVE_IDENTITY);
});

it("should redirect to uplift journey when user is required to step up auth", async () => {
req.session.user.isAuthenticated = true;
req.session.user.isUpliftRequired = true;
await proveIdentityWelcomePost(req as Request, res as Response);
it("should redirect to uplift journey when user is required to step up auth", async () => {
req.session.user.isAuthenticated = true;
req.session.user.isUpliftRequired = true;
await proveIdentityWelcomePost(req as Request, res as Response);

expect(res.redirect).to.have.been.calledWith(PATH_NAMES.UPLIFT_JOURNEY);
});
expect(res.redirect).to.have.been.calledWith(PATH_NAMES.UPLIFT_JOURNEY);
});

it("should redirect to enter password when user is required to login (prompt=LOGIN)", async () => {
req.session.user.isAuthenticated = true;
req.session.client.prompt = OIDC_PROMPT.LOGIN;
await proveIdentityWelcomePost(req as Request, res as Response);
it("should redirect to enter password when user is required to login (prompt=LOGIN)", async () => {
req.session.user.isAuthenticated = true;
req.session.client.prompt = OIDC_PROMPT.LOGIN;
await proveIdentityWelcomePost(req as Request, res as Response);

expect(res.redirect).to.have.been.calledWith(PATH_NAMES.ENTER_PASSWORD);
expect(res.redirect).to.have.been.calledWith(PATH_NAMES.ENTER_PASSWORD);
});
});
});
});
}

0 comments on commit 76cd86d

Please sign in to comment.