Search in sources :

Example 1 with SamlResponseWithAuthnRequestInformationDto

use of uk.gov.ida.hub.policy.contracts.SamlResponseWithAuthnRequestInformationDto in project verify-hub by alphagov.

the class AuthnRequestFromTransactionHandlerTest method testHandleRequestFromTransaction_logsToEventSink.

@Test
public void testHandleRequestFromTransaction_logsToEventSink() {
    final SamlResponseWithAuthnRequestInformationDto samlResponseWithAuthnRequestInformationDto = SamlResponseWithAuthnRequestInformationDtoBuilder.aSamlResponseWithAuthnRequestInformationDto().build();
    final String ipAddress = "ipaddress";
    final URI assertionConsumerServiceUri = URI.create("blah");
    final Optional<String> relayState = Optional.of("relaystate");
    when(policyConfiguration.getSessionLength()).thenReturn(Duration.standardHours(1));
    when(transactionsConfigProxy.getLevelsOfAssurance(samlResponseWithAuthnRequestInformationDto.getIssuer())).thenReturn(asList(LevelOfAssurance.LEVEL_1, LevelOfAssurance.LEVEL_1));
    authnRequestFromTransactionHandler.handleRequestFromTransaction(samlResponseWithAuthnRequestInformationDto, relayState, ipAddress, assertionConsumerServiceUri, false);
    verify(hubEventLogger, times(1)).logSessionStartedEvent(Matchers.<SamlResponseWithAuthnRequestInformationDto>any(), anyString(), Matchers.<DateTime>any(), Matchers.<SessionId>any(), Matchers.<LevelOfAssurance>any(), Matchers.<LevelOfAssurance>any());
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) SamlResponseWithAuthnRequestInformationDto(uk.gov.ida.hub.policy.contracts.SamlResponseWithAuthnRequestInformationDto) URI(java.net.URI) Test(org.junit.Test)

Example 2 with SamlResponseWithAuthnRequestInformationDto

use of uk.gov.ida.hub.policy.contracts.SamlResponseWithAuthnRequestInformationDto in project verify-hub by alphagov.

the class HubEventLoggerTest method logSessionOpenEvent_shouldSendEvent.

@Test
public void logSessionOpenEvent_shouldSendEvent() {
    final SamlResponseWithAuthnRequestInformationDto samlResponse = aSamlResponseWithAuthnRequestInformationDto().withId(REQUEST_ID).withIssuer(TRANSACTION_ENTITY_ID).build();
    eventLogger.logSessionStartedEvent(samlResponse, PRINCIPAL_IP_ADDRESS_SEEN_BY_HUB, SESSION_EXPIRY_TIMESTAMP, SESSION_ID, MINIMUM_LEVEL_OF_ASSURANCE, REQUIRED_LEVEL_OF_ASSURANCE);
    final Map<EventDetailsKey, String> details = new HashMap<>();
    details.put(principal_ip_address_as_seen_by_hub, PRINCIPAL_IP_ADDRESS_SEEN_BY_HUB);
    details.put(message_id, samlResponse.getId());
    details.put(minimum_level_of_assurance, MINIMUM_LEVEL_OF_ASSURANCE.name());
    details.put(required_level_of_assurance, REQUIRED_LEVEL_OF_ASSURANCE.name());
    details.put(session_event_type, SESSION_STARTED);
    final EventSinkHubEvent expectedEvent = createExpectedEventSinkHubEvent(details);
    verify(eventSinkProxy).logHubEvent(argThat(new EventMatching(expectedEvent)));
    verify(eventEmitter).record(argThat(new EventMatching(expectedEvent)));
}
Also used : HashMap(java.util.HashMap) EventDetailsKey(uk.gov.ida.eventsink.EventDetailsKey) SamlResponseWithAuthnRequestInformationDtoBuilder.aSamlResponseWithAuthnRequestInformationDto(uk.gov.ida.hub.policy.proxy.SamlResponseWithAuthnRequestInformationDtoBuilder.aSamlResponseWithAuthnRequestInformationDto) SamlResponseWithAuthnRequestInformationDto(uk.gov.ida.hub.policy.contracts.SamlResponseWithAuthnRequestInformationDto) EventSinkHubEvent(uk.gov.ida.hub.policy.domain.EventSinkHubEvent) Test(org.junit.Test)

Example 3 with SamlResponseWithAuthnRequestInformationDto

use of uk.gov.ida.hub.policy.contracts.SamlResponseWithAuthnRequestInformationDto in project verify-hub by alphagov.

the class SessionTimeoutIntegrationTests method setUp.

@Before
public void setUp() throws Exception {
    SamlResponseWithAuthnRequestInformationDto samlResponse = SamlResponseWithAuthnRequestInformationDtoBuilder.aSamlResponseWithAuthnRequestInformationDto().withIssuer(THE_TX_ID).build();
    samlRequest = SamlAuthnRequestContainerDtoBuilder.aSamlAuthnRequestContainerDto().build();
    samlEngineStub.setupStubForAuthnRequestTranslate(samlResponse);
    configStub.setUpStubForLevelsOfAssurance(samlResponse.getIssuer());
    eventSinkStub.setupStubForLogging();
    configStub.setUpStubForAssertionConsumerServiceUri(samlResponse.getIssuer());
    configStub.setupStubForEidasEnabledForTransaction(THE_TX_ID, false);
}
Also used : SamlResponseWithAuthnRequestInformationDto(uk.gov.ida.hub.policy.contracts.SamlResponseWithAuthnRequestInformationDto) Before(org.junit.Before)

