Search in sources :

Example 6 with EventDetailsKey

use of uk.gov.ida.eventsink.EventDetailsKey in project verify-hub by alphagov.

the class HealthCheckEventLoggerTest method shouldLogToEventSinkIfTheExceptionIsUnaudited.

@Test
public void shouldLogToEventSinkIfTheExceptionIsUnaudited() {
    URI uri = URI.create("uri-geller");
    ApplicationException unauditedException = ApplicationException.createUnauditedException(ExceptionType.INVALID_SAML, UUID.randomUUID(), uri);
    ImmutableMap<EventDetailsKey, String> details = ImmutableMap.of(downstream_uri, unauditedException.getUri().or(URI.create("uri-not-present")).toASCIIString(), message, unauditedException.getMessage());
    EventSinkHubEvent event = new EventSinkHubEvent(serviceInfo, NO_SESSION_CONTEXT_IN_ERROR, ERROR_EVENT, details);
    eventLogger.logException(unauditedException, "test error message");
    ArgumentCaptor<EventSinkHubEvent> eventSinkCaptor = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    ArgumentCaptor<EventSinkHubEvent> eventEmitterCaptor = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    verify(eventSinkProxy, times(1)).logHubEvent(eventSinkCaptor.capture());
    verify(eventEmitter, times(1)).record(eventEmitterCaptor.capture());
    assertThat(event).isEqualToComparingOnlyGivenFields(eventSinkCaptor.getValue(), "originatingService", "sessionId", "eventType", "details");
    assertThat(event).isEqualToComparingOnlyGivenFields(eventEmitterCaptor.getValue(), "originatingService", "sessionId", "eventType", "details");
}
Also used : ApplicationException(uk.gov.ida.exceptions.ApplicationException) EventDetailsKey(uk.gov.ida.eventsink.EventDetailsKey) URI(java.net.URI) EventSinkHubEvent(uk.gov.ida.eventsink.EventSinkHubEvent) Test(org.junit.Test)

Example 7 with EventDetailsKey

use of uk.gov.ida.eventsink.EventDetailsKey in project verify-hub by alphagov.

the class HubEventLogger method logRequestFromHub.

public void logRequestFromHub(SessionId sessionId, String transactionEntityId) {
    Map<EventDetailsKey, String> details = new HashMap<>();
    details.put(hub_event_type, RECEIVED_AUTHN_REQUEST_FROM_HUB);
    details.put(transaction_entity_id, transactionEntityId);
    EventSinkHubEvent eventSinkHubEvent = new EventSinkHubEvent(serviceInfo, sessionId, HUB_EVENT, details);
    eventSinkProxy.logHubEvent(eventSinkHubEvent);
    eventEmitter.record(eventSinkHubEvent);
}
Also used : HashMap(java.util.HashMap) EventDetailsKey(uk.gov.ida.eventsink.EventDetailsKey) EventSinkHubEvent(uk.gov.ida.hub.policy.domain.EventSinkHubEvent)

Example 8 with EventDetailsKey

use of uk.gov.ida.eventsink.EventDetailsKey in project verify-hub by alphagov.

the class HubEventLogger method logSessionTimeoutEvent.

public void logSessionTimeoutEvent(SessionId sessionId, DateTime sessionExpiryTimestamp, String transactionEntityId, String requestId) {
    Map<EventDetailsKey, String> details = new HashMap<>();
    details.put(session_event_type, SESSION_TIMEOUT);
    details.put(session_expiry_time, sessionExpiryTimestamp.toString());
    details.put(transaction_entity_id, transactionEntityId);
    details.put(request_id, requestId);
    EventSinkHubEvent eventSinkHubEvent = new EventSinkHubEvent(serviceInfo, sessionId, SESSION_EVENT, details);
    eventSinkProxy.logHubEvent(eventSinkHubEvent);
    eventEmitter.record(eventSinkHubEvent);
}
Also used : HashMap(java.util.HashMap) EventDetailsKey(uk.gov.ida.eventsink.EventDetailsKey) EventSinkHubEvent(uk.gov.ida.hub.policy.domain.EventSinkHubEvent)

Example 9 with EventDetailsKey

use of uk.gov.ida.eventsink.EventDetailsKey in project verify-hub by alphagov.

the class HubEventLoggerTest method logIdpSelectedEvent_shouldLogEventWithIdpSelected.

