Search in sources :

Example 6 with HubAttributeQueryRequest

use of uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest in project verify-hub by alphagov.

the class AttributeQueryGeneratorTest method handle_shouldReturnErrorDtoWhenTransformFails.

@Test
public void handle_shouldReturnErrorDtoWhenTransformFails() {
    Assertions.assertThrows(UnableToGenerateSamlException.class, () -> {
        HubAttributeQueryRequest hubAttributeQueryRequest = aHubAttributeQueryRequest();
        when(transformer.apply(hubAttributeQueryRequest)).thenThrow(new RuntimeException("failed to create attribute query request"));
        attributeQueryGenerator.createAttributeQueryContainer(hubAttributeQueryRequest, MATCHING_SERVICE_ENTITY_ID);
    });
}
Also used : HubAttributeQueryRequest(uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest) Test(org.junit.jupiter.api.Test)

Example 7 with HubAttributeQueryRequest

use of uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest in project verify-hub by alphagov.

the class AttributeQueryGeneratorTest method handle_shouldReturnDtoWithSamlMatchingServiceRequest.

// This test should move to the request builder?
@Test
public void handle_shouldReturnDtoWithSamlMatchingServiceRequest() {
    HubAttributeQueryRequest hubAttributeQueryRequest = aHubAttributeQueryRequest();
    Element transformedRequest = mock(Element.class);
    when(transformer.apply(any(HubAttributeQueryRequest.class))).thenReturn(transformedRequest);
    AttributeQueryContainerDto attributeQueryDto = attributeQueryGenerator.createAttributeQueryContainer(hubAttributeQueryRequest, URI.create("/dont_care"), MATCHING_SERVICE_ENTITY_ID, null, false);
    assertThat(attributeQueryDto.getSamlRequest()).isEqualTo(XmlUtils.writeToString(transformedRequest));
}
Also used : AttributeQueryContainerDto(uk.gov.ida.hub.samlengine.domain.AttributeQueryContainerDto) Element(org.w3c.dom.Element) HubAttributeQueryRequest(uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest) Test(org.junit.jupiter.api.Test)

Example 8 with HubAttributeQueryRequest

use of uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest in project verify-hub by alphagov.

the class AttributeQueryGeneratorTest method handle_shouldReturnDtoWithMatchingServiceEndpointReturnedFromConfig.

@Test
public void handle_shouldReturnDtoWithMatchingServiceEndpointReturnedFromConfig() {
    HubAttributeQueryRequest hubAttributeQueryRequest = aHubAttributeQueryRequest();
    URI attributeQueryUri = URI.create("/attribute-query-uri");
    AttributeQueryContainerDto attributeQueryDto = attributeQueryGenerator.createAttributeQueryContainer(hubAttributeQueryRequest, attributeQueryUri, MATCHING_SERVICE_ENTITY_ID, null, false);
    assertThat(attributeQueryDto.getMatchingServiceUri()).isEqualTo(attributeQueryUri);
}
Also used : AttributeQueryContainerDto(uk.gov.ida.hub.samlengine.domain.AttributeQueryContainerDto) HubAttributeQueryRequest(uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 9 with HubAttributeQueryRequest

use of uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest in project verify-hub by alphagov.

the class AttributeQueryGeneratorTest method handle_shouldSetEntityToEncryptFor.

@Test
public void handle_shouldSetEntityToEncryptFor() {
    HubAttributeQueryRequest hubAttributeQueryRequest = aHubAttributeQueryRequest();
    when(transformer.apply(any(HubAttributeQueryRequest.class))).thenThrow(new RuntimeException("Avoid NullPointerException later."));
    try {
        attributeQueryGenerator.createAttributeQueryContainer(hubAttributeQueryRequest, URI.create("/dont_care"), MATCHING_SERVICE_ENTITY_ID, null, false);
        fail("Should have thrown exception.");
    } catch (RuntimeException e) {
        assertThat(e).hasMessage("Avoid NullPointerException later.");
    }
    verify(entityToEncryptForLocator).addEntityIdForRequestId(hubAttributeQueryRequest.getId(), MATCHING_SERVICE_ENTITY_ID);
    verify(entityToEncryptForLocator).removeEntityIdForRequestId(hubAttributeQueryRequest.getId());
}
Also used : HubAttributeQueryRequest(uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest) Test(org.junit.jupiter.api.Test)

Example 10 with HubAttributeQueryRequest

use of uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest in project verify-hub by alphagov.

the class HubAttributeQueryRequestToSamlAttributeQueryTransformerTest method transform_shouldOnlyIncludeCycle3Unencrypted.

@Test
public void transform_shouldOnlyIncludeCycle3Unencrypted() {
    final HubAssertion cycle3DataAssertion = aHubAssertion().build();
    HubAttributeQueryRequest originalQuery = aHubAttributeQueryRequest().withCycle3DataAssertion(cycle3DataAssertion).build();
    AttributeQuery transformedQuery = transformer.apply(originalQuery);
    List<XMLObject> unknownXMLObjects = transformedQuery.getSubject().getSubjectConfirmations().get(0).getSubjectConfirmationData().getUnknownXMLObjects(Assertion.DEFAULT_ELEMENT_NAME);
    assertThat(unknownXMLObjects.size()).isEqualTo(1);
    assertThat(((Assertion) unknownXMLObjects.get(0)).getID()).isEqualTo(cycle3DataAssertion.getId());
}
Also used : AttributeQuery(org.opensaml.saml.saml2.core.AttributeQuery) EncryptedAssertion(org.opensaml.saml.saml2.core.EncryptedAssertion) HubAssertionBuilder.aHubAssertion(uk.gov.ida.saml.core.test.builders.HubAssertionBuilder.aHubAssertion) PassthroughAssertionBuilder.aPassthroughAssertion(uk.gov.ida.saml.core.test.builders.PassthroughAssertionBuilder.aPassthroughAssertion) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) XMLObject(org.opensaml.core.xml.XMLObject) HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest(uk.gov.ida.saml.hub.test.builders.HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest) HubAttributeQueryRequest(uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest) HubAssertionBuilder.aHubAssertion(uk.gov.ida.saml.core.test.builders.HubAssertionBuilder.aHubAssertion) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)11 HubAttributeQueryRequest (uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest)11 AttributeQuery (org.opensaml.saml.saml2.core.AttributeQuery)6 HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest (uk.gov.ida.saml.hub.test.builders.HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest)6 XMLObject (org.opensaml.core.xml.XMLObject)2 Attribute (org.opensaml.saml.saml2.core.Attribute)2 EncryptedAssertion (org.opensaml.saml.saml2.core.EncryptedAssertion)2 AttributeQueryContainerDto (uk.gov.ida.hub.samlengine.domain.AttributeQueryContainerDto)2 HubAssertion (uk.gov.ida.saml.core.domain.HubAssertion)2 HubAssertionBuilder.aHubAssertion (uk.gov.ida.saml.core.test.builders.HubAssertionBuilder.aHubAssertion)2 URI (java.net.URI)1 Assertion (org.opensaml.saml.saml2.core.Assertion)1 NameID (org.opensaml.saml.saml2.core.NameID)1 EncryptedAssertionBuilder (org.opensaml.saml.saml2.core.impl.EncryptedAssertionBuilder)1 Element (org.w3c.dom.Element)1 PersistentId (uk.gov.ida.saml.core.domain.PersistentId)1 PassthroughAssertionBuilder.aPassthroughAssertion (uk.gov.ida.saml.core.test.builders.PassthroughAssertionBuilder.aPassthroughAssertion)1