Search in sources :

Example 1 with SamlMessage

use of uk.gov.ida.hub.samlproxy.controllogic.SamlMessageSenderHandler.SamlMessage in project verify-hub by alphagov.

the class SamlMessageSenderHandlerTest method generateAuthnResponseFromHub_shouldAddExternalCommunicationEvent.

@Test
public void generateAuthnResponseFromHub_shouldAddExternalCommunicationEvent() throws Exception {
    SessionId sessionId = SessionId.createNewSessionId();
    String expectedSamlMessageId = UUID.randomUUID().toString();
    Response openSamlResponse = setUpAuthnResponseFromHub(sessionId, expectedSamlMessageId);
    SamlMessage authnResponse = samlMessageSenderHandler.generateAuthnResponseFromHub(sessionId, principalIpAddressAsSeenByHub);
    assertThat(authnResponse.getSamlMessage()).isEqualTo(samlRequest);
    assertThat(authnResponse.getPostEndpoint()).isEqualTo(postEndPoint.toString());
    assertThat(authnResponse.getRegistration().isPresent()).isFalse();
    assertThat(authnResponse.getRelayState().isPresent()).isTrue();
    assertThat(authnResponse.getRelayState().get()).isEqualTo(relayState.get());
    assertThat(authnResponse.getSamlMessageType()).isEqualTo(SamlMessageType.SAML_RESPONSE);
    verify(externalCommunicationEventLogger).logResponseFromHub(expectedSamlMessageId, sessionId, postEndPoint, principalIpAddressAsSeenByHub);
    verify(protectiveMonitoringLogger).logAuthnResponse(openSamlResponse, Direction.OUTBOUND, true);
}
Also used : Response(org.opensaml.saml.saml2.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlValidationResponse(uk.gov.ida.saml.core.validation.SamlValidationResponse) SamlMessage(uk.gov.ida.hub.samlproxy.controllogic.SamlMessageSenderHandler.SamlMessage) Matchers.anyString(org.mockito.Matchers.anyString) SessionId(uk.gov.ida.common.SessionId) Test(org.junit.Test)

Example 2 with SamlMessage

use of uk.gov.ida.hub.samlproxy.controllogic.SamlMessageSenderHandler.SamlMessage in project verify-hub by alphagov.

the class SamlMessageSenderHandlerTest method generateAuthnRequestFromHub_shouldAddExternalCommunicationEvent.

@Test
public void generateAuthnRequestFromHub_shouldAddExternalCommunicationEvent() throws Exception {
    SessionId sessionId = SessionId.createNewSessionId();
    String expectedSamlMessageId = UUID.randomUUID().toString();
    when(sessionProxy.getAuthnRequestFromHub(any(SessionId.class))).thenReturn(new AuthnRequestFromHubContainerDto(samlRequest, postEndPoint, true));
    AuthnRequest authnRequest = anAuthnRequest().withId(expectedSamlMessageId).build();
    when(authnRequestTransformer.apply(samlRequest)).thenReturn(authnRequest);
    SamlMessage authnResponse = samlMessageSenderHandler.generateAuthnRequestFromHub(sessionId, principalIpAddressAsSeenByHub);
    assertThat(authnResponse.getSamlMessage()).isEqualTo(samlRequest);
    assertThat(authnResponse.getPostEndpoint()).isEqualTo(postEndPoint.toString());
    assertThat(authnResponse.getRegistration().isPresent()).isTrue();
    assertThat(authnResponse.getRegistration().get()).isTrue();
    assertThat(authnResponse.getSamlMessageType()).isEqualTo(SamlMessageType.SAML_REQUEST);
    assertThat(authnResponse.getRelayState().isPresent()).isTrue();
    assertThat(authnResponse.getRelayState().get()).isEqualTo(sessionId.getSessionId());
    verify(externalCommunicationEventLogger).logIdpAuthnRequest(expectedSamlMessageId, sessionId, postEndPoint, principalIpAddressAsSeenByHub);
}
Also used : AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) AuthnRequestBuilder.anAuthnRequest(uk.gov.ida.saml.core.test.builders.AuthnRequestBuilder.anAuthnRequest) SamlMessage(uk.gov.ida.hub.samlproxy.controllogic.SamlMessageSenderHandler.SamlMessage) Matchers.anyString(org.mockito.Matchers.anyString) AuthnRequestFromHubContainerDto(uk.gov.ida.hub.samlproxy.domain.AuthnRequestFromHubContainerDto) SessionId(uk.gov.ida.common.SessionId) Test(org.junit.Test)

Example 3 with SamlMessage

use of uk.gov.ida.hub.samlproxy.controllogic.SamlMessageSenderHandler.SamlMessage in project verify-hub by alphagov.

the class SamlMessageSenderHandlerTest method generateErrorResponseFromHub_shouldAddExternalCommunicationEvent.

@Test
public void generateErrorResponseFromHub_shouldAddExternalCommunicationEvent() throws MarshallingException, SignatureException {
    SessionId sessionId = SessionId.createNewSessionId();
    String responseId = UUID.randomUUID().toString();
    when(sessionProxy.getErrorResponseFromHub(sessionId)).thenReturn(new AuthnResponseFromHubContainerDto(samlRequest, postEndPoint, relayState, responseId));
    Response samlResponse = setUpErrorResponseFromHub(sessionId, responseId);
    when(responseTransformer.apply(samlRequest)).thenReturn(samlResponse);
    SamlMessage samlMessage = samlMessageSenderHandler.generateErrorResponseFromHub(sessionId, principalIpAddressAsSeenByHub);
    assertThat(samlMessage.getSamlMessage()).isEqualTo(samlRequest);
    assertThat(samlMessage.getPostEndpoint()).isEqualTo(postEndPoint.toString());
    assertThat(samlMessage.getRegistration().isPresent()).isFalse();
    assertThat(samlMessage.getSamlMessageType()).isEqualTo(SamlMessageType.SAML_RESPONSE);
    assertThat(samlMessage.getRelayState().isPresent()).isTrue();
    assertThat(samlMessage.getRelayState()).isEqualTo(relayState);
    verify(externalCommunicationEventLogger).logResponseFromHub(responseId, sessionId, postEndPoint, principalIpAddressAsSeenByHub);
}
Also used : Response(org.opensaml.saml.saml2.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlValidationResponse(uk.gov.ida.saml.core.validation.SamlValidationResponse) AuthnResponseFromHubContainerDto(uk.gov.ida.hub.samlproxy.contracts.AuthnResponseFromHubContainerDto) SamlMessage(uk.gov.ida.hub.samlproxy.controllogic.SamlMessageSenderHandler.SamlMessage) Matchers.anyString(org.mockito.Matchers.anyString) SessionId(uk.gov.ida.common.SessionId) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 Matchers.anyString (org.mockito.Matchers.anyString)3 SessionId (uk.gov.ida.common.SessionId)3 SamlMessage (uk.gov.ida.hub.samlproxy.controllogic.SamlMessageSenderHandler.SamlMessage)3 Response (org.opensaml.saml.saml2.core.Response)2 ResponseBuilder.aResponse (uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse)2 SamlValidationResponse (uk.gov.ida.saml.core.validation.SamlValidationResponse)2 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)1 AuthnResponseFromHubContainerDto (uk.gov.ida.hub.samlproxy.contracts.AuthnResponseFromHubContainerDto)1 AuthnRequestFromHubContainerDto (uk.gov.ida.hub.samlproxy.domain.AuthnRequestFromHubContainerDto)1 AuthnRequestBuilder.anAuthnRequest (uk.gov.ida.saml.core.test.builders.AuthnRequestBuilder.anAuthnRequest)1