[java-identity-provider] branch main updated: Refactor attribute tests.
Scott Cantor
cantor.2 at osu.edu
Tue Sep 20 14:23:21 UTC 2022
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=e11c214072d0a25b578b59aaae786d9bd067ff10
The following commit(s) were added to refs/heads/main by this push:
new e11c21407 Refactor attribute tests.
e11c21407 is described below
commit e11c214072d0a25b578b59aaae786d9bd067ff10
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Sep 20 10:23:18 2022 -0400
Refactor attribute tests.
---
idp-authn-impl/pom.xml | 12 +-
.../impl/BaseAttributeDefinitionParserTest.java | 203 +++++++++++++++++++++
...ontextDerivedAttributeDefinitionParserTest.java | 1 -
.../impl/SubjectDataConnectorParserTest.java | 1 -
idp-profile-impl/pom.xml | 11 +-
5 files changed, 206 insertions(+), 22 deletions(-)
diff --git a/idp-authn-impl/pom.xml b/idp-authn-impl/pom.xml
index faccae9cf..4b68ffed5 100644
--- a/idp-authn-impl/pom.xml
+++ b/idp-authn-impl/pom.xml
@@ -229,26 +229,16 @@
<artifactId>shib-attribute-resolver-impl</artifactId>
<scope>test</scope>
</dependency>
-
- <dependency>
- <groupId>net.shibboleth</groupId>
- <artifactId>shib-attribute-resolver-api</artifactId>
- <scope>test</scope>
- <type>test-jar</type>
- </dependency>
-
<!-- Required despite dependency:analyze. -->
<dependency>
<groupId>net.shibboleth</groupId>
<artifactId>shib-attribute-resolver-spring</artifactId>
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>net.shibboleth</groupId>
- <artifactId>shib-attribute-resolver-spring</artifactId>
+ <artifactId>shib-attribute-testing</artifactId>
<scope>test</scope>
- <type>test-jar</type>
</dependency>
<dependency>
diff --git a/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/context/impl/BaseAttributeDefinitionParserTest.java b/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/context/impl/BaseAttributeDefinitionParserTest.java
new file mode 100644
index 000000000..7af9c7585
--- /dev/null
+++ b/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/context/impl/BaseAttributeDefinitionParserTest.java
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.idp.authn.context.impl;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.opensaml.core.testing.OpenSAMLInitBaseTestCase;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ConversionServiceFactoryBean;
+import org.springframework.context.support.GenericApplicationContext;
+import org.testng.annotations.AfterMethod;
+
+import net.shibboleth.idp.attribute.resolver.AttributeDefinition;
+import net.shibboleth.idp.attribute.resolver.DataConnector;
+import net.shibboleth.idp.attribute.resolver.impl.AttributeResolverImpl;
+import net.shibboleth.idp.attribute.resolver.spring.ad.BaseAttributeDefinitionParser;
+import net.shibboleth.idp.attribute.resolver.spring.ad.impl.SimpleAttributeDefinitionParser;
+import net.shibboleth.idp.attribute.resolver.spring.impl.AttributeResolverServiceStrategy;
+import net.shibboleth.shared.spring.config.IdentifiableBeanPostProcessor;
+import net.shibboleth.shared.spring.config.StringToDurationConverter;
+import net.shibboleth.shared.spring.config.StringToIPRangeConverter;
+import net.shibboleth.shared.spring.config.StringToResourceConverter;
+import net.shibboleth.shared.spring.context.FilesystemGenericApplicationContext;
+import net.shibboleth.shared.spring.custom.SchemaTypeAwareXMLBeanDefinitionReader;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+
+/**
+ * Base class for tests for {@link SimpleAttributeDefinitionParser} and by extension {@link BaseAttributeDefinitionParser}.
+ *
+ * Note that several helper classes are marked private. This is purely to discourage accidental use of non validating
+ * parsers with no need.
+ */
+ at SuppressWarnings("javadoc")
+public abstract class BaseAttributeDefinitionParserTest extends OpenSAMLInitBaseTestCase {
+
+ public static final String BEAN_FILE_PATH = "net/shibboleth/idp/attribute/resolver/spring/";
+
+ public static final String ATTRIBUTE_FILE_PATH = BEAN_FILE_PATH + "ad/";
+
+ public static final String DATACONNECTOR_FILE_PATH = BEAN_FILE_PATH + "dc/";
+
+ public static final String ENCODER_FILE_PATH = BEAN_FILE_PATH + "enc/";
+
+ public static final String PRINCIPALCONNECTOR_FILE_PATH = BEAN_FILE_PATH + "pc/";
+
+ protected GenericApplicationContext pendingTeardownContext = null;
+
+ @AfterMethod public void tearDownTestContext() {
+ if (null == pendingTeardownContext ) {
+ return;
+ }
+ pendingTeardownContext.close();
+ pendingTeardownContext = null;
+ }
+
+ protected void setTestContext(final GenericApplicationContext context) {
+ tearDownTestContext();
+ pendingTeardownContext = context;
+ }
+
+ private void loadFile(final String fileName, final GenericApplicationContext context, final boolean supressValid) {
+ final SchemaTypeAwareXMLBeanDefinitionReader beanDefinitionReader =
+ new SchemaTypeAwareXMLBeanDefinitionReader(context);
+
+ if (supressValid) {
+ beanDefinitionReader.setValidating(false);
+ }
+
+ beanDefinitionReader.loadBeanDefinitions(fileName, BEAN_FILE_PATH + "customBean.xml");
+ }
+
+ protected void loadFile(final String fileName, final GenericApplicationContext context) {
+ loadFile(fileName, context, false);
+ }
+
+ protected <Type> Type getBean(final String fileName, final Class<Type> claz, final GenericApplicationContext context,
+ final boolean supressValid) {
+
+ final ConversionServiceFactoryBean service = new ConversionServiceFactoryBean();
+ service.setConverters(new HashSet<>(Arrays.asList(
+ new StringToIPRangeConverter(),
+ new StringToResourceConverter(),
+ new StringToDurationConverter())));
+ service.afterPropertiesSet();
+
+ context.getBeanFactory().setConversionService(service.getObject());
+
+ loadFile(fileName, context, supressValid);
+
+ context.refresh();
+
+ final Collection<Type> beans = context.getBeansOfType(claz).values();
+ assertEquals(beans.size(), 1);
+
+ return beans.iterator().next();
+ }
+
+ protected <Type> Type getBean(final String fileName, final Class<Type> claz, final GenericApplicationContext context) {
+ return getBean(fileName, claz, context, false);
+ }
+
+ protected <Type extends AttributeDefinition> Type getAttributeDefn(final String fileName, final Class<Type> claz,
+ final GenericApplicationContext context) {
+
+ return getBean(ATTRIBUTE_FILE_PATH + fileName, claz, context);
+ }
+
+ private <Type extends AttributeDefinition> Type getAttributeDefn(final String fileName, final Class<Type> claz,
+ final GenericApplicationContext context, final boolean supressValidation) {
+
+ return getBean(ATTRIBUTE_FILE_PATH + fileName, claz, context, supressValidation);
+ }
+
+ protected <Type extends AttributeDefinition> Type getAttributeDefn(final String fileName, final String beanFileName,
+ final Class<Type> claz) {
+ return getAttributeDefn(fileName, beanFileName, claz, false);
+
+ }
+
+ private <Type extends AttributeDefinition> Type getAttributeDefn(final String fileName, final String beanFileName,
+ final Class<Type> claz, final boolean supressValidation) {
+
+ final GenericApplicationContext context = new GenericApplicationContext();
+ setTestContext(context);
+ context.setDisplayName("ApplicationContext: " + claz);
+ final XmlBeanDefinitionReader configReader = new SchemaTypeAwareXMLBeanDefinitionReader(context);
+
+ final ConversionServiceFactoryBean service = new ConversionServiceFactoryBean();
+ service.setConverters(new HashSet<>(Arrays.asList(
+ new StringToIPRangeConverter(),
+ new StringToResourceConverter(),
+ new StringToDurationConverter())));
+ service.afterPropertiesSet();
+
+ context.getBeanFactory().setConversionService(service.getObject());
+
+ configReader.loadBeanDefinitions(BEAN_FILE_PATH + beanFileName);
+
+ return getAttributeDefn(fileName, claz, context, supressValidation);
+ }
+
+ protected <Type extends AttributeDefinition> Type getAttributeDefn(final String fileName, final Class<Type> claz) {
+ return getAttributeDefn(fileName, claz, false);
+
+ }
+
+ protected <Type extends AttributeDefinition> Type getAttributeDefn(final String fileName, final Class<Type> claz,
+ final boolean supressValid) {
+
+ final GenericApplicationContext context = new FilesystemGenericApplicationContext();
+ setTestContext(context);
+ context.setDisplayName("ApplicationContext: " + claz);
+
+ return getAttributeDefn(fileName, claz, context, supressValid);
+ }
+
+ protected <Type extends DataConnector> Type getDataConnector(final String fileName, final Class<Type> claz) {
+ return getDataConnector(fileName, claz, false);
+ }
+
+ private <Type extends DataConnector> Type
+ getDataConnector(final String fileName, final Class<Type> claz, final boolean supressValid) {
+
+ final GenericApplicationContext context = new GenericApplicationContext();
+ context.getBeanFactory().addBeanPostProcessor(new IdentifiableBeanPostProcessor());
+ setTestContext(context);
+ context.setDisplayName("ApplicationContext: " + claz);
+
+ return getBean(DATACONNECTOR_FILE_PATH + fileName, claz, context, supressValid);
+ }
+
+ static public AttributeResolverImpl getResolver(final ApplicationContext appCtx) {
+ final AttributeResolverServiceStrategy strategy = new AttributeResolverServiceStrategy();
+ strategy.setId("testResolver");
+ try {
+ strategy.initialize();
+ } catch (final ComponentInitializationException e) {
+ return null;
+ }
+ return (AttributeResolverImpl) strategy.apply(appCtx);
+ }
+
+}
diff --git a/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/context/impl/ContextDerivedAttributeDefinitionParserTest.java b/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/context/impl/ContextDerivedAttributeDefinitionParserTest.java
index dd3a4a118..fc063e502 100644
--- a/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/context/impl/ContextDerivedAttributeDefinitionParserTest.java
+++ b/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/context/impl/ContextDerivedAttributeDefinitionParserTest.java
@@ -38,7 +38,6 @@ import net.shibboleth.idp.attribute.resolver.ad.impl.ContextDerivedAttributeDefi
import net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext;
import net.shibboleth.idp.attribute.resolver.spring.ad.impl.ContextDerivedAttributeDefinitionParser;
import net.shibboleth.idp.attribute.resolver.spring.ad.impl.SubjectDerivedAttributeDefinitionParser;
-import net.shibboleth.idp.attribute.resolver.spring.testing.BaseAttributeDefinitionParserTest;
import net.shibboleth.idp.attribute.resolver.testing.TestSources;
import net.shibboleth.idp.authn.AuthenticationResult;
import net.shibboleth.idp.authn.context.SubjectCanonicalizationContext;
diff --git a/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/context/impl/SubjectDataConnectorParserTest.java b/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/context/impl/SubjectDataConnectorParserTest.java
index 6bd4cf379..e8231be99 100644
--- a/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/context/impl/SubjectDataConnectorParserTest.java
+++ b/idp-authn-impl/src/test/java/net/shibboleth/idp/authn/context/impl/SubjectDataConnectorParserTest.java
@@ -25,7 +25,6 @@ import org.testng.annotations.Test;
import net.shibboleth.idp.attribute.resolver.dc.impl.ContextDerivedDataConnector;
import net.shibboleth.idp.attribute.resolver.spring.dc.impl.SubjectDataConnectorParser;
-import net.shibboleth.idp.attribute.resolver.spring.testing.BaseAttributeDefinitionParserTest;
/**
* test for {@link SubjectDataConnectorParser}
diff --git a/idp-profile-impl/pom.xml b/idp-profile-impl/pom.xml
index 4732416d2..5e8da4fad 100644
--- a/idp-profile-impl/pom.xml
+++ b/idp-profile-impl/pom.xml
@@ -124,12 +124,6 @@
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>net.shibboleth</groupId>
- <artifactId>shib-attribute-filter-api</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>net.shibboleth</groupId>
<artifactId>shib-attribute-filter-impl</artifactId>
@@ -137,13 +131,12 @@
</dependency>
<dependency>
<groupId>net.shibboleth</groupId>
- <artifactId>shib-attribute-resolver-api</artifactId>
- <type>test-jar</type>
+ <artifactId>shib-attribute-resolver-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.shibboleth</groupId>
- <artifactId>shib-attribute-resolver-impl</artifactId>
+ <artifactId>shib-attribute-testing</artifactId>
<scope>test</scope>
</dependency>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list