[java-idp-integration-tests] 03/04: Adjust tests to new IdP layout
Tom Zeller
tzeller at dragonacea.biz
Thu May 18 00:04:18 UTC 2023
This is an automated email from the git hooks/post-receive script.
tzeller pushed a commit to branch main
in repository java-idp-integration-tests.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-integration-tests.git;a=commit;h=14c20b3c774375b138fb5e0e995bc028dd72bbc5
commit 14c20b3c774375b138fb5e0e995bc028dd72bbc5
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Wed May 17 18:28:17 2023 -0500
Adjust tests to new IdP layout
Remove the testbed as a dependency :
- copy storage record serializer from testbed
- extract messages.properties from idp-conf-impl JAR
Copy flows/ from distribution to idp.home
---
pom.xml | 14 --
.../idp/integration/tests/BaseIntegrationTest.java | 49 ++++++-
.../tests/clientstorage/ClientStorageTest.java | 1 -
.../SimpleStorageRecordSerializer.java | 144 +++++++++++++++++++++
4 files changed, 189 insertions(+), 19 deletions(-)
diff --git a/pom.xml b/pom.xml
index 2286e57..1160321 100644
--- a/pom.xml
+++ b/pom.xml
@@ -103,20 +103,6 @@
<scope>test</scope>
<version>${idp.version}</version>
</dependency>
- <dependency>
- <groupId>net.shibboleth.idp</groupId>
- <artifactId>idp-testbed</artifactId>
- <version>${testbed.version}</version>
- <scope>test</scope>
- <type>jar</type>
- <classifier>${testbed.classifier}</classifier>
- <exclusions>
- <exclusion>
- <groupId>org.ldaptive</groupId>
- <artifactId>ldaptive</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
index d63ba53..bf791dc 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
@@ -43,6 +43,7 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Properties;
import java.util.Random;
import java.util.Set;
@@ -50,6 +51,7 @@ import java.util.SortedSet;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Stream;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -500,6 +502,7 @@ public abstract class BaseIntegrationTest {
copyFromIdPDistToIdPHome("metadata");
copyFromIdPDistToIdPHome("credentials");
copyFromIdPDistToIdPHome("testbed-war");
+ copyFromIdPDistToIdPHome("flows");
// Path to conf/idp.properties
pathToIdPProperties = Paths.get(pathToIdPHome.toAbsolutePath().toString(), "conf", "idp.properties");
@@ -509,10 +512,7 @@ public abstract class BaseIntegrationTest {
pathToLDAPProperties = Paths.get(pathToIdPHome.toAbsolutePath().toString(), "conf", "ldap.properties");
Assert.assertTrue(pathToLDAPProperties.toFile().exists(), "Path to conf/ldap.properties not found");
- // Classpath messages.properties
- messagesPropertiesResource = new ClassPathResource("/net/shibboleth/idp/messages/messages.properties");
- Assert.assertTrue(messagesPropertiesResource.exists(), "Classpath resource messages.properties not found");
- log.debug("Path to message properties '{}'", messagesPropertiesResource);
+ loadMessagesProperties();
pathToIdPWAR = pathToIdPHome.resolve("war").resolve("idp.war").toAbsolutePath();
log.debug("Path to idp.war '{}'", pathToIdPWAR);
@@ -2560,4 +2560,45 @@ public abstract class BaseIntegrationTest {
Files.write(pathToFile, content.getBytes(charset));
}
+ /**
+ * Extract messages.properties from idp-conf-impl JAR and load as
+ * {@link messagesPropertiesResource}.
+ */
+ public void loadMessagesProperties() {
+
+ final Path pathToDistWebINFLib = pathToIdPHome.resolve(Paths.get("dist", "webapp", "WEB-INF", "lib"));
+ Assert.assertTrue(pathToDistWebINFLib.toFile().exists(), "Path to dist/webapp/WEB-INF/lib not found");
+
+ try (final Stream<Path> results = Files.find(pathToDistWebINFLib, Integer.MAX_VALUE,
+ (path, basicFileAttributes) -> path.toFile().getName().matches("idp-conf-impl-.*.jar"))) {
+
+ final Optional<Path> firstResult = results.findFirst();
+ Assert.assertTrue(firstResult.isPresent());
+
+ final Path pathToIdpConfImplJAR = firstResult.get().toAbsolutePath();
+ log.debug("Path to idp-conf-impl JAR '{}'", pathToIdpConfImplJAR);
+ Assert.assertTrue(pathToIdpConfImplJAR.toFile().exists(), "Path to idp-conf-impl JAR not found");
+
+ final String[] commands = new String[] { "jar", "xvf", pathToIdpConfImplJAR.toString(),
+ "net/shibboleth/idp/messages/messages.properties" };
+
+ final String logPrefix = "Extract messages.properties :";
+
+ final Process process = Runtime.getRuntime().exec(commands, null, pathToIdPHome.resolve("dist").toFile());
+
+ logProcess(process, logPrefix);
+
+ } catch (final IOException e) {
+ log.error("Error searching for additional properties", e);
+ }
+
+ final Path pathToMessagesProperties = pathToIdPHome
+ .resolve(Paths.get("dist", "net", "shibboleth", "idp", "messages", "messages.properties"));
+ Assert.assertTrue(pathToMessagesProperties.toFile().exists(), "Path to messages.properties not found");
+
+ messagesPropertiesResource = new FileSystemResource(pathToMessagesProperties);
+ Assert.assertTrue(messagesPropertiesResource.exists(), "Classpath resource messages.properties not found");
+ log.debug("Path to messages.properties '{}'", messagesPropertiesResource);
+ }
+
}
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/clientstorage/ClientStorageTest.java b/src/test/java/net/shibboleth/idp/integration/tests/clientstorage/ClientStorageTest.java
index 64f739e..1c7acb7 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/clientstorage/ClientStorageTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/clientstorage/ClientStorageTest.java
@@ -38,7 +38,6 @@ import org.testng.annotations.Test;
import net.shibboleth.idp.integration.tests.BaseIntegrationTest;
import net.shibboleth.idp.integration.tests.BrowserData;
import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
-import storage.SimpleStorageRecordSerializer;
/**
* Client storage tests.
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/clientstorage/SimpleStorageRecordSerializer.java b/src/test/java/net/shibboleth/idp/integration/tests/clientstorage/SimpleStorageRecordSerializer.java
new file mode 100644
index 0000000..80feab6
--- /dev/null
+++ b/src/test/java/net/shibboleth/idp/integration/tests/clientstorage/SimpleStorageRecordSerializer.java
@@ -0,0 +1,144 @@
+/*
+ * 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.integration.tests.clientstorage;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import javax.json.Json;
+import javax.json.JsonNumber;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.json.JsonReaderFactory;
+import javax.json.JsonStructure;
+import javax.json.stream.JsonGenerator;
+import javax.json.stream.JsonGeneratorFactory;
+
+import org.opensaml.storage.MutableStorageRecord;
+import org.opensaml.storage.StorageRecord;
+import org.opensaml.storage.StorageSerializer;
+
+import net.shibboleth.shared.annotation.constraint.NotEmpty;
+import net.shibboleth.shared.annotation.constraint.Positive;
+import net.shibboleth.shared.component.AbstractInitializableComponent;
+
+/**
+ * A simple {@link StorageRecord} serializer.
+ */
+public class SimpleStorageRecordSerializer extends AbstractInitializableComponent
+ implements StorageSerializer<StorageRecord> {
+
+ /** JSON generator factory. */
+ @Nonnull private final JsonGeneratorFactory generatorFactory;
+
+ /** JSON reader factory. */
+ @Nonnull private JsonReaderFactory readerFactory;
+
+ public SimpleStorageRecordSerializer() {
+ final Map<String, String> generatorConfig = new HashMap<>();
+ generatorConfig.put(JsonGenerator.PRETTY_PRINTING, "true");
+ generatorFactory = Json.createGeneratorFactory(generatorConfig);
+ readerFactory = Json.createReaderFactory(null);
+ }
+
+ /** {@inheritDoc} */
+ public String serialize(@Nonnull final StorageRecord instance) throws IOException {
+
+ final StringWriter sink = new StringWriter();
+ final JsonGenerator gen = generatorFactory.createGenerator(sink);
+
+ gen.writeStartObject();
+ gen.write("value", instance.getValue());
+ gen.write("version", instance.getVersion());
+ final Long expiration = instance.getExpiration();
+ if (expiration != null) {
+ gen.write("expiration", expiration);
+ }
+ gen.writeEnd().close();
+
+ return sink.toString();
+ }
+
+ /** {@inheritDoc} */
+ @Nonnull public StorageRecord deserialize(final long version, @Nonnull @NotEmpty final String context,
+ @Nonnull @NotEmpty final String key, @Nonnull @NotEmpty final String value, @Nullable Long expiration)
+ throws IOException {
+ final VersionableStorageRecord record = new VersionableStorageRecord(value, expiration);
+ record.setVersion(version);
+ return record;
+ }
+
+ /**
+ * Returns an object recovered from the context, key, and string produced through the {@link #serialize} method.
+ *
+ * @param context storage record context
+ * @param key storage record key
+ * @param serialized serialized storage record
+ * @return a deserialized object
+ * @throws IOException if an error occurs
+ */
+ @Nonnull public StorageRecord deserialize(@Nonnull @NotEmpty final String context,
+ @Nonnull @NotEmpty final String key, @Nonnull final String serialized) throws IOException {
+ final JsonReader reader = readerFactory.createReader(new StringReader(serialized));
+ final JsonStructure st = reader.read();
+ if (!(st instanceof JsonObject)) {
+ throw new IOException("Found invalid data structure");
+ }
+ final JsonObject obj = (JsonObject) st;
+ final String value = obj.getString("value");
+ final int version = obj.getInt("version");
+ Long expiration = null;
+ final JsonNumber jsonExpiration = obj.getJsonNumber("expiration");
+ if (jsonExpiration != null) {
+ expiration = Long.valueOf(jsonExpiration.longValueExact());
+ }
+
+ return deserialize(version, context, key, value, expiration);
+ }
+
+ /**
+ * Exposes mutation of {@link StorageRecord} properties including version.
+ */
+ private class VersionableStorageRecord extends MutableStorageRecord {
+
+ /**
+ * Constructor.
+ *
+ * @param val value
+ * @param exp expiration or null if none
+ */
+ public VersionableStorageRecord(@Nonnull @NotEmpty final String val, @Nullable final Long exp) {
+ super(val, exp);
+ }
+
+ /**
+ * Set the record version.
+ *
+ * @param version record version; must be positive.
+ */
+ @Override protected void setVersion(@Positive final long version) {
+ super.setVersion(version);
+ }
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list