Skip to content

Commit

Permalink
ATO-224: Return to orchestration on ID journeys
Browse files Browse the repository at this point in the history
When the auth orch split is enabled, we should return to orchestration rather than redirecting to IPV.
  • Loading branch information
ethanmills committed Dec 5, 2023
1 parent cf1b545 commit b05c692
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 2 deletions.
27 changes: 26 additions & 1 deletion src/components/prove-identity/prove-identity-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,36 @@ import { proveIdentityService } from "./prove-identity-service";
import { ProveIdentityServiceInterface } from "./types";
import { getNextPathAndUpdateJourney } from "../common/constants";
import { USER_JOURNEY_EVENTS } from "../common/state-machine/state-machine";
import { supportAuthOrchSplit } from "../../config";
import { authCodeGet } from "../auth-code/auth-code-controller";
import { AuthCodeServiceInterface } from "../auth-code/types";
import { authCodeService } from "../auth-code/auth-code-service";

export function proveIdentityGet(
service: ProveIdentityServiceInterface = proveIdentityService()
service: ProveIdentityServiceInterface = proveIdentityService(),
authCode: AuthCodeServiceInterface = authCodeService()
): ExpressRouteFunc {
const returnToOrchestration = async (
req: Request,
res: Response
): Promise<void> => {
const { sessionId } = res.locals;
getNextPathAndUpdateJourney(
req,
req.path,
USER_JOURNEY_EVENTS.PROVE_IDENTITY_INIT,
null,
sessionId
);

return authCodeGet(authCode)(req, res);
};

return async function (req: Request, res: Response) {
if (supportAuthOrchSplit()) {
return returnToOrchestration(req, res);
}

const { email } = req.session.user;
const { sessionId, clientSessionId, persistentSessionId } = res.locals;
const result = await service.ipvAuthorize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import {
RequestOutput,
ResponseOutput,
} from "mock-req-res";
import { PATH_NAMES } from "../../../app.constants";
import { API_ENDPOINTS, PATH_NAMES } from "../../../app.constants";
import { SinonStub } from "sinon";
import { AuthCodeServiceInterface } from "../../auth-code/types";
import { Http } from "../../../utils/http";
import { authCodeService } from "../../auth-code/auth-code-service";
import { ExpressRouteFunc } from "../../../types";
import { proveIdentityService } from "../prove-identity-service";

describe("prove identity controller", () => {
let req: RequestOutput;
Expand Down Expand Up @@ -70,4 +76,82 @@ describe("prove identity controller", () => {
).to.be.rejectedWith("1222:Error occurred");
});
});

describe("with auth orch split feature flag on", () => {
const redirectUriSentToAuth = "/redirect-uri";
const rpSectorHostSentToAuth = "https://rp.redirect.uri";
const isAccountCreationJourneyUserSession = true;
const redirectUriReturnedFromResponse =
"/redirect-here?with-some-params=added-by-the-endpoint";
const frontendBaseUrl = "/frontend-base-url";

const axiosResponse = Promise.resolve({
data: {
location: redirectUriReturnedFromResponse,
},
status: 200,
statusText: "OK",
headers: {},
config: {},
});
let postStub: SinonStub;
let service: AuthCodeServiceInterface;
let controller: ExpressRouteFunc;

beforeEach(() => {
process.env.API_KEY = "api-key";
process.env.FRONTEND_API_BASE_URL = frontendBaseUrl;
const httpInstance = new Http();
service = authCodeService(httpInstance);
controller = proveIdentityGet(proveIdentityService(), service);
postStub = sinon.stub(httpInstance.client, "post");
postStub.resolves(axiosResponse);
res.locals.sessionId = "s-123456-djjad";
res.locals.clientSessionId = "c-123456-djjad";
res.locals.persistentSessionId = "dips-123456-abc";
});

afterEach(() => {
postStub.reset();
});

it("it should make a post request to the orch auth endpoint with claim, state and redirect uri in the body", async () => {
process.env.SUPPORT_AUTH_ORCH_SPLIT = "1";

const claim = ["phone_number", "phone_number_verified"];
const state = "state";
req.session.client = {
claim: claim,
state: state,
redirectUri: redirectUriSentToAuth,
rpSectorHost: rpSectorHostSentToAuth,
};

req.session.user = {
isAccountCreationJourney: isAccountCreationJourneyUserSession,
};

await controller(req as Request, res as Response);

const expectedBody = {
claims: claim,
state: state,
"redirect-uri": redirectUriSentToAuth,
"rp-sector-uri": rpSectorHostSentToAuth,
"is-new-account": isAccountCreationJourneyUserSession,
};

expect(
postStub.calledOnceWithExactly(
API_ENDPOINTS.ORCH_AUTH_CODE,
expectedBody,
{
headers: sinon.match.object,
proxy: sinon.match.bool,
baseURL: frontendBaseUrl,
}
)
).to.be.true;
});
});
});

0 comments on commit b05c692

Please sign in to comment.