diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityDescriptorServiceImpl.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityDescriptorServiceImpl.java index 4807e336a..d46c789c3 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityDescriptorServiceImpl.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityDescriptorServiceImpl.java @@ -60,6 +60,8 @@ import java.util.Optional; import java.util.stream.Collectors; +import static edu.internet2.tier.shibboleth.admin.util.ModelRepresentationConversions.getStringListOfAttributeValues; + /** * Default implementation of {@link EntityDescriptorService} * @@ -493,10 +495,14 @@ public EntityDescriptorRepresentation createRepresentationFromDescriptor(org.ope for (org.opensaml.saml.saml2.core.Attribute attribute : ((EntityAttributes) ed.getExtensions().getUnknownXMLObjects(EntityAttributes.DEFAULT_ELEMENT_NAME).get(0)).getAttributes()) { Attribute jpaAttribute = (Attribute) attribute; - Optional override = ModelRepresentationConversions.getOverrideByAttributeName(jpaAttribute.getName()); - if (override.isPresent()) { - relyingPartyOverrides.put(((RelyingPartyOverrideProperty)override.get()).getName(), - jpaAttribute.getAttributeValues()); + if (jpaAttribute.getName().equals(MDDCConstants.RELEASE_ATTRIBUTES)) { + representation.setAttributeRelease(getStringListOfAttributeValues(attribute.getAttributeValues())); + } else { + Optional override = ModelRepresentationConversions.getOverrideByAttributeName(jpaAttribute.getName()); + if (override.isPresent()) { + relyingPartyOverrides.put(((RelyingPartyOverrideProperty) override.get()).getName(), + jpaAttribute.getAttributeValues()); + } } } diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityServiceImpl.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityServiceImpl.java index db673bb66..b3ba1fd1c 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityServiceImpl.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityServiceImpl.java @@ -28,7 +28,7 @@ public class JPAEntityServiceImpl implements EntityService { private AttributeUtility attributeUtility; @Autowired - private CustomPropertiesConfiguration customPropertiesConfiguration = new CustomPropertiesConfiguration(); + private CustomPropertiesConfiguration customPropertiesConfiguration; public JPAEntityServiceImpl(OpenSamlObjects openSamlObjects) { this.openSamlObjects = openSamlObjects; @@ -39,6 +39,14 @@ public JPAEntityServiceImpl(OpenSamlObjects openSamlObjects, AttributeUtility at this.attributeUtility = attributeUtility; } + public JPAEntityServiceImpl(OpenSamlObjects openSamlObjects, + AttributeUtility attributeUtility, + CustomPropertiesConfiguration customPropertiesConfiguration) { + this.openSamlObjects = openSamlObjects; + this.attributeUtility = attributeUtility; + this.customPropertiesConfiguration = customPropertiesConfiguration; + } + @Override public List getAttributeListFromEntityRepresentation(EntityDescriptorRepresentation entityDescriptorRepresentation) { List list = new ArrayList<>(); @@ -95,7 +103,7 @@ public List getAttributeListFromRelyingPartyOverridesRepresentation(M for (Map.Entry entry : relyingPartyOverridesRepresentation.entrySet()) { String key = (String) entry.getKey(); - RelyingPartyOverrideProperty overrideProperty = overridePropertyList.stream().filter(op -> op.getDisplayName().equals(key)).findFirst().get(); + RelyingPartyOverrideProperty overrideProperty = overridePropertyList.stream().filter(op -> op.getName().equals(key)).findFirst().get(); switch (ModelRepresentationConversions.AttributeTypes.valueOf(overrideProperty.getDisplayType().toUpperCase())) { case BOOLEAN: if (!overrideProperty.getPersistType().equalsIgnoreCase("boolean")) { @@ -120,12 +128,12 @@ public List getAttributeListFromRelyingPartyOverridesRepresentation(M (String) entry.getValue())); break; case SET: - list.add(attributeUtility.createAttributeWithArbitraryValues(overrideProperty.getAttributeName(), + list.add(attributeUtility.createAttributeWithStringValues(overrideProperty.getAttributeName(), overrideProperty.getAttributeFriendlyName(), - (Set) entry.getValue())); + (List) entry.getValue())); break; case LIST: - list.add(attributeUtility.createAttributeWithArbitraryValues(overrideProperty.getAttributeName(), + list.add(attributeUtility.createAttributeWithStringValues(overrideProperty.getAttributeName(), overrideProperty.getAttributeFriendlyName(), (List) entry.getValue())); break; diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/util/AttributeUtility.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/util/AttributeUtility.java index 206f2d51d..20fca363c 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/util/AttributeUtility.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/util/AttributeUtility.java @@ -34,7 +34,6 @@ public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWi return attribute; } - public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWithIntegerValue(String name, String friendlyName, Integer value) { edu.internet2.tier.shibboleth.admin.ui.domain.Attribute attribute = createNewAttribute(name, friendlyName); @@ -45,7 +44,6 @@ public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWi return attribute; } - public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWithStringValues(String name, String friendlyName, String... values) { edu.internet2.tier.shibboleth.admin.ui.domain.Attribute attribute = createNewAttribute(name, friendlyName); @@ -58,7 +56,6 @@ public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWi return attribute; } - /* * Provided for calling with name = MDDCConstants.RELEASE_ATTRIBUTES. */ @@ -70,27 +67,6 @@ public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWi return createAttributeWithStringValues(name, friendlyName, values.toArray(new String[]{})); } - public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWithArbitraryValues(String name, String friendlyName, String... values) { - edu.internet2.tier.shibboleth.admin.ui.domain.Attribute attribute = createNewAttribute(name, friendlyName); - - for (String value : values) { - XSAny xsAny = (XSAny) openSamlObjects.getBuilderFactory().getBuilder(XSAny.TYPE_NAME).buildObject(AttributeValue.DEFAULT_ELEMENT_NAME); - xsAny.setTextContent(value); - attribute.getAttributeValues().add(xsAny); - } - - return attribute; - } - - public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWithArbitraryValues(String name, String friendlyName, List values) { - return createAttributeWithArbitraryValues(name, friendlyName, values.toArray(new String[]{})); - } - - public edu.internet2.tier.shibboleth.admin.ui.domain.Attribute createAttributeWithArbitraryValues(String name, String friendlyName, Set values) { - return createAttributeWithStringValues(name, friendlyName, values.toArray(new String[]{})); - } - - /* Calling this method with name = MDDCConstants.RELEASE_ATTRIBUTES seems to be a special case. In this case, * we haven't been setting the friendlyName or nameFormat. Hence the null check. */ diff --git a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/util/ModelRepresentationConversions.java b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/util/ModelRepresentationConversions.java index 3edb7f3ee..de834abbc 100644 --- a/backend/src/main/java/edu/internet2/tier/shibboleth/admin/util/ModelRepresentationConversions.java +++ b/backend/src/main/java/edu/internet2/tier/shibboleth/admin/util/ModelRepresentationConversions.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -121,7 +122,7 @@ public static Object getOverrideFromAttribute(Attribute attribute) { } case LIST: case SET: - return attributeValues.stream().map(it -> ((XSAny) it).getTextContent()).collect(Collectors.toList()); + return attributeValues.stream().map(it -> ((XSString) it).getValue()).collect(Collectors.toList()); default: throw new UnsupportedOperationException("An unsupported persist type was specified (" + relyingPartyOverrideProperty.getPersistType() + ")!"); } @@ -142,51 +143,61 @@ public static List getAttributeListFromA List overridePropertyList = customPropertiesConfiguration.getOverrides(); List list = new ArrayList<>(); - for (Map.Entry entry : relyingPartyOverridesRepresentation.entrySet()) { - String key = (String) entry.getKey(); - RelyingPartyOverrideProperty overrideProperty = overridePropertyList.stream().filter(op -> op.getName().equals(key)).findFirst().get(); - switch (AttributeTypes.valueOf(overrideProperty.getDisplayType().toUpperCase())) { - case BOOLEAN: - if (overrideProperty.getPersistType() != null && - !overrideProperty.getPersistType().equalsIgnoreCase("boolean")) { - // we must be persisting a string then - list.add(ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(), + if (relyingPartyOverridesRepresentation != null) { + for (Map.Entry entry : relyingPartyOverridesRepresentation.entrySet()) { + String key = (String) entry.getKey(); + RelyingPartyOverrideProperty overrideProperty = overridePropertyList.stream().filter(op -> op.getName().equals(key)).findFirst().get(); + switch (AttributeTypes.valueOf(overrideProperty.getDisplayType().toUpperCase())) { + case BOOLEAN: + if (overrideProperty.getPersistType() != null && + !overrideProperty.getPersistType().equalsIgnoreCase("boolean")) { + // we must be persisting a string then + list.add(ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(), + overrideProperty.getAttributeFriendlyName(), + overrideProperty.getPersistValue())); + } else { + list.add(ATTRIBUTE_UTILITY.createAttributeWithBooleanValue(overrideProperty.getAttributeName(), + overrideProperty.getAttributeFriendlyName(), + (Boolean) entry.getValue())); + } + break; + case INTEGER: + list.add(ATTRIBUTE_UTILITY.createAttributeWithIntegerValue(overrideProperty.getAttributeName(), overrideProperty.getAttributeFriendlyName(), - overrideProperty.getPersistValue())); - } else { - list.add(ATTRIBUTE_UTILITY.createAttributeWithBooleanValue(overrideProperty.getAttributeName(), + (Integer) entry.getValue())); + break; + case STRING: + list.add(ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(), overrideProperty.getAttributeFriendlyName(), - (Boolean) entry.getValue())); - } - break; - case INTEGER: - list.add(ATTRIBUTE_UTILITY.createAttributeWithIntegerValue(overrideProperty.getAttributeName(), - overrideProperty.getAttributeFriendlyName(), - (Integer) entry.getValue())); - break; - case STRING: - list.add(ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(), - overrideProperty.getAttributeFriendlyName(), - (String) entry.getValue())); - break; - case SET: - Set setValues = (Set) entry.getValue(); - if (setValues.size() > 0) { - list.add(ATTRIBUTE_UTILITY.createAttributeWithArbitraryValues(overrideProperty.getAttributeName(), - overrideProperty.getAttributeFriendlyName(), - setValues)); - } - break; - case LIST: - List listValues = (List) entry.getValue(); - if (listValues.size() > 0) { - list.add(ATTRIBUTE_UTILITY.createAttributeWithArbitraryValues(overrideProperty.getAttributeName(), - overrideProperty.getAttributeFriendlyName(), - listValues)); - } - break; - default: - throw new UnsupportedOperationException("getAttributeListFromRelyingPartyOverridesRepresentation was called with an unsupported type (" + overrideProperty.getDisplayType() + ")!"); + (String) entry.getValue())); + break; + case SET: + Set setValues; + if (entry.getValue() instanceof Set) { + setValues = (Set) entry.getValue(); + } else if (entry.getValue() instanceof List) { + setValues = new HashSet<>(); + setValues.addAll((List) entry.getValue()); + } else { + throw new UnsupportedOperationException("The collection passed from the UI is neither a Set or List. This shouldn't happen. Fix this!"); + } + if (setValues.size() > 0) { + list.add(ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(), + overrideProperty.getAttributeFriendlyName(), + new ArrayList<>(setValues))); + } + break; + case LIST: + List listValues = (List) entry.getValue(); + if (listValues.size() > 0) { + list.add(ATTRIBUTE_UTILITY.createAttributeWithStringValues(overrideProperty.getAttributeName(), + overrideProperty.getAttributeFriendlyName(), + listValues)); + } + break; + default: + throw new UnsupportedOperationException("getAttributeListFromRelyingPartyOverridesRepresentation was called with an unsupported type (" + overrideProperty.getDisplayType() + ")!"); + } } } diff --git a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntitiesControllerIntegrationTests.groovy b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntitiesControllerIntegrationTests.groovy index 33a407f1a..8bf12484a 100644 --- a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntitiesControllerIntegrationTests.groovy +++ b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntitiesControllerIntegrationTests.groovy @@ -1,6 +1,7 @@ package edu.internet2.tier.shibboleth.admin.ui.controller import edu.internet2.tier.shibboleth.admin.ui.opensaml.OpenSamlObjects +import groovy.json.JsonOutput import net.shibboleth.ext.spring.resource.ResourceHelper import org.joda.time.DateTime import org.opensaml.saml.metadata.resolver.ChainingMetadataResolver @@ -15,6 +16,7 @@ import org.springframework.context.annotation.Bean import org.springframework.core.io.ClassPathResource import org.springframework.test.context.ActiveProfiles import org.springframework.test.web.reactive.server.WebTestClient +import org.springframework.test.web.servlet.result.MockMvcResultHandlers import org.springframework.web.util.DefaultUriBuilderFactory import org.xmlunit.builder.DiffBuilder import org.xmlunit.builder.Input @@ -59,17 +61,7 @@ class EntitiesControllerIntegrationTests extends Specification { "serviceEnabled":false, "createdDate":null, "modifiedDate":null, - "relyingPartyOverrides":{ - "signAssertion":false, - "dontSignResponse":false, - "turnOffEncryption":false, - "useSha":false, - "ignoreAuthenticationMethod":false, - "omitNotBefore":false, - "responderId":null, - "nameIdFormats":[], - "authenticationMethods":[] - }, + "relyingPartyOverrides":{}, "attributeRelease":["givenName","employeeNumber"] } ''' diff --git a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntitiesControllerTests.groovy b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntitiesControllerTests.groovy index 89a43e4a8..99a8a0fd4 100644 --- a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntitiesControllerTests.groovy +++ b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntitiesControllerTests.groovy @@ -77,17 +77,7 @@ class EntitiesControllerTests extends Specification { "serviceEnabled":false, "createdDate":null, "modifiedDate":null, - "relyingPartyOverrides":{ - "signAssertion":false, - "dontSignResponse":false, - "turnOffEncryption":false, - "useSha":false, - "ignoreAuthenticationMethod":false, - "omitNotBefore":false, - "responderId":null, - "nameIdFormats":[], - "authenticationMethods":[] - }, + "relyingPartyOverrides":{}, "attributeRelease":["givenName","employeeNumber"] } ''' diff --git a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntityDescriptorControllerTests.groovy b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntityDescriptorControllerTests.groovy index bc3de95e5..122a349ae 100644 --- a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntityDescriptorControllerTests.groovy +++ b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/controller/EntityDescriptorControllerTests.groovy @@ -448,18 +448,7 @@ class EntityDescriptorControllerTests extends Specification { "serviceEnabled": false, "createdDate": null, "modifiedDate": null, - "relyingPartyOverrides": { - "signAssertion": false, - "dontSignResponse": false, - "turnOffEncryption": false, - "useSha": false, - "ignoreAuthenticationMethod": false, - "omitNotBefore": false, - "responderId": null, - "nameIdFormats": [], - "authenticationMethods": [], - "forceAuthn": false - }, + "relyingPartyOverrides": {}, "attributeRelease": [ "givenName", "employeeNumber" @@ -577,18 +566,7 @@ class EntityDescriptorControllerTests extends Specification { "serviceEnabled": false, "createdDate": null, "modifiedDate": null, - "relyingPartyOverrides": { - "signAssertion": false, - "dontSignResponse": false, - "turnOffEncryption": false, - "useSha": false, - "ignoreAuthenticationMethod": false, - "omitNotBefore": false, - "responderId": null, - "nameIdFormats": [], - "authenticationMethods": [], - "forceAuthn": false - }, + "relyingPartyOverrides": {}, "attributeRelease": [ "givenName", "employeeNumber" diff --git a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/service/IncommonJPAMetadataResolverServiceImplTests.groovy b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/service/IncommonJPAMetadataResolverServiceImplTests.groovy index 003e8c167..cae0c8afc 100644 --- a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/service/IncommonJPAMetadataResolverServiceImplTests.groovy +++ b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/service/IncommonJPAMetadataResolverServiceImplTests.groovy @@ -3,6 +3,7 @@ package edu.internet2.tier.shibboleth.admin.ui.service import edu.internet2.tier.shibboleth.admin.ui.configuration.CoreShibUiConfiguration import edu.internet2.tier.shibboleth.admin.ui.configuration.InternationalizationConfiguration import edu.internet2.tier.shibboleth.admin.ui.configuration.SearchConfiguration +import edu.internet2.tier.shibboleth.admin.ui.domain.XSString import edu.internet2.tier.shibboleth.admin.ui.domain.filters.EntityAttributesFilter import edu.internet2.tier.shibboleth.admin.ui.domain.filters.EntityAttributesFilterTarget import edu.internet2.tier.shibboleth.admin.ui.domain.filters.EntityRoleWhiteListFilter @@ -12,6 +13,7 @@ import edu.internet2.tier.shibboleth.admin.ui.opensaml.OpenSamlObjects import edu.internet2.tier.shibboleth.admin.ui.repository.MetadataResolverRepository import edu.internet2.tier.shibboleth.admin.ui.util.TestObjectGenerator import edu.internet2.tier.shibboleth.admin.util.AttributeUtility +import groovy.xml.XmlUtil import org.opensaml.saml.metadata.resolver.ChainingMetadataResolver import org.opensaml.saml.metadata.resolver.MetadataResolver import org.springframework.beans.factory.annotation.Autowired @@ -73,11 +75,11 @@ class IncommonJPAMetadataResolverServiceImplTests extends Specification { it.value = ['https://sp1.example.org'] it } - def attribute = attributeUtility.createAttributeWithArbitraryValues('here', null, 'there') + def attribute = attributeUtility.createAttributeWithStringValues('here', null, 'there') attribute.nameFormat = null attribute.namespacePrefix = 'saml' attribute.attributeValues.each { val -> - val.namespacePrefix = 'saml' + ((XSString)val).namespacePrefix = 'saml' } it.attributes = [attribute] it diff --git a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityDescriptorServiceImplTests.groovy b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityDescriptorServiceImplTests.groovy index 679260897..f6326bca3 100644 --- a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityDescriptorServiceImplTests.groovy +++ b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityDescriptorServiceImplTests.groovy @@ -1,31 +1,57 @@ package edu.internet2.tier.shibboleth.admin.ui.service import com.fasterxml.jackson.databind.ObjectMapper +import edu.internet2.tier.shibboleth.admin.ui.ShibbolethUiApplication +import edu.internet2.tier.shibboleth.admin.ui.configuration.CoreShibUiConfiguration +import edu.internet2.tier.shibboleth.admin.ui.configuration.CustomPropertiesConfiguration +import edu.internet2.tier.shibboleth.admin.ui.configuration.InternationalizationConfiguration +import edu.internet2.tier.shibboleth.admin.ui.configuration.MetadataResolverConverterConfiguration +import edu.internet2.tier.shibboleth.admin.ui.configuration.SearchConfiguration import edu.internet2.tier.shibboleth.admin.ui.domain.EntityDescriptor import edu.internet2.tier.shibboleth.admin.ui.domain.XSAny import edu.internet2.tier.shibboleth.admin.ui.domain.XSBoolean -import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.AssertionConsumerServiceRepresentation -import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.ContactRepresentation -import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.EntityDescriptorRepresentation -import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.LogoutEndpointRepresentation -import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.MduiRepresentation -import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.OrganizationRepresentation -import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.RelyingPartyOverridesRepresentation -import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.SecurityInfoRepresentation -import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.ServiceProviderSsoDescriptorRepresentation +import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.* import edu.internet2.tier.shibboleth.admin.ui.opensaml.OpenSamlObjects import edu.internet2.tier.shibboleth.admin.ui.util.RandomGenerator import edu.internet2.tier.shibboleth.admin.ui.util.TestObjectGenerator import edu.internet2.tier.shibboleth.admin.util.AttributeUtility +import org.assertj.core.api.Assertions +import org.spockframework.spring.SpringBean +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.domain.EntityScan +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest +import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer +import org.springframework.boot.test.context.SpringBootContextLoader +import org.springframework.boot.test.context.SpringBootTest import org.springframework.boot.test.json.JacksonTester +import org.springframework.context.ApplicationContext +import org.springframework.context.annotation.PropertySource +import org.springframework.data.jpa.repository.config.EnableJpaRepositories +import org.springframework.test.annotation.DirtiesContext +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.web.WebAppConfiguration import org.xmlunit.builder.DiffBuilder import org.xmlunit.builder.Input import org.xmlunit.diff.DefaultNodeMatcher import org.xmlunit.diff.ElementSelectors import spock.lang.Specification +//@TestPropertySource("/application.yml") +//@ContextConfiguration(classes = [CoreShibUiConfiguration, CustomPropertiesConfiguration], initializers = ConfigFileApplicationContextInitializer.class) +@ContextConfiguration(classes=[CoreShibUiConfiguration, CustomPropertiesConfiguration]) +@SpringBootTest(classes = ShibbolethUiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.NONE) +@PropertySource("classpath:application.yml") class JPAEntityDescriptorServiceImplTests extends Specification { + @Autowired + CustomPropertiesConfiguration customPropertiesConfiguration + + @Autowired + FilterService filterService + + @Autowired + ApplicationContext context + def testObjectGenerator OpenSamlObjects openSamlObjects = new OpenSamlObjects().with { @@ -34,7 +60,7 @@ class JPAEntityDescriptorServiceImplTests extends Specification { } def service = new JPAEntityDescriptorServiceImpl(openSamlObjects, - new JPAEntityServiceImpl(openSamlObjects, new AttributeUtility(openSamlObjects))) + new JPAEntityServiceImpl(openSamlObjects, new AttributeUtility(openSamlObjects), customPropertiesConfiguration)) JacksonTester jacksonTester @@ -634,8 +660,8 @@ class JPAEntityDescriptorServiceImplTests extends Specification { then: // TODO: finish - // Assertions.assertThat(actualOutputJson).isEqualToJson('/json/SHIBUI-219-3.json') - assert true + Assertions.assertThat(actualOutputJson).isEqualToJson('/json/SHIBUI-219-3.json') +// assert true } def "SHIBUI-223"() { diff --git a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityServiceImplTests.groovy b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityServiceImplTests.groovy index 83a5c76f4..f3db3350e 100644 --- a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityServiceImplTests.groovy +++ b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/service/JPAEntityServiceImplTests.groovy @@ -1,5 +1,6 @@ package edu.internet2.tier.shibboleth.admin.ui.service +import edu.internet2.tier.shibboleth.admin.ui.configuration.CustomPropertiesConfiguration import edu.internet2.tier.shibboleth.admin.ui.configuration.InternationalizationConfiguration import edu.internet2.tier.shibboleth.admin.ui.configuration.TestConfiguration import edu.internet2.tier.shibboleth.admin.ui.configuration.CoreShibUiConfiguration diff --git a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/util/TestHelpers.groovy b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/util/TestHelpers.groovy index 29db1fb1d..a310e31dc 100644 --- a/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/util/TestHelpers.groovy +++ b/backend/src/test/groovy/edu/internet2/tier/shibboleth/admin/ui/util/TestHelpers.groovy @@ -1,7 +1,9 @@ package edu.internet2.tier.shibboleth.admin.ui.util import edu.internet2.tier.shibboleth.admin.ui.domain.frontend.RelyingPartyOverridesRepresentation +import groovy.xml.XmlUtil import org.apache.commons.lang.StringUtils +import org.codehaus.groovy.tools.xml.DomToGroovy import org.w3c.dom.Document import org.xmlunit.builder.DiffBuilder import org.xmlunit.builder.Input @@ -35,4 +37,8 @@ class TestHelpers { .build() .hasDifferences() } + + static String XmlDocumentToString(Document document) { + return XmlUtil.serialize(document.documentElement) + } } diff --git a/backend/src/test/resources/conf/278.2.xml b/backend/src/test/resources/conf/278.2.xml index 20b513e1f..269a2f3ec 100644 --- a/backend/src/test/resources/conf/278.2.xml +++ b/backend/src/test/resources/conf/278.2.xml @@ -28,7 +28,7 @@ - there + there https://sp1.example.org