@Test
public void logIdpSelectedEvent_shouldLogEventWithIdpSelected() {
    final IdpSelectedState state = IdpSelectedStateBuilder.anIdpSelectedState().withLevelsOfAssurance(Arrays.asList(LevelOfAssurance.LEVEL_1, LevelOfAssurance.LEVEL_2)).withSessionExpiryTimestamp(SESSION_EXPIRY_TIMESTAMP).withIdpEntityId(IDP_ENTITY_ID).withRequestIssuerEntityId(TRANSACTION_ENTITY_ID).withRequestId(REQUEST_ID).withSessionId(SESSION_ID).build();
    eventLogger.logIdpSelectedEvent(state, PRINCIPAL_IP_ADDRESS_SEEN_BY_HUB);
    final Map<EventDetailsKey, String> details = Maps.newHashMap();
    details.put(session_event_type, IDP_SELECTED);
    details.put(idp_entity_id, IDP_ENTITY_ID);
    details.put(principal_ip_address_as_seen_by_hub, PRINCIPAL_IP_ADDRESS_SEEN_BY_HUB);
    details.put(minimum_level_of_assurance, MINIMUM_LEVEL_OF_ASSURANCE.name());
    details.put(required_level_of_assurance, REQUIRED_LEVEL_OF_ASSURANCE.name());
    final EventSinkHubEvent expectedEvent = createExpectedEventSinkHubEvent(details);
    verify(eventSinkProxy).logHubEvent(argThat(new EventMatching(expectedEvent)));
    verify(eventEmitter).record(argThat(new EventMatching(expectedEvent)));
}
Also used : EventDetailsKey(uk.gov.ida.eventsink.EventDetailsKey) IdpSelectedState(uk.gov.ida.hub.policy.domain.state.IdpSelectedState) EventSinkHubEvent(uk.gov.ida.hub.policy.domain.EventSinkHubEvent) Test(org.junit.Test)

Example 10 with EventDetailsKey

use of uk.gov.ida.eventsink.EventDetailsKey in project verify-hub by alphagov.

the class HubEventLoggerTest method logIdpAuthnSucceededEvent_shouldContainLevelsOfAssuranceInDetailsFieldForBilling.

@Test
public void logIdpAuthnSucceededEvent_shouldContainLevelsOfAssuranceInDetailsFieldForBilling() {
    eventLogger.logIdpAuthnSucceededEvent(SESSION_ID, SESSION_EXPIRY_TIMESTAMP, IDP_ENTITY_ID, TRANSACTION_ENTITY_ID, PERSISTENT_ID, REQUEST_ID, MINIMUM_LEVEL_OF_ASSURANCE, REQUIRED_LEVEL_OF_ASSURANCE, PROVIDED_LEVEL_OF_ASSURANCE, Optional.fromNullable(PRINCIPAL_IP_ADDRESS_SEEN_BY_IDP), PRINCIPAL_IP_ADDRESS_SEEN_BY_HUB);
    final Map<EventDetailsKey, String> details = Maps.newHashMap();
    details.put(idp_entity_id, IDP_ENTITY_ID);
    details.put(pid, PERSISTENT_ID.getNameId());
    details.put(minimum_level_of_assurance, MINIMUM_LEVEL_OF_ASSURANCE.name());
    details.put(required_level_of_assurance, REQUIRED_LEVEL_OF_ASSURANCE.name());
    details.put(provided_level_of_assurance, PROVIDED_LEVEL_OF_ASSURANCE.name());
    details.put(principal_ip_address_as_seen_by_idp, PRINCIPAL_IP_ADDRESS_SEEN_BY_IDP);
    details.put(principal_ip_address_as_seen_by_hub, PRINCIPAL_IP_ADDRESS_SEEN_BY_HUB);
    details.put(session_event_type, IDP_AUTHN_SUCCEEDED);
    final EventSinkHubEvent expectedEvent = createExpectedEventSinkHubEvent(details);
    verify(eventSinkProxy).logHubEvent(argThat(new EventMatching(expectedEvent)));
    verify(eventEmitter).record(argThat(new EventMatching(expectedEvent)));
}
Also used : EventDetailsKey(uk.gov.ida.eventsink.EventDetailsKey) EventSinkHubEvent(uk.gov.ida.hub.policy.domain.EventSinkHubEvent) Test(org.junit.Test)

Aggregations

EventDetailsKey (uk.gov.ida.eventsink.EventDetailsKey)28 Test (org.junit.Test)23 EventSinkHubEvent (uk.gov.ida.hub.policy.domain.EventSinkHubEvent)18 EventSinkHubEvent (uk.gov.ida.eventsink.EventSinkHubEvent)10 HashMap (java.util.HashMap)5 URI (java.net.URI)1 UUID (java.util.UUID)1 ApplicationException (uk.gov.ida.exceptions.ApplicationException)1 FraudDetectedDetailsBuilder.aFraudDetectedDetails (uk.gov.ida.hub.policy.builder.domain.FraudDetectedDetailsBuilder.aFraudDetectedDetails)1 SamlResponseWithAuthnRequestInformationDto (uk.gov.ida.hub.policy.contracts.SamlResponseWithAuthnRequestInformationDto)1 FraudDetectedDetails (uk.gov.ida.hub.policy.domain.FraudDetectedDetails)1 IdpSelectedState (uk.gov.ida.hub.policy.domain.state.IdpSelectedState)1 SamlResponseWithAuthnRequestInformationDtoBuilder.aSamlResponseWithAuthnRequestInformationDto (uk.gov.ida.hub.policy.proxy.SamlResponseWithAuthnRequestInformationDtoBuilder.aSamlResponseWithAuthnRequestInformationDto)1