Search in sources :

Example 16 with SessionId

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

the class ExecuteAttributeQueryRequestTest method run_shouldCallInboundMessageValidatorWithAttributeQuery.

@Test
public void run_shouldCallInboundMessageValidatorWithAttributeQuery() 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 17 with SessionId

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

the class ExecuteAttributeQueryRequestTest method run_shouldSendToTheCorrectUri.

@Test
public void run_shouldSendToTheCorrectUri() throws Exception {
    when(attributeQueryRequestClient.sendQuery(any(Element.class), anyString(), any(SessionId.class), any(URI.class))).thenReturn(matchingServiceResponse);
    when(elementToResponseTransformer.apply(matchingServiceResponse)).thenReturn(aResponse().build());
    executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto);
    final ArgumentCaptor<URI> uriArgumentCaptor = ArgumentCaptor.forClass(URI.class);
    verify(attributeQueryRequestClient).sendQuery(any(Element.class), anyString(), any(SessionId.class), uriArgumentCaptor.capture());
    final URI uri = uriArgumentCaptor.getValue();
    assertThat(uri).isEqualTo(matchingServiceUri);
}
Also used : Element(org.w3c.dom.Element) SessionId(uk.gov.ida.common.SessionId) URI(java.net.URI) Test(org.junit.Test)

Example 18 with SessionId

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

the class ExecuteAttributeQueryRequestTest method run_shouldUseCorrectSignatureValidators.

@Test
public void run_shouldUseCorrectSignatureValidators() throws Exception {
    when(attributeQueryRequestClient.sendQuery(any(Element.class), anyString(), any(SessionId.class), any(URI.class))).thenReturn(matchingServiceResponse);
    final Response response = aResponse().build();
    when(elementToResponseTransformer.apply(matchingServiceResponse)).thenReturn(response);
    executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto);
    verify(matchingRequestSignatureValidator).validate(attributeQuery, AttributeAuthorityDescriptor.DEFAULT_ELEMENT_NAME);
    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 19 with SessionId

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

the class CountryMetadataConsumerTest method shouldReturnErrorWhenValidatingEidasAuthnResponseContainingInvalidSignature.

@Test
public void shouldReturnErrorWhenValidatingEidasAuthnResponseContainingInvalidSignature() throws Exception {
    // Given
    SessionId sessionId = SessionId.createNewSessionId();
    String response = authnResponseFactory.aSamlResponseFromIdp("a-request", countryMetadata.getCountryMetadataUri(), anotherIdpSigningCert, anotherIdpSigningKey, "", SIGNATURE_ALGORITHM, DIGEST_ALGORITHM);
    // When
    Response responseFromSamlProxy = postSAML(new SamlRequestDto(response, sessionId.getSessionId(), "127.0.0.1"));
    // Then
    assertThat(responseFromSamlProxy.getStatus()).isEqualTo(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
Also used : Response(javax.ws.rs.core.Response) SamlRequestDto(uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto) SessionId(uk.gov.ida.common.SessionId) Test(org.junit.Test)

Example 20 with SessionId

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

the class MetadataConsumerTests method shouldReturnBadRequestWhenEntityIdCannotBeFoundInMetadata.

@Test
public void shouldReturnBadRequestWhenEntityIdCannotBeFoundInMetadata() throws Exception {
    SessionId sessionId = SessionId.createNewSessionId();
    policyStubRule.register(UriBuilder.fromPath(Urls.PolicyUrls.IDP_AUTHN_RESPONSE_RESOURCE).build(sessionId).getPath(), 200, ResponseActionDto.success(sessionId, true, LEVEL_2));
    String response = authnResponseFactory.aSamlResponseFromIdp("non-existent-entity-id", STUB_IDP_PUBLIC_PRIMARY_CERT, STUB_IDP_PUBLIC_PRIMARY_PRIVATE_KEY, "", SIGNATURE_ALGORITHM, DIGEST_ALGORITHM);
    SamlRequestDto samlRequestDto = new SamlRequestDto(response, sessionId.getSessionId(), "127.0.0.1");
    assertThat(postSAML(samlRequestDto).getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
}
Also used : SamlRequestDto(uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto) SessionId(uk.gov.ida.common.SessionId) 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