[java-identity-provider] branch main updated: Remove DatabaseTestingSupport from the IdP and rely on the one in shib-testing

Rod Widdowson rdw at steadingsoftware.com
Sat Oct 1 12:50:39 UTC 2022


This is an automated email from the git hooks/post-receive script.

rdw 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=0e527c1c2d75f5940d2701b7a32c044968d936da

The following commit(s) were added to refs/heads/main by this push:
     new 0e527c1c2 Remove DatabaseTestingSupport from the IdP and rely on the one in shib-testing
0e527c1c2 is described below

commit 0e527c1c2d75f5940d2701b7a32c044968d936da
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Sep 30 14:44:06 2022 +0100

    Remove DatabaseTestingSupport from the IdP and rely on the one in shib-testing
---
 .../impl/PersistentSAML2NameIDGeneratorTest.java   |   2 +-
 .../nameid/impl/StoredPersistentIdDecoderTest.java |  24 ++--
 .../idp/saml/impl/testing/TestSources.java         |   7 +-
 .../idp/testing/DatabaseTestingSupport.java        | 152 ---------------------
 4 files changed, 16 insertions(+), 169 deletions(-)

diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/nameid/impl/PersistentSAML2NameIDGeneratorTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/nameid/impl/PersistentSAML2NameIDGeneratorTest.java
index 8544cd60f..d529c3efc 100644
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/nameid/impl/PersistentSAML2NameIDGeneratorTest.java
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/nameid/impl/PersistentSAML2NameIDGeneratorTest.java
@@ -31,7 +31,7 @@ import net.shibboleth.idp.authn.context.SubjectContext;
 import net.shibboleth.idp.profile.context.RelyingPartyContext;
 import net.shibboleth.idp.profile.testing.RequestContextBuilder;
 import net.shibboleth.idp.saml.impl.testing.TestSources;
-import net.shibboleth.idp.testing.DatabaseTestingSupport;
+import net.shibboleth.shared.testing.DatabaseTestingSupport;
 import net.shibboleth.shared.component.ComponentInitializationException;
 
 import org.opensaml.core.testing.OpenSAMLInitBaseTestCase;
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/nameid/impl/StoredPersistentIdDecoderTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/nameid/impl/StoredPersistentIdDecoderTest.java
index 41c435e4f..e5968034c 100644
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/nameid/impl/StoredPersistentIdDecoderTest.java
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/nameid/impl/StoredPersistentIdDecoderTest.java
@@ -23,6 +23,17 @@ import java.util.Collections;
 
 import javax.sql.DataSource;
 
+import org.opensaml.core.testing.OpenSAMLInitBaseTestCase;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.saml.saml2.core.NameID;
+import org.opensaml.saml.saml2.core.Subject;
+import org.opensaml.saml.saml2.testing.SAML2ActionTestingSupport;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
 import net.shibboleth.idp.attribute.IdPAttribute;
 import net.shibboleth.idp.attribute.StringAttributeValue;
 import net.shibboleth.idp.attribute.context.AttributeContext;
@@ -33,19 +44,8 @@ import net.shibboleth.idp.profile.context.RelyingPartyContext;
 import net.shibboleth.idp.profile.testing.RequestContextBuilder;
 import net.shibboleth.idp.saml.impl.testing.TestSources;
 import net.shibboleth.idp.saml.nameid.NameDecoderException;
-import net.shibboleth.idp.testing.DatabaseTestingSupport;
 import net.shibboleth.shared.component.ComponentInitializationException;
