Search in sources :

Example 11 with SessionId

use of uk.gov.ida.common.SessionId in project verify-hub by alphagov.

the class SamlProxySamlTransformationErrorExceptionMapperTest method shouldLogToEventSinkWhenExceptionHasContextAndSessionId.

@Test
public void shouldLogToEventSinkWhenExceptionHasContextAndSessionId() throws Exception {
    TestSamlTransformationErrorException exception = new TestSamlTransformationErrorException("error", new RuntimeException(), Level.DEBUG);
    SessionId sessionId = SessionId.createNewSessionId();
    when(httpServletRequest.getParameter(Urls.SharedUrls.SESSION_ID_PARAM)).thenReturn(sessionId.getSessionId());
    exceptionMapper.handleException(exception);
    verify(eventSinkMessageSender).audit(eq(exception), any(UUID.class), eq(sessionId));
}
Also used : UUID(java.util.UUID) SessionId(uk.gov.ida.common.SessionId) Test(org.junit.Test)

Example 12 with SessionId

use of uk.gov.ida.common.SessionId in project verify-hub by alphagov.

the class AttributeQueryRequestRunnableTest method run_shouldNotSendResponse_IfAttributeQueryHasTimedOut_AfterSendingMessage.

@Test
public void run_shouldNotSendResponse_IfAttributeQueryHasTimedOut_AfterSendingMessage() throws Exception {
    final Element matchingServiceResponse = XmlUtils.convertToElement("<someResponse/>");
    when(executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto)).thenReturn(matchingServiceResponse);
    doNothing().doThrow(new AttributeQueryTimeoutException()).when(timeoutEvaluator).hasAttributeQueryTimedOut(attributeQueryContainerDto);
    attributeQueryRequestRunnable.run();
    verify(executeAttributeQueryRequest).execute(sessionId, attributeQueryContainerDto);
    verify(hubMatchingServiceResponseReceiverProxy, never()).notifyHubOfAResponseFromMatchingService(any(SessionId.class), any(String.class));
    verify(eventSinkProxy, times(1)).logHubEvent(isA(EventSinkHubEvent.class));
    verify(eventEmitter, times(1)).record(isA(EventSinkHubEvent.class));
}
Also used : Element(org.w3c.dom.Element) AttributeQueryTimeoutException(uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException) SessionId(uk.gov.ida.common.SessionId) EventSinkHubEvent(uk.gov.ida.eventsink.EventSinkHubEvent) Test(org.junit.Test)

Example 13 with SessionId

use of uk.gov.ida.common.SessionId in project verify-hub by alphagov.

the class ExecuteAttributeQueryRequestTest method run_shouldCallSamlMessageSignatureValidatorWithRequest.

@Test
public void run_shouldCallSamlMessageSignatureValidatorWithRequest() throws Exception {
    when(attributeQueryRequestClient.sendQuery(any(Element.class), anyString(), any(SessionId.class), any(URI.class))).thenReturn(matchingServiceResponse);
    Response response = aResponse().build();
    when(elementToResponseTransformer.apply(matchingServiceResponse)).thenReturn(response);
    executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto);
    verify(matchingRequestSignatureValidator).validate(attributeQuery, AttributeAuthorityDescriptor.DEFAULT_ELEMENT_NAME);
}
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) Element(org.w3c.dom.Element) SessionId(uk.gov.ida.common.SessionId) URI(java.net.URI) Test(org.junit.Test)

Example 14 with SessionId

use of uk.gov.ida.common.SessionId in project verify-hub by alphagov.

the class ExecuteAttributeQueryRequestTest method run_shouldLogStatusMessageIfItExists.

@Test
public void run_shouldLogStatusMessageIfItExists() throws MarshallingException, SignatureException {
    final Element matchingServiceResponse = mock(Element.class);
    when(attributeQueryRequestClient.sendQuery(any(Element.class), anyString(), any(SessionId.class), any(URI.class))).thenReturn(matchingServiceResponse);
    String message = "Some message";
    StatusMessage statusMessage = StatusMessageBuilder.aStatusMessage().withMessage(message).build();
    Response response = aResponse().withStatus(StatusBuilder.aStatus().withMessage(statusMessage).build()).build();
    when(elementToResponseTransformer.apply(matchingServiceResponse)).thenReturn(response);
    executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto);
    verify(protectiveMonitoringLogger).logAttributeQueryResponse(response.getID(), response.getInResponseTo(), response.getIssuer().getValue(), true, response.getStatus().getStatusCode().getValue(), message);
}
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) Element(org.w3c.dom.Element) Matchers.anyString(org.mockito.Matchers.anyString) SessionId(uk.gov.ida.common.SessionId) URI(java.net.URI) StatusMessage(org.opensaml.saml.saml2.core.StatusMessage) Test(org.junit.Test)

Example 15 with SessionId

use of uk.gov.ida.common.SessionId in project verify-hub by alphagov.

the class ExecuteAttributeQueryRequestTest method run_shouldLogProtectiveMonitoringCorrectly.

@Test
public void run_shouldLogProtectiveMonitoringCorrectly() throws Exception {
    final Element matchingServiceResponse = mock(Element.class);
    when(attributeQueryRequestClient.sendQuery(any(Element.class), anyString(), any(SessionId.class), any(URI.class))).thenReturn(matchingServiceResponse);
    Response response = aResponse().build();
    when(elementToResponseTransformer.apply(matchingServiceResponse)).thenReturn(response);
    executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto);
    verify(protectiveMonitoringLogger).logAttributeQuery(attributeQuery.getID(), attributeQueryContainerDto.getMatchingServiceUri().toASCIIString(), attributeQuery.getIssuer().getValue(), true);
    verify(protectiveMonitoringLogger).logAttributeQueryResponse(response.getID(), response.getInResponseTo(), response.getIssuer().getValue(), true, response.getStatus().getStatusCode().getValue(), "");
}
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) Element(org.w3c.dom.Element) SessionId(uk.gov.ida.common.SessionId) URI(java.net.URI) Test(org.junit.Test)

Aggregations

SessionId (uk.gov.ida.common.SessionId)39 Test (org.junit.Test)32 URI (java.net.URI)17 ResponseBuilder.aResponse (uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse)15 SamlValidationResponse (uk.gov.ida.saml.core.validation.SamlValidationResponse)15 Response (javax.ws.rs.core.Response)12 Response (org.opensaml.saml.saml2.core.Response)12 Element (org.w3c.dom.Element)10 Matchers.anyString (org.mockito.Matchers.anyString)7 AuthnResponseFromHubContainerDto (uk.gov.ida.hub.samlproxy.contracts.AuthnResponseFromHubContainerDto)6 SamlRequestDto (uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto)5 OutboundResponseFromHub (uk.gov.ida.saml.core.domain.OutboundResponseFromHub)5 ResponseActionDto (uk.gov.ida.hub.samlproxy.domain.ResponseActionDto)4 HubTransformersFactory (uk.gov.ida.saml.hub.api.HubTransformersFactory)4 Timed (com.codahale.metrics.annotation.Timed)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Produces (javax.ws.rs.Produces)3 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)3 SamlMessage (uk.gov.ida.hub.samlproxy.controllogic.SamlMessageSenderHandler.SamlMessage)3