Search in sources :

Example 36 with SessionId

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

the class MatchingServiceRequestSenderTest method sendHubMatchingServiceRequest_shouldErrorIfRequestIsBad_wrongIssuer.

// When a bad request is made, it is nevertheless accepted - these bad requests are unit tested in
// AttributeQueryRequestRunnableTest
// So, this test is probably of dubious value but probably worth keeping given we have already spun up the
// SamlSoapProxyAppRule
@Test
public void sendHubMatchingServiceRequest_shouldErrorIfRequestIsBad_wrongIssuer() {
    AttributeQueryContainerDto attributeQueryContainerDto = AttributeQueryContainerDtoBuilder.anAttributeQueryContainerDto(AttributeQueryBuilder.anAttributeQuery().withIssuer(IssuerBuilder.anIssuer().withIssuerId(HUB_ENTITY_ID).build()).build()).withIssuerId(TEST_RP).withMatchingServiceUri(msaStubRule.getAttributeQueryRequestUri()).build();
    SessionId sessionId = SessionId.createNewSessionId();
    final URI uri = UriBuilder.fromUri(samlSoapProxyAppRule.getUri(Urls.SamlSoapProxyUrls.MATCHING_SERVICE_REQUEST_SENDER_RESOURCE)).queryParam(Urls.SharedUrls.SESSION_ID_PARAM, sessionId).build();
    Response response = post(attributeQueryContainerDto, uri);
    assertThat(response.getStatus()).isEqualTo(Response.Status.ACCEPTED.getStatusCode());
    andPolicyShouldReceiveAFailure(sessionId);
}
Also used : RequestAndResponse(httpstub.RequestAndResponse) Response(javax.ws.rs.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) AttributeQueryContainerDto(uk.gov.ida.hub.samlsoapproxy.domain.AttributeQueryContainerDto) SessionId(uk.gov.ida.common.SessionId) URI(java.net.URI) Test(org.junit.Test)

Example 37 with SessionId

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

the class ExecuteAttributeQueryRequestTest method run_shouldThrowCertChainValidationExceptionOnResponse.

@Test
public void run_shouldThrowCertChainValidationExceptionOnResponse() throws Exception {
    when(attributeQueryRequestClient.sendQuery(any(Element.class), anyString(), any(SessionId.class), any(URI.class))).thenReturn(matchingServiceResponse);
    final BasicX509Credential x509Credential = new BasicX509Credential(new X509CertificateFactory().createCertificate(UNCHAINED_PUBLIC_CERT), new PrivateKeyFactory().createPrivateKey(Base64.decode(UNCHAINED_PRIVATE_KEY.getBytes())));
    Response response = aResponse().withSigningCredential(x509Credential).withIssuer(anIssuer().withIssuerId("issuer-id").build()).build();
    when(elementToResponseTransformer.apply(matchingServiceResponse)).thenReturn(response);
    executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto);
    verify(matchingResponseSignatureValidator).validate(response, AttributeAuthorityDescriptor.DEFAULT_ELEMENT_NAME);
}
Also used : X509CertificateFactory(uk.gov.ida.common.shared.security.X509CertificateFactory) 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) BasicX509Credential(org.opensaml.security.x509.BasicX509Credential) PrivateKeyFactory(uk.gov.ida.common.shared.security.PrivateKeyFactory) Element(org.w3c.dom.Element) SessionId(uk.gov.ida.common.SessionId) URI(java.net.URI) Test(org.junit.Test)

Example 38 with SessionId

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

the class ExecuteAttributeQueryRequestTest method run_shouldCallSamlMessageSignatureValidatorWithResponse.

@Test
public void run_shouldCallSamlMessageSignatureValidatorWithResponse() throws Exception {
    when(attributeQueryRequestClient.sendQuery(any(Element.class), anyString(), any(SessionId.class), any(URI.class))).thenReturn(matchingServiceResponse);
    Response response = aResponse().withIssuer(anIssuer().withIssuerId("issuer-id").build()).build();
    when(elementToResponseTransformer.apply(matchingServiceResponse)).thenReturn(response);
    executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto);
    verify(matchingResponseSignatureValidator).validate(response, 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 39 with SessionId

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

the class ExecuteAttributeQueryRequestTest method run_shouldCallInboundMessageValidatorWithResponse.

@Test
public void run_shouldCallInboundMessageValidatorWithResponse() 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(matchingResponseSignatureValidator).validate(response, 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)

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