Search in sources :

Example 1 with HubAttributeQueryRequest

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

the class HubAttributeQueryRequestToSamlAttributeQueryTransformerTest method transform_shouldSetAttributesToUserAccountCreationAttributes.

@Test
public void transform_shouldSetAttributesToUserAccountCreationAttributes() {
    Attribute attribute1 = openSamlXmlObjectFactory.createAttribute();
    Attribute attribute2 = openSamlXmlObjectFactory.createAttribute();
    when(attributeQueryAttributeFactory.createAttribute(CURRENT_ADDRESS)).thenReturn(attribute1);
    when(attributeQueryAttributeFactory.createAttribute(DATE_OF_BIRTH)).thenReturn(attribute2);
    HubAttributeQueryRequest hubAttributeQueryRequest = aHubAttributeQueryRequest().addUserAccountCreationAttribute(CURRENT_ADDRESS).addUserAccountCreationAttribute(DATE_OF_BIRTH).build();
    AttributeQuery transformedQuery = transformer.apply(hubAttributeQueryRequest);
    List<Attribute> transformedQueryAttributes = transformedQuery.getAttributes();
    assertThat(transformedQueryAttributes.size()).isEqualTo(2);
    assertThat(transformedQueryAttributes).contains(attribute1);
    assertThat(transformedQueryAttributes).contains(attribute2);
}
Also used : Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeQuery(org.opensaml.saml.saml2.core.AttributeQuery) HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest(uk.gov.ida.saml.hub.test.builders.HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest) HubAttributeQueryRequest(uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest) Test(org.junit.jupiter.api.Test)

Example 2 with HubAttributeQueryRequest

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

the class HubAttributeQueryRequestToSamlAttributeQueryTransformerTest method transform_shouldSetTheSPNameQualifierAndNameQualifierToValuesThatShouldntBeThereButCurrentlyHaveNoWhereBetterToBe.

@Test
public void transform_shouldSetTheSPNameQualifierAndNameQualifierToValuesThatShouldntBeThereButCurrentlyHaveNoWhereBetterToBe() {
    final String authnStatementAssertion = aPassthroughAssertion().withUnderlyingAssertion(ENCRYPTED_AUTHN_ASSERTION).buildAuthnStatementAssertionAsString();
    final HubAssertion cycle3DataAssertion = aHubAssertion().build();
    HubAttributeQueryRequest originalQuery = aHubAttributeQueryRequest().withEncryptedAuthnAssertion(authnStatementAssertion).withCycle3DataAssertion(cycle3DataAssertion).withAssertionConsumerServiceUrl(URI.create("/foo")).withAuthnRequestIssuerEntityId("authn-request-issuer").build();
    AttributeQuery transformedQuery = transformer.apply(originalQuery);
    NameID nameID = transformedQuery.getSubject().getNameID();
    assertThat(nameID.getSPNameQualifier()).isEqualTo("authn-request-issuer");
    assertThat(nameID.getNameQualifier()).isEqualTo("/foo");
}
Also used : AttributeQuery(org.opensaml.saml.saml2.core.AttributeQuery) NameID(org.opensaml.saml.saml2.core.NameID) 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)

Example 3 with HubAttributeQueryRequest

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

the class HubAttributeQueryRequestToSamlAttributeQueryTransformerTest method transform_shouldNotExplodeWhenUserAccountCreationAttributesAreAbsent.

@Test
public void transform_shouldNotExplodeWhenUserAccountCreationAttributesAreAbsent() {
    HubAttributeQueryRequest hubAttributeQueryRequest = aHubAttributeQueryRequest().withoutUserAccountCreationAttributes().build();
    AttributeQuery transformedQuery = transformer.apply(hubAttributeQueryRequest);
    List<Attribute> transformedQueryAttributes = transformedQuery.getAttributes();
    assertThat(transformedQueryAttributes.size()).isEqualTo(0);
}
Also used : AttributeQuery(org.opensaml.saml.saml2.core.AttributeQuery) Attribute(org.opensaml.saml.saml2.core.Attribute) HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest(uk.gov.ida.saml.hub.test.builders.HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest) HubAttributeQueryRequest(uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest) Test(org.junit.jupiter.api.Test)

Example 4 with HubAttributeQueryRequest

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

the class HubAttributeQueryRequestToSamlAttributeQueryTransformerTest method transform_shouldProperlyTransform.

@Test
public void transform_shouldProperlyTransform() {
    PersistentId persistentId = new PersistentId("default-name-id");
    HubAttributeQueryRequest originalQuery = aHubAttributeQueryRequest().withId("originalId").withPersistentId(persistentId).build();
    AttributeQuery transformedQuery = transformer.apply(originalQuery);
    assertThat(transformedQuery.getID()).isEqualTo(originalQuery.getId());
    assertThat(transformedQuery.getSubject().getNameID().getValue()).isEqualTo(persistentId.getNameId());
    assertThat(transformedQuery.getIssuer().getValue()).isEqualTo(originalQuery.getIssuer());
    assertThat(transformedQuery.getVersion()).isEqualTo(SAMLVersion.VERSION_20);
}
Also used : AttributeQuery(org.opensaml.saml.saml2.core.AttributeQuery) HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest(uk.gov.ida.saml.hub.test.builders.HubAttributeQueryRequestBuilder.aHubAttributeQueryRequest) HubAttributeQueryRequest(uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest) PersistentId(uk.gov.ida.saml.core.domain.PersistentId) Test(org.junit.jupiter.api.Test)

Example 5 with HubAttributeQueryRequest

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

the class AttributeQueryGeneratorTest method handle_shouldDelegateToTransformerWithCorrectData.

@Test
public void handle_shouldDelegateToTransformerWithCorrectData() {
    DateTimeFreezer.freezeTime();
    HubAttributeQueryRequest hubAttributeQueryRequest = aHubAttributeQueryRequest();
    attributeQueryGenerator.createAttributeQueryContainer(hubAttributeQueryRequest, URI.create("/dont_care"), MATCHING_SERVICE_ENTITY_ID, null, false);
    verify(transformer).apply(hubAttributeQueryRequestCaptor.capture());
    HubAttributeQueryRequest request = hubAttributeQueryRequestCaptor.getValue();
    assertThat(request.getId()).isEqualTo(hubAttributeQueryRequest.getId());
    assertThat(request.getEncryptedAuthnAssertion()).isEqualTo(hubAttributeQueryRequest.getEncryptedAuthnAssertion());
    assertThat(request.getCycle3AttributeAssertion().isPresent()).isEqualTo(false);
    assertThat(request.getIssueInstant()).isEqualTo(DateTime.now());
    assertThat(request.getAssertionConsumerServiceUrl()).isEqualTo(hubAttributeQueryRequest.getAssertionConsumerServiceUrl());
    assertThat(request.getAuthnRequestIssuerEntityId()).isEqualTo(hubAttributeQueryRequest.getAuthnRequestIssuerEntityId());
}
Also used : HubAttributeQueryRequest(uk.gov.ida.saml.hub.domain.HubAttributeQueryRequest) 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