Skip to content

Commit

Permalink
AUT-2578: Convert send notification 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 be7affb commit 28aef8f
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const resendMfaCodePost = (
req.ip,
persistentSessionId,
xss(req.cookies.lng as string),
req,
journeyType,
phoneNumber
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe("resend mfa controller", () => {
"127.0.0.1",
"123123-djjad",
"",
req,
"ACCOUNT_RECOVERY"
);
});
Expand Down Expand Up @@ -110,6 +111,7 @@ describe("resend mfa controller", () => {
"127.0.0.1",
"123123-djjad",
"",
req,
"REGISTRATION"
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function accountNotFoundPost(
req.ip,
persistentSessionId,
xss(req.cookies.lng as string),
req,
JOURNEY_TYPE.REGISTRATION
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function sendEmailOtp(
req.ip,
persistentSessionId,
xss(req.cookies.lng as string),
req,
JOURNEY_TYPE.ACCOUNT_RECOVERY
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const checkYourPhonePost = (
req.ip,
res.locals.persistentSessionId,
xss(req.cookies.lng as string),
req,
journeyType
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { ApiResponseResult, DefaultApiResponse } from "../../../types";
import { API_ENDPOINTS, HTTP_STATUS_CODES } from "../../../app.constants";
import {
createApiResponse,
getRequestConfig,
getInternalRequestConfigWithSecurityHeaders,
http,
Http,
} from "../../../utils/http";
import { SendNotificationServiceInterface } from "./types";
import { Request } from "express";

export function sendNotificationService(
axios: Http = http
Expand All @@ -19,6 +20,7 @@ export function sendNotificationService(
sourceIp: string,
persistentSessionId: string,
userLanguage: string,
req: Request,
journeyType?: string,
phoneNumber?: string,
requestNewCode?: boolean
Expand All @@ -43,17 +45,21 @@ export function sendNotificationService(
const response = await axios.client.post<DefaultApiResponse>(
API_ENDPOINTS.SEND_NOTIFICATION,
payload,
getRequestConfig({
sessionId: sessionId,
clientSessionId: clientSessionId,
sourceIp: sourceIp,
persistentSessionId: persistentSessionId,
validationStatuses: [
HTTP_STATUS_CODES.NO_CONTENT,
HTTP_STATUS_CODES.BAD_REQUEST,
],
userLanguage: userLanguage,
})
getInternalRequestConfigWithSecurityHeaders(
{
sessionId: sessionId,
clientSessionId: clientSessionId,
sourceIp: sourceIp,
persistentSessionId: persistentSessionId,
validationStatuses: [
HTTP_STATUS_CODES.NO_CONTENT,
HTTP_STATUS_CODES.BAD_REQUEST,
],
userLanguage: userLanguage,
},
req,
API_ENDPOINTS.SEND_NOTIFICATION
)
);

return createApiResponse<DefaultApiResponse>(response, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ import { Http } from "../../../../utils/http";
import {
checkApiCallMadeWithExpectedBodyAndHeaders,
commonVariables,
expectedHeadersFromCommonVarsWithoutSecurityHeaders,
expectedHeadersFromCommonVarsWithSecurityHeaders,
requestHeadersWithIpAndAuditEncoded,
resetApiKeyAndBaseUrlEnvVars,
setupApiKeyAndBaseUrlEnvVars,
} from "../../../../../test/helpers/service-test-helper";
import { API_ENDPOINTS, NOTIFICATION_TYPE } from "../../../../app.constants";
import {
API_ENDPOINTS,
NOTIFICATION_TYPE,
PATH_NAMES,
} from "../../../../app.constants";
import { SendNotificationServiceInterface } from "../types";
import { sendNotificationService } from "../send-notification-service";
import { JOURNEY_TYPE } from "../../constants";
import { createMockRequest } from "../../../../../test/helpers/mock-request-helper";

describe("send notification service", () => {
let postStub: SinonStub;
Expand All @@ -23,10 +29,13 @@ describe("send notification service", () => {
});
const { sessionId, clientSessionId, email, ip, diPersistentSessionId } =
commonVariables;
const req = createMockRequest(PATH_NAMES.RESEND_MFA_CODE, {
headers: requestHeadersWithIpAndAuditEncoded,
});
const notificationType = NOTIFICATION_TYPE.VERIFY_EMAIL;
const userLanguage = "cy";
const expectedHeaders = {
...expectedHeadersFromCommonVarsWithoutSecurityHeaders,
...expectedHeadersFromCommonVarsWithSecurityHeaders,
"User-Language": userLanguage,
};

Expand All @@ -51,7 +60,8 @@ describe("send notification service", () => {
notificationType,
ip,
diPersistentSessionId,
userLanguage
userLanguage,
req
);

const expectedApiCallDetails = {
Expand Down Expand Up @@ -81,6 +91,7 @@ describe("send notification service", () => {
ip,
diPersistentSessionId,
userLanguage,
req,
journeyType,
phoneNumber,
requestNewCode
Expand Down
2 changes: 2 additions & 0 deletions src/components/common/send-notification/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 SendNotificationServiceInterface {
sendNotification: (
Expand All @@ -9,6 +10,7 @@ export interface SendNotificationServiceInterface {
sourceIp: string,
persistentSessionId: string,
userLanguage: string,
req: Request,
journeyType?: string,
phoneNumber?: string,
requestNewCode?: boolean
Expand Down
1 change: 1 addition & 0 deletions src/components/enter-email/enter-email-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export function enterEmailCreatePost(
req.ip,
persistentSessionId,
xss(req.cookies.lng as string),
req,
JOURNEY_TYPE.REGISTRATION
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export function enterPhoneNumberPost(
req.ip,
persistentSessionId,
xss(req.cookies.lng as string),
req,
journeyType,
phoneNumber
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function resendEmailCodePost(
req.ip,
persistentSessionId,
xss(req.cookies.lng as string),
req,
journeyType,
undefined,
xss(req.body.requestNewCode as string) === "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export function setupAuthenticatorAppPost(
req.ip,
res.locals.persistentSessionId,
xss(req.cookies.lng as string),
req,
journeyType
);

Expand Down

0 comments on commit 28aef8f

Please sign in to comment.