Example 4 with SamlResponseWithAuthnRequestInformationDto

use of uk.gov.ida.hub.policy.contracts.SamlResponseWithAuthnRequestInformationDto in project verify-hub by alphagov.

the class SessionServiceTest method shouldThrowSessionCreationFailureExceptionIfProvidedAssertionConsumerServiceUrlDoesntMatch.

@Test(expected = SessionCreationFailureException.class)
public void shouldThrowSessionCreationFailureExceptionIfProvidedAssertionConsumerServiceUrlDoesntMatch() throws Exception {
    SamlResponseWithAuthnRequestInformationDto samlResponse = aSamlResponseWithAuthnRequestInformationDto().withAssertionConsumerServiceUrl(URI.create("http://wrongurl")).build();
    URI assertionConsumerServiceUri = UriBuilder.fromUri(UUID.randomUUID().toString()).build();
    final SessionId sessionId = SessionIdBuilder.aSessionId().with("coffee-pasta").build();
    givenSamlEngineTranslatesRequest(samlResponse);
    givenConfigReturnsAssertionConsumerServiceURLFor(samlResponse, assertionConsumerServiceUri);
    givenSessionIsCreated(samlResponse, assertionConsumerServiceUri, sessionId, false);
    service.create(requestDto);
}
Also used : SamlResponseWithAuthnRequestInformationDtoBuilder.aSamlResponseWithAuthnRequestInformationDto(uk.gov.ida.hub.policy.proxy.SamlResponseWithAuthnRequestInformationDtoBuilder.aSamlResponseWithAuthnRequestInformationDto) SamlResponseWithAuthnRequestInformationDto(uk.gov.ida.hub.policy.contracts.SamlResponseWithAuthnRequestInformationDto) URI(java.net.URI) SessionId(uk.gov.ida.hub.policy.domain.SessionId) SessionId.createNewSessionId(uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId) Test(org.junit.Test)

Example 5 with SamlResponseWithAuthnRequestInformationDto

use of uk.gov.ida.hub.policy.contracts.SamlResponseWithAuthnRequestInformationDto in project verify-hub by alphagov.

the class SessionServiceTest method shouldCreateSessionWithTransactionSupportsEidas.

@Test
public void shouldCreateSessionWithTransactionSupportsEidas() throws Exception {
    // Given
    URI assertionConsumerServiceUri = UriBuilder.fromUri(UUID.randomUUID().toString()).build();
    SamlResponseWithAuthnRequestInformationDto samlResponse = aSamlResponseWithAuthnRequestInformationDto().build();
    final SessionId sessionId = SessionIdBuilder.aSessionId().with("coffee-pasta").build();
    givenSamlEngineTranslatesRequest(samlResponse);
    givenConfigReturnsAssertionConsumerServiceURLFor(samlResponse, assertionConsumerServiceUri);
    givenConfigReturnsTransactionSupportsEidas(samlResponse, true);
    givenSessionIsCreated(samlResponse, assertionConsumerServiceUri, sessionId, true);
    // When
    SessionId result = service.create(requestDto);
    // Then
    assertThat(result, is(sessionId));
    verify(authnRequestHandler).handleRequestFromTransaction(samlResponse, requestDto.getRelayState(), requestDto.getPrincipalIPAddressAsSeenByHub(), assertionConsumerServiceUri, true);
}
Also used : URI(java.net.URI) SamlResponseWithAuthnRequestInformationDtoBuilder.aSamlResponseWithAuthnRequestInformationDto(uk.gov.ida.hub.policy.proxy.SamlResponseWithAuthnRequestInformationDtoBuilder.aSamlResponseWithAuthnRequestInformationDto) SamlResponseWithAuthnRequestInformationDto(uk.gov.ida.hub.policy.contracts.SamlResponseWithAuthnRequestInformationDto) SessionId(uk.gov.ida.hub.policy.domain.SessionId) SessionId.createNewSessionId(uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId) Test(org.junit.Test)

Aggregations

SamlResponseWithAuthnRequestInformationDto (uk.gov.ida.hub.policy.contracts.SamlResponseWithAuthnRequestInformationDto)9 Test (org.junit.Test)7 URI (java.net.URI)6 SamlResponseWithAuthnRequestInformationDtoBuilder.aSamlResponseWithAuthnRequestInformationDto (uk.gov.ida.hub.policy.proxy.SamlResponseWithAuthnRequestInformationDtoBuilder.aSamlResponseWithAuthnRequestInformationDto)6 SessionId (uk.gov.ida.hub.policy.domain.SessionId)4 SessionId.createNewSessionId (uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId)4 HashMap (java.util.HashMap)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1 EventDetailsKey (uk.gov.ida.eventsink.EventDetailsKey)1 EventSinkHubEvent (uk.gov.ida.hub.policy.domain.EventSinkHubEvent)1