Skip to content

Commit

Permalink
AUT-2578: Convert check reauth service to use common headers
Browse files Browse the repository at this point in the history
  • Loading branch information
BeckaL committed May 21, 2024
1 parent b97faa2 commit 425665f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
32 changes: 19 additions & 13 deletions src/components/check-reauth-users/check-reauth-users-service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {
createApiResponse,
getRequestConfig,
getInternalRequestConfigWithSecurityHeaders,
Http,
http,
} from "../../utils/http";
import { API_ENDPOINTS, HTTP_STATUS_CODES } from "../../app.constants";
import { CheckReauthServiceInterface } from "./types";
import { ApiResponseResult, DefaultApiResponse } from "../../types";
import { Request } from "express";

export function checkReauthUsersService(
axios: Http = http
Expand All @@ -17,20 +18,25 @@ export function checkReauthUsersService(
sub: string,
sourceIp: string,
clientSessionId: string,
persistentSessionId: string
persistentSessionId: string,
req: Request
): Promise<ApiResponseResult<DefaultApiResponse>> {
const lowerCaseEmail = emailAddress.toLowerCase();
const config = getRequestConfig({
sessionId,
sourceIp,
validationStatuses: [
HTTP_STATUS_CODES.OK,
HTTP_STATUS_CODES.BAD_REQUEST,
HTTP_STATUS_CODES.NOT_FOUND,
],
clientSessionId,
persistentSessionId,
});
const config = getInternalRequestConfigWithSecurityHeaders(
{
sessionId,
sourceIp,
validationStatuses: [
HTTP_STATUS_CODES.OK,
HTTP_STATUS_CODES.BAD_REQUEST,
HTTP_STATUS_CODES.NOT_FOUND,
],
clientSessionId,
persistentSessionId,
},
req,
API_ENDPOINTS.CHECK_REAUTH_USER
);

const response = await axios.client.post<DefaultApiResponse>(
API_ENDPOINTS.CHECK_REAUTH_USER,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { describe } from "mocha";
import { Http } from "../../../utils/http";
import { sinon } from "../../../../test/utils/test-utils";
import { API_ENDPOINTS } from "../../../app.constants";
import { API_ENDPOINTS, PATH_NAMES } from "../../../app.constants";
import { SinonStub } from "sinon";
import { checkReauthUsersService } from "../check-reauth-users-service";
import { CheckReauthServiceInterface } from "../types";
import {
checkApiCallMadeWithExpectedBodyAndHeaders,
commonVariables,
expectedHeadersFromCommonVarsWithoutSecurityHeaders,

Check failure on line 11 in src/components/check-reauth-users/tests/check-reauth-user-service.test.ts

View workflow job for this annotation

GitHub Actions / run-tests

'expectedHeadersFromCommonVarsWithoutSecurityHeaders' is defined but never used
expectedHeadersFromCommonVarsWithSecurityHeaders,
requestHeadersWithIpAndAuditEncoded,
resetApiKeyAndBaseUrlEnvVars,
setupApiKeyAndBaseUrlEnvVars,
} from "../../../../test/helpers/service-test-helper";
import { createMockRequest } from "../../../../test/helpers/mock-request-helper";

describe("re-authentication service", () => {
const httpInstance = new Http();
Expand Down Expand Up @@ -39,19 +42,23 @@ describe("re-authentication service", () => {
postStub.resolves(axiosResponse);
const { sessionId, email, ip, clientSessionId, diPersistentSessionId } =
commonVariables;
const req = createMockRequest(PATH_NAMES.ENTER_EMAIL_SIGN_IN, {
headers: requestHeadersWithIpAndAuditEncoded,
});

const result = await service.checkReauthUsers(
sessionId,
email,
SUBJECT,
ip,
clientSessionId,
diPersistentSessionId
diPersistentSessionId,
req
);

const expectedApiCallDetails = {
expectedPath: API_ENDPOINTS.CHECK_REAUTH_USER,
expectedHeaders: expectedHeadersFromCommonVarsWithoutSecurityHeaders,
expectedHeaders: expectedHeadersFromCommonVarsWithSecurityHeaders,
expectedBody: { email: commonVariables.email, rpPairwiseId: SUBJECT },
validateStatus: true,
};
Expand Down
4 changes: 3 additions & 1 deletion src/components/check-reauth-users/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiResponseResult, DefaultApiResponse } from "../../types";
import { Request } from "express";

export interface CheckReauthServiceInterface {
checkReauthUsers: (
Expand All @@ -7,6 +8,7 @@ export interface CheckReauthServiceInterface {
sub: string,
sourceIp: string,
clientSessionId: string,
persistentSessionId: string
persistentSessionId: string,
req: Request
) => Promise<ApiResponseResult<DefaultApiResponse>>;
}
3 changes: 2 additions & 1 deletion src/components/enter-email/enter-email-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export function enterEmailPost(
sub,
req.ip,
clientSessionId,
persistentSessionId
persistentSessionId,
req
);

if (!checkReauth.success) {
Expand Down

0 comments on commit 425665f

Please sign in to comment.