Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ATO-1322: Swap getter in AccountInterventionsHandler #5886

Draft
wants to merge 2 commits into
base: ATO-1284-update-base-frontend-handler
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private void submitAuditEvents(
var auditContext =
auditContextFromUserContext(
userContext,
userContext.getSession().getInternalCommonSubjectIdentifier(),
userContext.getAuthSession().getInternalCommonSubjectId(),
userContext.getSession().getEmailAddress(),
IpAddressHelper.extractIpAddress(input),
userContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> VALID_HEADERS =
Map.ofEntries(
Map.entry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand All @@ -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))
Expand All @@ -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);
Expand All @@ -175,7 +180,7 @@ void setUp() throws URISyntaxException {
cloudwatchMetricsService,
new NowHelper.NowClock(fixed(fixedDate, systemDefault())),
mockLambdaInvokerService,
mockAuthSessionService);
authSessionService);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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";
Expand Down
Loading