use of uk.gov.ida.saml.core.domain.HubAssertion in project verify-hub by alphagov.
the class HubEidasAttributeQueryRequestBuilderTest method shouldCreateHubAttributeQueryRequest.
@Test
public void shouldCreateHubAttributeQueryRequest() {
final EidasAttributeQueryRequestDto eidasAttributeQueryRequestDto = anEidasAttributeQueryRequestDto().build();
final Optional<HubAssertion> cycle3AttributeAssertion = Optional.empty();
HubEidasAttributeQueryRequest expectedResult = new HubEidasAttributeQueryRequest(eidasAttributeQueryRequestDto.getRequestId(), HUB_EIDAS_ENTITY_ID, NOW, new uk.gov.ida.saml.core.domain.PersistentId(eidasAttributeQueryRequestDto.getPersistentId().getNameId()), eidasAttributeQueryRequestDto.getAssertionConsumerServiceUri(), eidasAttributeQueryRequestDto.getAuthnRequestIssuerEntityId(), eidasAttributeQueryRequestDto.getEncryptedIdentityAssertion(), AuthnContext.LEVEL_2, cycle3AttributeAssertion, USER_ACCOUNT_CREATION_ATTRIBUTES);
HubEidasAttributeQueryRequest hubEidasAttributeQueryRequest = builder.createHubAttributeQueryRequest(eidasAttributeQueryRequestDto);
assertThat(hubEidasAttributeQueryRequest.getId()).isEqualTo(expectedResult.getId());
assertThat(hubEidasAttributeQueryRequest.getPersistentId().getNameId()).isEqualTo(expectedResult.getPersistentId().getNameId());
assertThat(hubEidasAttributeQueryRequest.getEncryptedIdentityAssertion()).isEqualTo(expectedResult.getEncryptedIdentityAssertion());
assertThat(hubEidasAttributeQueryRequest.getAssertionConsumerServiceUrl()).isEqualTo(expectedResult.getAssertionConsumerServiceUrl());
assertThat(hubEidasAttributeQueryRequest.getAuthnRequestIssuerEntityId()).isEqualTo(expectedResult.getAuthnRequestIssuerEntityId());
assertThat(hubEidasAttributeQueryRequest.getAuthnContext()).isEqualTo(expectedResult.getAuthnContext());
assertThat(hubEidasAttributeQueryRequest.getIssuer()).isEqualTo(expectedResult.getIssuer());
assertThat(hubEidasAttributeQueryRequest.getIssueInstant()).isEqualTo(expectedResult.getIssueInstant());
assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion()).isEqualTo(cycle3AttributeAssertion);
assertThat(hubEidasAttributeQueryRequest.getUserAccountCreationAttributes()).isEqualTo(USER_ACCOUNT_CREATION_ATTRIBUTES);
}
use of uk.gov.ida.saml.core.domain.HubAssertion in project verify-hub by alphagov.
the class HubEidasAttributeQueryRequestBuilderTest method shouldCreateHubAttributeQueryRequestWithCycle3Assertion.
@Test
public void shouldCreateHubAttributeQueryRequestWithCycle3Assertion() {
final Map<String, String> dataset = new HashMap<>();
dataset.put("DrivingLicenceNumber", "MORGA657054SM9IJ");
final Cycle3Dataset cycle3Dataset = new Cycle3Dataset(dataset);
final EidasAttributeQueryRequestDto eidasAttributeQueryRequestDto = anEidasAttributeQueryRequestDto().withCycle3Dataset(cycle3Dataset).build();
final uk.gov.ida.saml.core.domain.PersistentId persistentId = new uk.gov.ida.saml.core.domain.PersistentId(eidasAttributeQueryRequestDto.getPersistentId().getNameId());
final uk.gov.ida.saml.core.domain.Cycle3Dataset oldCycle3Dataset = uk.gov.ida.saml.core.domain.Cycle3Dataset.createFromData(eidasAttributeQueryRequestDto.getCycle3Dataset().get().getAttributes());
final AssertionRestrictions assertionRestrictions = new AssertionRestrictions(eidasAttributeQueryRequestDto.getAssertionExpiry(), eidasAttributeQueryRequestDto.getRequestId(), eidasAttributeQueryRequestDto.getAuthnRequestIssuerEntityId());
final HubAssertion hubAssertion = new HubAssertion(UUID.randomUUID().toString(), HUB_EIDAS_ENTITY_ID, NOW, persistentId, assertionRestrictions, Optional.of(oldCycle3Dataset));
final Optional<HubAssertion> cycle3Assertion = Optional.of(hubAssertion);
final HubEidasAttributeQueryRequest expectedResult = new HubEidasAttributeQueryRequest(eidasAttributeQueryRequestDto.getRequestId(), HUB_EIDAS_ENTITY_ID, NOW, persistentId, eidasAttributeQueryRequestDto.getAssertionConsumerServiceUri(), eidasAttributeQueryRequestDto.getAuthnRequestIssuerEntityId(), eidasAttributeQueryRequestDto.getEncryptedIdentityAssertion(), AuthnContext.LEVEL_2, cycle3Assertion, USER_ACCOUNT_CREATION_ATTRIBUTES);
HubEidasAttributeQueryRequest hubEidasAttributeQueryRequest = builder.createHubAttributeQueryRequest(eidasAttributeQueryRequestDto);
assertThat(hubEidasAttributeQueryRequest.getId()).isEqualTo(expectedResult.getId());
assertThat(hubEidasAttributeQueryRequest.getPersistentId().getNameId()).isEqualTo(expectedResult.getPersistentId().getNameId());
assertThat(hubEidasAttributeQueryRequest.getEncryptedIdentityAssertion()).isEqualTo(expectedResult.getEncryptedIdentityAssertion());
assertThat(hubEidasAttributeQueryRequest.getAssertionConsumerServiceUrl()).isEqualTo(expectedResult.getAssertionConsumerServiceUrl());
assertThat(hubEidasAttributeQueryRequest.getAuthnRequestIssuerEntityId()).isEqualTo(expectedResult.getAuthnRequestIssuerEntityId());
assertThat(hubEidasAttributeQueryRequest.getAuthnContext()).isEqualTo(expectedResult.getAuthnContext());
assertThat(hubEidasAttributeQueryRequest.getIssuer()).isEqualTo(expectedResult.getIssuer());
assertThat(hubEidasAttributeQueryRequest.getIssueInstant()).isEqualTo(expectedResult.getIssueInstant());
assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().isPresent()).isTrue();
assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().get().getIssuerId()).isEqualTo(hubAssertion.getIssuerId());
assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().get().getAssertionRestrictions().getInResponseTo()).isEqualTo(hubAssertion.getAssertionRestrictions().getInResponseTo());
assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().get().getAssertionRestrictions().getNotOnOrAfter()).isEqualTo(hubAssertion.getAssertionRestrictions().getNotOnOrAfter());
assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().get().getAssertionRestrictions().getRecipient()).isEqualTo(hubAssertion.getAssertionRestrictions().getRecipient());
assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().get().getPersistentId().getNameId()).isEqualTo(hubAssertion.getPersistentId().getNameId());
assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().get().getIssueInstant()).isEqualTo(hubAssertion.getIssueInstant());
assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().get().getCycle3Data().isPresent()).isTrue();
assertThat(hubEidasAttributeQueryRequest.getCycle3AttributeAssertion().get().getCycle3Data().get().getAttributes()).isEqualTo(hubAssertion.getCycle3Data().get().getAttributes());
assertThat(hubEidasAttributeQueryRequest.getUserAccountCreationAttributes()).isEqualTo(USER_ACCOUNT_CREATION_ATTRIBUTES);
}
use of uk.gov.ida.saml.core.domain.HubAssertion in project verify-hub by alphagov.
the class HubEidasAttributeQueryRequestBuilder method createCycle3Assertion.
private Optional<HubAssertion> createCycle3Assertion(EidasAttributeQueryRequestDto attributeQueryRequestDto) {
Optional<HubAssertion> cycle3AttributeAssertion = Optional.empty();
Optional<uk.gov.ida.hub.samlengine.domain.Cycle3Dataset> serializableCycle3Dataset = attributeQueryRequestDto.getCycle3Dataset();
if (serializableCycle3Dataset.isPresent()) {
AssertionRestrictions assertionRestrictions = new AssertionRestrictions(attributeQueryRequestDto.getAssertionExpiry(), attributeQueryRequestDto.getRequestId(), attributeQueryRequestDto.getAuthnRequestIssuerEntityId());
Optional<Cycle3Dataset> cycle3Data = serializableCycle3Dataset.map(uk.gov.ida.hub.samlengine.domain.Cycle3Dataset::getAttributes).map(Cycle3Dataset::createFromData);
HubAssertion hubAssertion = new HubAssertion(UUID.randomUUID().toString(), hubEntityId, DateTime.now(), new PersistentId(attributeQueryRequestDto.getPersistentId().getNameId()), assertionRestrictions, cycle3Data);
cycle3AttributeAssertion = Optional.of(hubAssertion);
}
return cycle3AttributeAssertion;
}
use of uk.gov.ida.saml.core.domain.HubAssertion 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());
}
use of uk.gov.ida.saml.core.domain.HubAssertion in project verify-hub by alphagov.
the class HubAssertionMarshallerTest method transform_shouldTransformLevelOfCycle3DataAssertion.
@Test
public void transform_shouldTransformLevelOfCycle3DataAssertion() {
String attributeName = "someName";
String value = "some value";
HubAssertion assertion = aHubAssertion().withCycle3Data(aCycle3Dataset().addCycle3Data(attributeName, value).build()).build();
Attribute expectedAttribute = aSimpleStringAttribute().build();
when(attributeFactory.createCycle3DataAttribute(attributeName, value)).thenReturn(expectedAttribute);
Assertion transformedAssertion = marshaller.toSaml(assertion);
List<AttributeStatement> attributeStatements = transformedAssertion.getAttributeStatements();
assertThat(attributeStatements.size()).isGreaterThan(0);
Attribute attribute = attributeStatements.get(0).getAttributes().get(0);
assertThat(attribute).isEqualTo(expectedAttribute);
}
Aggregations