-
-import org.opensaml.core.testing.OpenSAMLInitBaseTestCase;
-import org.opensaml.profile.context.ProfileRequestContext;
-import org.opensaml.saml.saml2.core.NameID;
-import org.opensaml.saml.saml2.core.Subject;
-import org.opensaml.saml.saml2.testing.SAML2ActionTestingSupport;
-import org.testng.Assert;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
+import net.shibboleth.shared.testing.DatabaseTestingSupport;
 
 /** Test for {@link StoredPersistentIdDecoder}. */
 public class StoredPersistentIdDecoderTest extends OpenSAMLInitBaseTestCase {
diff --git a/idp-testing/src/main/java/net/shibboleth/idp/saml/impl/testing/TestSources.java b/idp-testing/src/main/java/net/shibboleth/idp/saml/impl/testing/TestSources.java
index 1286b74f8..b214c3df3 100644
--- a/idp-testing/src/main/java/net/shibboleth/idp/saml/impl/testing/TestSources.java
+++ b/idp-testing/src/main/java/net/shibboleth/idp/saml/impl/testing/TestSources.java
@@ -43,7 +43,6 @@ import net.shibboleth.idp.attribute.resolver.ResolverDataConnectorDependency;
 import net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext;
 import net.shibboleth.idp.attribute.resolver.context.AttributeResolverWorkContext;
 import net.shibboleth.idp.saml.attribute.resolver.impl.SAML2NameIDAttributeDefinition;
-import net.shibboleth.idp.testing.DatabaseTestingSupport;
 import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.shared.annotation.constraint.NonnullElements;
 import net.shibboleth.shared.annotation.constraint.NullableElements;
@@ -108,11 +107,11 @@ public final class TestSources {
     /** Authentication method for Principal method tests */
     public static final String TEST_AUTHN_METHOD = "AuthNmEthod";
 
-    public static final String IDP_ENTITY_ID = DatabaseTestingSupport.IDP_ENTITY_ID;
+    public static final String IDP_ENTITY_ID = "https://idp.example.org/idp";
 
-    public static final String PRINCIPAL_ID = DatabaseTestingSupport.PRINCIPAL_ID;
+    public static final String PRINCIPAL_ID = "PETER_THE_PRINCIPAL";
 
-    public static final String SP_ENTITY_ID = DatabaseTestingSupport.SP_ENTITY_ID;
+    public static final String SP_ENTITY_ID = "https://sp.example.org/sp";
 
     /** Constructor. */
     private TestSources() {
diff --git a/idp-testing/src/main/java/net/shibboleth/idp/testing/DatabaseTestingSupport.java b/idp-testing/src/main/java/net/shibboleth/idp/testing/DatabaseTestingSupport.java
deleted file mode 100644
index 987d74ce2..000000000
--- a/idp-testing/src/main/java/net/shibboleth/idp/testing/DatabaseTestingSupport.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * 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.testing;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import javax.sql.DataSource;
-
-import org.hsqldb.jdbc.JDBCDataSource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.io.CharStreams;
-
-import net.shibboleth.shared.primitive.StringSupport;
-
-/**
- *
- */
-public class DatabaseTestingSupport {
-
-    static Logger log = LoggerFactory.getLogger(DatabaseTestingSupport.class);
-    
-    public static final String IDP_ENTITY_ID = "https://idp.example.org/idp";
-
-    public static final String PRINCIPAL_ID = "PETER_THE_PRINCIPAL";
-
-    public static final String SP_ENTITY_ID = "https://sp.example.org/sp";
-    
-
-    public static void InitializeDataSource(@Nullable String initializingSQLFile, DataSource source) {
-
-        final String sql = ReadSqlFromFile(initializingSQLFile);
-        if (sql == null) {
-            return;
-        }
-        ExecuteUpdate(sql, source);
-    }
-
-    protected static String ReadSqlFromFile(@Nullable String initializingSQLFile) {
-
-        final String file = StringSupport.trimOrNull(initializingSQLFile);
-
-        if (null == file) {
-            return null;
-        }
-
-        final InputStream is = DatabaseTestingSupport.class.getResourceAsStream(file);
-
-        if (null == is) {
-            log.warn("Could not locate SQL file called {} ", file);
-            return null;
-        }
-        String sql;
-        try {
-            sql = StringSupport.trimOrNull(CharStreams.toString(new InputStreamReader(is)));
-        } catch (IOException e) {
-            log.warn("Could not read SQL file called {}.", file);
-            return null;
-        }
-
-        if (null == sql) {
-            log.warn("SQL file called {} was empty.", file);
-            return null;
-        }
-
-        return sql;
-    }
-
-    protected static void ExecuteUpdate(@Nullable String sql, DataSource source) {
-
-        log.debug("Applying SQL: \n {}", sql);
-
-        try {
-            Connection dbConn = source.getConnection();
-            Statement statement = dbConn.createStatement();
-
-            statement.executeUpdate(sql);
-        } catch (SQLException e) {
-            log.warn("Could not contact data source {} or execute commands", source, e);
-            return;
-        }
-    }
-
-    /**
-     * Summons up an in memory database with the provided identifier. The contents of the resource stream (if any) are
-     * then submitted to the database (so as to allow initializing to a known state.
-     * 
-     * @param initializingSQLFile a file in the classpath with SQL files. For instance
-     *            "/data/net/shibboleth/idp/attribute/resolver/impl/dc/StoredIdStore.sql"
-     * @param identifier a name to uniquify this database.
-     * @return a DataSource which can then be used for testing.
-     */
-    public static DataSource GetMockDataSource(@Nullable String initializingSQLFile, @Nonnull String identifier) {
-
-        return GetDataSourceFromUrl(initializingSQLFile, "jdbc:hsqldb:mem:" + identifier);
-    }
-
-    /**
-     * Summons up a database connection to  an hsqldb server running somewhere.
-     * @param initializingSQLFile a file in the classpath with SQL files. For instance
-     *            "/data/net/shibboleth/idp/attribute/resolver/impl/dc/StoredIdStore.sql"
-     * @param server the server name and database name.  For instance "//localhost/testdb"
-     * @return a DataSource which can then be used for testing
-     */
-    public static DataSource GetDataSourceFromHsqlServer(@Nullable String initializingSQLFile, @Nonnull String server) {
-
-        return GetDataSourceFromUrl(initializingSQLFile, "jdbc:hsqldb:hsql:" + server);
-    }
-
-    public static void InitializeDataSourceFromFile(String sqlFile, DataSource source) {
-        final String sql = ReadSqlFromFile(sqlFile);
-        final String[] statements = sql.split(";");
-        for (String statement : statements) {
-            ExecuteUpdate(statement.trim(), source);
-        }
-    }
-
-    protected static DataSource GetDataSourceFromUrl(String initializingSQLFile, String JdbcUri) {
-        JDBCDataSource jdbcSource = new JDBCDataSource();
-
-        jdbcSource.setUrl(JdbcUri);
-        jdbcSource.setUser("SA");
-        jdbcSource.setPassword("");
-
-        InitializeDataSource(initializingSQLFile, jdbcSource);
-
-        return jdbcSource;
-    }
-}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list