From ff62e031dab71b1dfef661c2af0f7d2ed2901693 Mon Sep 17 00:00:00 2001 From: Ryan Andrews Date: Fri, 7 Feb 2025 09:38:21 +0000 Subject: [PATCH 1/2] BAU: Rename common test var Renames test var to be INTERNAL_COMMON_SUBJECT_ID instead of just COMMON_SUBJECT_ID --- .../frontendapi/helpers/CommonTestVariables.java | 2 +- .../lambda/MfaResetAuthorizeHandlerTest.java | 10 +++++----- .../services/IPVReverificationServiceTest.java | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend-api/src/test/java/uk/gov/di/authentication/frontendapi/helpers/CommonTestVariables.java b/frontend-api/src/test/java/uk/gov/di/authentication/frontendapi/helpers/CommonTestVariables.java index 5d58ef6a80..e7f8fd4693 100644 --- a/frontend-api/src/test/java/uk/gov/di/authentication/frontendapi/helpers/CommonTestVariables.java +++ b/frontend-api/src/test/java/uk/gov/di/authentication/frontendapi/helpers/CommonTestVariables.java @@ -22,7 +22,7 @@ public class CommonTestVariables { public static final String CLIENT_SESSION_ID = "known-client-session-id"; public static final String CLIENT_NAME = "client-name"; public static final String CLIENT_ID = "client-id"; - public static final String COMMON_SUBJECT_ID = "urn:some:subject:identifier"; + public static final String INTERNAL_COMMON_SUBJECT_ID = "urn:some:subject:identifier"; public static final Map VALID_HEADERS = Map.ofEntries( Map.entry( diff --git a/frontend-api/src/test/java/uk/gov/di/authentication/frontendapi/lambda/MfaResetAuthorizeHandlerTest.java b/frontend-api/src/test/java/uk/gov/di/authentication/frontendapi/lambda/MfaResetAuthorizeHandlerTest.java index c4cea1c48f..924ddf815f 100644 --- a/frontend-api/src/test/java/uk/gov/di/authentication/frontendapi/lambda/MfaResetAuthorizeHandlerTest.java +++ b/frontend-api/src/test/java/uk/gov/di/authentication/frontendapi/lambda/MfaResetAuthorizeHandlerTest.java @@ -42,10 +42,10 @@ import static org.mockito.Mockito.when; import static uk.gov.di.authentication.frontendapi.domain.FrontendAuditableEvent.AUTH_REVERIFY_AUTHORISATION_REQUESTED; import static uk.gov.di.authentication.frontendapi.helpers.CommonTestVariables.CLIENT_SESSION_ID; -import static uk.gov.di.authentication.frontendapi.helpers.CommonTestVariables.COMMON_SUBJECT_ID; import static uk.gov.di.authentication.frontendapi.helpers.CommonTestVariables.DI_PERSISTENT_SESSION_ID; import static uk.gov.di.authentication.frontendapi.helpers.CommonTestVariables.EMAIL; import static uk.gov.di.authentication.frontendapi.helpers.CommonTestVariables.ENCODED_DEVICE_DETAILS; +import static uk.gov.di.authentication.frontendapi.helpers.CommonTestVariables.INTERNAL_COMMON_SUBJECT_ID; import static uk.gov.di.authentication.frontendapi.helpers.CommonTestVariables.IP_ADDRESS; import static uk.gov.di.authentication.frontendapi.helpers.CommonTestVariables.SESSION_ID; import static uk.gov.di.authentication.shared.entity.ErrorResponse.ERROR_1060; @@ -100,7 +100,7 @@ class MfaResetAuthorizeHandlerTest { static void globalSetup() { when(userContext.getSession()).thenReturn(new Session(SESSION_ID)); when(userContext.getClientSessionId()).thenReturn(CLIENT_SESSION_ID); - when(session.getInternalCommonSubjectIdentifier()).thenReturn(COMMON_SUBJECT_ID); + when(session.getInternalCommonSubjectIdentifier()).thenReturn(INTERNAL_COMMON_SUBJECT_ID); when(sessionService.getSessionFromRequestHeaders(anyMap())) .thenReturn(Optional.of(session)); when(session.getSessionId()).thenReturn(SESSION_ID); @@ -130,7 +130,7 @@ void returnsA200WithRedirectUriInBody() { String expectedBody = objectMapper.writeValueAsString(new MfaResetResponse(TEST_REDIRECT_URI)); when(ipvReverificationService.buildIpvReverificationRedirectUri( - eq(new Subject(COMMON_SUBJECT_ID)), eq(CLIENT_SESSION_ID), any())) + eq(new Subject(INTERNAL_COMMON_SUBJECT_ID)), eq(CLIENT_SESSION_ID), any())) .thenReturn(TEST_REDIRECT_URI); APIGatewayProxyResponseEvent response = handler.handleRequest(TEST_INVOKE_EVENT, context); @@ -161,7 +161,7 @@ void storesTheStateValuesForCrossBrowserIssue() { @Test void returnsA500WithErrorMessageWhenServiceThrowsJwtServiceException() { when(ipvReverificationService.buildIpvReverificationRedirectUri( - eq(new Subject(COMMON_SUBJECT_ID)), eq(CLIENT_SESSION_ID), any())) + eq(new Subject(INTERNAL_COMMON_SUBJECT_ID)), eq(CLIENT_SESSION_ID), any())) .thenThrow(new JwtServiceException("SomeError")); APIGatewayProxyResponseEvent response = handler.handleRequest(TEST_INVOKE_EVENT, context); @@ -173,7 +173,7 @@ void returnsA500WithErrorMessageWhenServiceThrowsJwtServiceException() { @Test void returns500WithErrorMessageWhenIpvReverificationServiceExceptionIsThrown() { when(ipvReverificationService.buildIpvReverificationRedirectUri( - eq(new Subject(COMMON_SUBJECT_ID)), eq(CLIENT_SESSION_ID), any())) + eq(new Subject(INTERNAL_COMMON_SUBJECT_ID)), eq(CLIENT_SESSION_ID), any())) .thenThrow(new IPVReverificationServiceException("SomeError")); APIGatewayProxyResponseEvent response = handler.handleRequest(TEST_INVOKE_EVENT, context); diff --git a/frontend-api/src/test/java/uk/gov/di/authentication/frontendapi/services/IPVReverificationServiceTest.java b/frontend-api/src/test/java/uk/gov/di/authentication/frontendapi/services/IPVReverificationServiceTest.java index 9d1bf5e4d5..299bde7172 100644 --- a/frontend-api/src/test/java/uk/gov/di/authentication/frontendapi/services/IPVReverificationServiceTest.java +++ b/frontend-api/src/test/java/uk/gov/di/authentication/frontendapi/services/IPVReverificationServiceTest.java @@ -58,7 +58,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static uk.gov.di.authentication.frontendapi.helpers.CommonTestVariables.COMMON_SUBJECT_ID; +import static uk.gov.di.authentication.frontendapi.helpers.CommonTestVariables.INTERNAL_COMMON_SUBJECT_ID; import static uk.gov.di.authentication.sharedtest.helper.KeyPairHelper.GENERATE_RSA_KEY_PAIR; class IPVReverificationServiceTest { @@ -68,7 +68,7 @@ class IPVReverificationServiceTest { private static final String TEST_STATE_VALUE = "testState"; public static final State STATE = State.parse(TEST_STATE_VALUE); private static final String TEST_CLIENT_SESSION_ID = "journeyId"; - private static final Subject TEST_SUBJECT = new Subject(COMMON_SUBJECT_ID); + private static final Subject TEST_SUBJECT = new Subject(INTERNAL_COMMON_SUBJECT_ID); private static final String TEST_AUDIENCE_CLAIM = "someAud"; private static final String TEST_ISSUER_CLAIM = "someIssuer"; private static final String TEST_UUID = "someSuperUniqueUUID"; From 5d7fd633633e0956ec42da4814ed2b7951a001ab Mon Sep 17 00:00:00 2001 From: Ryan Andrews Date: Fri, 7 Feb 2025 09:44:43 +0000 Subject: [PATCH 2/2] ATO-1322: Replace getter in account interventions Also makes use of the renamed common test variable to make this clearer --- .../lambda/AccountInterventionsHandler.java | 2 +- .../AccountInterventionsHandlerTest.java | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/frontend-api/src/main/java/uk/gov/di/authentication/frontendapi/lambda/AccountInterventionsHandler.java b/frontend-api/src/main/java/uk/gov/di/authentication/frontendapi/lambda/AccountInterventionsHandler.java index 4d1f32dc97..9ea1f121cb 100644 --- a/frontend-api/src/main/java/uk/gov/di/authentication/frontendapi/lambda/AccountInterventionsHandler.java +++ b/frontend-api/src/main/java/uk/gov/di/authentication/frontendapi/lambda/AccountInterventionsHandler.java @@ -325,7 +325,7 @@ private void submitAuditEvents( var auditContext = auditContextFromUserContext( userContext, - userContext.getSession().getInternalCommonSubjectIdentifier(), + userContext.getAuthSession().getInternalCommonSubjectId(), userContext.getSession().getEmailAddress(), IpAddressHelper.extractIpAddress(input), userContext diff --git a/frontend-api/src/test/java/uk/gov/di/authentication/frontendapi/lambda/AccountInterventionsHandlerTest.java b/frontend-api/src/test/java/uk/gov/di/authentication/frontendapi/lambda/AccountInterventionsHandlerTest.java index 9d93a44042..6874cf1bb4 100644 --- a/frontend-api/src/test/java/uk/gov/di/authentication/frontendapi/lambda/AccountInterventionsHandlerTest.java +++ b/frontend-api/src/test/java/uk/gov/di/authentication/frontendapi/lambda/AccountInterventionsHandlerTest.java @@ -77,13 +77,14 @@ import static uk.gov.di.authentication.frontendapi.domain.FrontendAuditableEvent.AUTH_TEMP_SUSPENDED_INTERVENTION; import static uk.gov.di.authentication.frontendapi.helpers.CommonTestVariables.CLIENT_NAME; import static uk.gov.di.authentication.frontendapi.helpers.CommonTestVariables.EMAIL; +import static uk.gov.di.authentication.frontendapi.helpers.CommonTestVariables.INTERNAL_COMMON_SUBJECT_ID; import static uk.gov.di.authentication.frontendapi.helpers.CommonTestVariables.SESSION_ID; +import static uk.gov.di.authentication.frontendapi.lambda.LoginHandler.INTERNAL_SUBJECT_ID; import static uk.gov.di.authentication.sharedtest.matchers.APIGatewayProxyResponseEventMatcher.hasBody; import static uk.gov.di.authentication.sharedtest.matchers.APIGatewayProxyResponseEventMatcher.hasStatus; class AccountInterventionsHandlerTest { private static final String TEST_CLIENT_ID = "test_client_id"; - private static final String TEST_INTERNAL_SUBJECT_ID = "test-internal-subject-id"; private static final String TEST_SUBJECT_ID = "subject-id"; private static final String INTERNAL_SECTOR_URI = "https://test.account.gov.uk"; private static final String TEST_ENVIRONMENT = "test-environment"; @@ -113,22 +114,25 @@ class AccountInterventionsHandlerTest { private final CloudwatchMetricsService cloudwatchMetricsService = mock(CloudwatchMetricsService.class); private final LambdaInvokerService mockLambdaInvokerService = mock(LambdaInvokerService.class); - private final AuthSessionService mockAuthSessionService = mock(AuthSessionService.class); + private final AuthSessionService authSessionService = mock(AuthSessionService.class); private static final ClientSession clientSession = getClientSession(); private final Session session = new Session(SESSION_ID) .setEmailAddress(EMAIL) .setSessionId(SESSION_ID) - .setInternalCommonSubjectIdentifier(TEST_INTERNAL_SUBJECT_ID); - private final AuthSessionItem authSession = new AuthSessionItem().withSessionId(SESSION_ID); + .setInternalCommonSubjectIdentifier(INTERNAL_COMMON_SUBJECT_ID); + private final AuthSessionItem authSession = + new AuthSessionItem() + .withSessionId(SESSION_ID) + .withInternalCommonSubjectId(INTERNAL_SUBJECT_ID); private static final AuditContext AUDIT_CONTEXT = new AuditContext( CommonTestVariables.CLIENT_ID, CommonTestVariables.CLIENT_SESSION_ID, CommonTestVariables.SESSION_ID, - TEST_INTERNAL_SUBJECT_ID, + INTERNAL_SUBJECT_ID, EMAIL, CommonTestVariables.IP_ADDRESS, AuditService.UNKNOWN, @@ -141,7 +145,7 @@ void setUp() throws URISyntaxException { when(context.getAwsRequestId()).thenReturn("aws-session-id"); when(sessionService.getSessionFromRequestHeaders(anyMap())) .thenReturn(Optional.of(session)); - when(mockAuthSessionService.getSessionFromRequestHeaders(anyMap())) + when(authSessionService.getSessionFromRequestHeaders(anyMap())) .thenReturn(Optional.of(authSession)); UserProfile userProfile = generateUserProfile(); when(authenticationService.getUserProfileByEmailMaybe(EMAIL)) @@ -154,6 +158,7 @@ void setUp() throws URISyntaxException { .thenReturn(new URI("https://account-interventions.gov.uk/v1")); when(configurationService.getAwsRegion()).thenReturn("eu-west-2"); when(userContext.getSession()).thenReturn(session); + when(userContext.getAuthSession()).thenReturn(authSession); when(userContext.getClientSession()).thenReturn(clientSession); when(userContext.getClientId()).thenReturn(CommonTestVariables.CLIENT_ID); when(userContext.getClientSessionId()).thenReturn(CommonTestVariables.CLIENT_SESSION_ID); @@ -175,7 +180,7 @@ void setUp() throws URISyntaxException { cloudwatchMetricsService, new NowHelper.NowClock(fixed(fixedDate, systemDefault())), mockLambdaInvokerService, - mockAuthSessionService); + authSessionService); } @Test