Skip to content

Commit

Permalink
BAU: Remove source ip from send notication service
Browse files Browse the repository at this point in the history
This is no longer required to set the ip in headers, since the common headers library that is now used gets this from the request that we now pass through.

Also pulls out some common noisy setup from these tests
  • Loading branch information
BeckaL committed May 22, 2024
1 parent aba1bf7 commit b286b7a
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export const resendMfaCodePost = (
clientSessionId,
email,
NOTIFICATION_TYPE.VERIFY_PHONE_NUMBER,
req.ip,
persistentSessionId,
xss(req.cookies.lng as string),
req,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ describe("resend mfa controller", () => {
});

describe("resendMfaCodePost", () => {
it("should request new phone verification code from send notification service and if successful redirect to /enter-code view", async () => {
const fakeService: SendNotificationServiceInterface = {
sendNotification: sinon.fake.returns({
success: true,
}),
} as unknown as SendNotificationServiceInterface;
let fakeService: SendNotificationServiceInterface;

beforeEach(() => {
fakeService = { sendNotification: sinon.fake.returns({ success: true }) };
});

it("should request new phone verification code from send notification service and if successful redirect to /enter-code view", async () => {
req.path = PATH_NAMES.RESEND_MFA_CODE_ACCOUNT_CREATION;

await resendMfaCodePost(fakeService)(req as Request, res as Response);
Expand All @@ -60,24 +60,19 @@ describe("resend mfa controller", () => {
});

it("should request new phone verification code from send notification service and if successful redirect to /enter-code view", async () => {
const fakeService: SendNotificationServiceInterface = {
sendNotification: sinon.fake.returns({
success: true,
}),
} as unknown as SendNotificationServiceInterface;

req.session.user = {
email,
isAccountRecoveryJourney: true,
};
req.path = PATH_NAMES.RESEND_MFA_CODE_ACCOUNT_CREATION;

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

expect(fakeService.sendNotification).to.have.been.calledWith(
sessionId,
clientSessionId,
email,
"VERIFY_PHONE_NUMBER",
ip,
diPersistentSessionId,
"",
req,
Expand All @@ -86,24 +81,19 @@ describe("resend mfa controller", () => {
});

it("should request new phone verification code from send notification service and if successful redirect to /enter-code view", async () => {
const fakeService: SendNotificationServiceInterface = {
sendNotification: sinon.fake.returns({
success: true,
}),
} as unknown as SendNotificationServiceInterface;

req.session.user = {
email,
isAccountCreationJourney: true,
};
req.path = PATH_NAMES.RESEND_MFA_CODE_ACCOUNT_CREATION;

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

expect(fakeService.sendNotification).to.have.been.calledWith(
sessionId,
clientSessionId,
email,
"VERIFY_PHONE_NUMBER",
ip,
diPersistentSessionId,
"",
req,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export function accountNotFoundPost(
clientSessionId,
req.session.user.email,
NOTIFICATION_TYPE.VERIFY_EMAIL,
req.ip,
persistentSessionId,
xss(req.cookies.lng as string),
req,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export function sendEmailOtp(
clientSessionId,
email,
NOTIFICATION_TYPE.VERIFY_CHANGE_HOW_GET_SECURITY_CODES,
req.ip,
persistentSessionId,
xss(req.cookies.lng as string),
req,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export const checkYourPhonePost = (
res.locals.clientSessionId,
req.session.user.email,
notificationType,
req.ip,
res.locals.persistentSessionId,
xss(req.cookies.lng as string),
req,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ describe("check your phone controller", () => {
});

describe("checkYourPhonePost", () => {
let fakeNotificationService: SendNotificationServiceInterface;

beforeEach(() => {
fakeNotificationService = { sendNotification: sinon.fake() };
});
it("can send the journeyType when requesting the MFA code", async () => {
const fakeService: VerifyMfaCodeInterface = {
verifyMfaCode: sinon.fake.returns({
Expand All @@ -60,10 +65,6 @@ describe("check your phone controller", () => {
}),
} as unknown as VerifyMfaCodeInterface;

const fakeNotificationService: SendNotificationServiceInterface = {
sendNotification: sinon.fake(),
};

const getJourneyTypeFromUserSessionSpy = sinon.spy(
journey,
"getJourneyTypeFromUserSession"
Expand Down Expand Up @@ -108,10 +109,6 @@ describe("check your phone controller", () => {
}),
} as unknown as VerifyMfaCodeInterface;

const fakeNotificationService: SendNotificationServiceInterface = {
sendNotification: sinon.fake(),
};

req.body.code = "123456";
res.locals.sessionId = "123456-djjad";

Expand All @@ -126,9 +123,9 @@ describe("check your phone controller", () => {
undefined,
undefined,
NOTIFICATION_TYPE.ACCOUNT_CREATED_CONFIRMATION,
"127.0.0.1",
undefined,
""
"",
req
);
expect(res.redirect).to.have.calledWith(
PATH_NAMES.CREATE_ACCOUNT_SUCCESSFUL
Expand All @@ -143,10 +140,6 @@ describe("check your phone controller", () => {
}),
} as unknown as VerifyMfaCodeInterface;

const fakeNotificationService: SendNotificationServiceInterface = {
sendNotification: sinon.fake(),
};

req.body.code = "123456";
res.locals.sessionId = "123456-djjad";
req.session.user = {
Expand All @@ -165,9 +158,9 @@ describe("check your phone controller", () => {
undefined,
undefined,
NOTIFICATION_TYPE.CHANGE_HOW_GET_SECURITY_CODES_CONFIRMATION,
"127.0.0.1",
undefined,
""
"",
req
);
expect(res.redirect).to.have.calledWith(
PATH_NAMES.CHANGE_SECURITY_CODES_CONFIRMATION
Expand All @@ -184,9 +177,6 @@ describe("check your phone controller", () => {
},
}),
} as unknown as VerifyMfaCodeInterface;
const fakeNotificationService: SendNotificationServiceInterface = {
sendNotification: sinon.fake(),
};

req.t = sinon.fake.returns("translated string");
req.body.code = "678988";
Expand All @@ -212,10 +202,6 @@ describe("check your phone controller", () => {
}),
} as unknown as VerifyMfaCodeInterface;

const fakeNotificationService: SendNotificationServiceInterface = {
sendNotification: sinon.fake(),
};

req.t = sinon.fake.returns("translated string");
req.body.code = "678988";
res.locals.sessionId = "123456-djjad";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export function sendNotificationService(
clientSessionId: string,
email: string,
notificationType: string,
sourceIp: string,
persistentSessionId: string,
userLanguage: string,
req: Request,
Expand Down Expand Up @@ -49,7 +48,6 @@ export function sendNotificationService(
{
sessionId: sessionId,
clientSessionId: clientSessionId,
sourceIp: sourceIp,
persistentSessionId: persistentSessionId,
validationStatuses: [
HTTP_STATUS_CODES.NO_CONTENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("send notification service", () => {
status: 200,
statusText: "OK",
});
const { sessionId, clientSessionId, email, ip, diPersistentSessionId } =
const { sessionId, clientSessionId, email, diPersistentSessionId } =
commonVariables;
const req = createMockRequest(PATH_NAMES.RESEND_MFA_CODE, {
headers: requestHeadersWithIpAndAuditEncoded,
Expand Down Expand Up @@ -58,7 +58,6 @@ describe("send notification service", () => {
clientSessionId,
email,
notificationType,
ip,
diPersistentSessionId,
userLanguage,
req
Expand Down Expand Up @@ -88,7 +87,6 @@ describe("send notification service", () => {
clientSessionId,
email,
notificationType,
ip,
diPersistentSessionId,
userLanguage,
req,
Expand Down
1 change: 0 additions & 1 deletion src/components/common/send-notification/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export interface SendNotificationServiceInterface {
clientSessionId: string,
email: string,
notificationType: string,
sourceIp: string,
persistentSessionId: string,
userLanguage: string,
req: Request,
Expand Down
1 change: 0 additions & 1 deletion src/components/enter-email/enter-email-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ export function enterEmailCreatePost(
clientSessionId,
email,
NOTIFICATION_TYPE.VERIFY_EMAIL,
req.ip,
persistentSessionId,
xss(req.cookies.lng as string),
req,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export function enterPhoneNumberPost(
clientSessionId,
email,
NOTIFICATION_TYPE.VERIFY_PHONE_NUMBER,
req.ip,
persistentSessionId,
xss(req.cookies.lng as string),
req,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export function resendEmailCodePost(
clientSessionId,
email,
getNotificationTemplateType(isAccountRecoveryJourney),
req.ip,
persistentSessionId,
xss(req.cookies.lng as string),
req,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ export function setupAuthenticatorAppPost(
res.locals.clientSessionId,
req.session.user.email,
notificationType,
req.ip,
res.locals.persistentSessionId,
xss(req.cookies.lng as string),
req,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ describe("setup-authenticator-app controller", () => {
});

describe("setupAuthenticatorAppPost", () => {
let fakeNotificationService: SendNotificationServiceInterface;

beforeEach(() => {
fakeNotificationService = { sendNotification: sinon.fake() };
});

it("can send the journeyType when sending the MFA code", async () => {
req.session.user.authAppSecret = "testsecret";
req.session.user.email = "[email protected]";
Expand All @@ -57,10 +63,6 @@ describe("setup-authenticator-app controller", () => {
verifyMfaCode: sinon.fake.returns({ success: true }),
} as unknown as VerifyMfaCodeInterface;

const fakeNotificationService: SendNotificationServiceInterface = {
sendNotification: sinon.fake(),
};

const getJourneyTypeFromUserSessionSpy = sinon.spy(
journey,
"getJourneyTypeFromUserSession"
Expand Down Expand Up @@ -101,25 +103,20 @@ describe("setup-authenticator-app controller", () => {
verifyMfaCode: sinon.fake.returns({ success: true }),
} as unknown as VerifyMfaCodeInterface;

const fakeNotificationService: SendNotificationServiceInterface = {
sendNotification: sinon.fake(),
};

await setupAuthenticatorAppPost(fakeMfAService, fakeNotificationService)(
req as Request,
res as Response
);

expect(fakeMfAService.verifyMfaCode).to.have.been.calledOnce;
expect(fakeNotificationService.sendNotification).to.have.been.calledOnce;
expect(fakeNotificationService.sendNotification).to.have.calledWith(
expect(fakeNotificationService.sendNotification).to.have.calledOnceWith(
undefined,
undefined,
"[email protected]",
NOTIFICATION_TYPE.ACCOUNT_CREATED_CONFIRMATION,
"127.0.0.1",
undefined,
""
"",
req
);

expect(res.redirect).to.have.calledWith(
Expand All @@ -140,25 +137,20 @@ describe("setup-authenticator-app controller", () => {
verifyMfaCode: sinon.fake.returns({ success: true }),
} as unknown as VerifyMfaCodeInterface;

const fakeNotificationService: SendNotificationServiceInterface = {
sendNotification: sinon.fake(),
};

await setupAuthenticatorAppPost(fakeMfAService, fakeNotificationService)(
req as Request,
res as Response
);

expect(fakeMfAService.verifyMfaCode).to.have.been.calledOnce;
expect(fakeNotificationService.sendNotification).to.have.been.calledOnce;
expect(fakeNotificationService.sendNotification).to.have.calledWith(
expect(fakeNotificationService.sendNotification).to.have.calledOnceWith(
undefined,
undefined,
"[email protected]",
NOTIFICATION_TYPE.CHANGE_HOW_GET_SECURITY_CODES_CONFIRMATION,
"127.0.0.1",
undefined,
""
"",
req
);

expect(res.redirect).to.have.calledWith(
Expand All @@ -178,10 +170,6 @@ describe("setup-authenticator-app controller", () => {
}),
} as unknown as VerifyMfaCodeInterface;

const fakeNotificationService: SendNotificationServiceInterface = {
sendNotification: sinon.fake(),
};

await setupAuthenticatorAppPost(fakeMfAService, fakeNotificationService)(
req as Request,
res as Response
Expand All @@ -205,10 +193,6 @@ describe("setup-authenticator-app controller", () => {
verifyMfaCode: sinon.fake.returns({ success: true }),
} as unknown as VerifyMfaCodeInterface;

const fakeNotificationService: SendNotificationServiceInterface = {
sendNotification: sinon.fake(),
};

await setupAuthenticatorAppPost(fakeMfAService, fakeNotificationService)(
req as Request,
res as Response
Expand Down

0 comments on commit b286b7a

Please sign in to comment.