[java-idp-integration-tests] 10/10: Conditionally run Linux, IdP V5+, and conformance OP tests
Tom Zeller
tzeller at dragonacea.biz
Wed Aug 28 22:38:38 UTC 2024
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=345cb9c2750c3e9daa2bac29ea114b7dcfafb865
commit 345cb9c2750c3e9daa2bac29ea114b7dcfafb865
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Wed Aug 28 01:30:23 2024 -0500
Conditionally run Linux, IdP V5+, and conformance OP tests
Use a TestNG method interceptor to ignore test methods based on custom
annotations.
---
.../idp/integration/tests/BaseIntegrationTest.java | 31 +++++
.../idp/integration/tests/oidc/AbstractOPTest.java | 3 +
.../integration/tests/oidc/OPConformanceTest.java | 19 ++-
.../idp/integration/tests/oidc/OPTest.java | 11 +-
.../tests/util/testng/IgnoreTestIntercepter.java | 130 +++++++++++++++++++++
.../tests/util/testng/annotation/IdPV5OrLater.java | 13 +++
.../tests/util/testng/annotation/LinuxOnly.java | 13 +++
.../util/testng/annotation/OPConformance.java | 13 +++
8 files changed, 217 insertions(+), 16 deletions(-)
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 122bef5..b7381d2 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
@@ -21,6 +21,7 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.io.UncheckedIOException;
import java.lang.ProcessBuilder.Redirect;
import java.lang.reflect.Method;
import java.net.InetAddress;
@@ -3135,4 +3136,34 @@ public abstract class BaseIntegrationTest {
}
}
+ /**
+ * Get IdP version being tested.
+ *
+ * @return version of IdP being tested or null if none found
+ * @throws UncheckedIOException
+ * if more than one IdP distribution is found
+ */
+ public static String idpVersion() {
+ // IdP distribution name pattern
+ final String regex = "shibboleth-identity-provider-(.*)";
+
+ // Find IdP distributions in test-distributions directory
+ final List<String> idpDistributionsFound = new ArrayList<String>();
+ try (Stream<Path> results = Files.find(Paths.get(TEST_DISTRIBUTIONS_DIRECTORY), 1,
+ (path, basicFileAttributes) -> path.toFile().getName().matches(regex))) {
+ results.forEach(path -> idpDistributionsFound.add(path.toString()));
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+
+ // Should only find 1 IdP distribution
+ if (idpDistributionsFound.size() != 1) {
+ throw new RuntimeException("Should find one IdP distribution");
+ }
+
+ // Determine IdP version from distribution name
+ final Matcher matcher = Pattern.compile(regex).matcher(idpDistributionsFound.get(0));
+ return matcher.find() ? matcher.group(1) : null;
+ }
+
}
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/oidc/AbstractOPTest.java b/src/test/java/net/shibboleth/idp/integration/tests/oidc/AbstractOPTest.java
index 1423971..7b78461 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/oidc/AbstractOPTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/oidc/AbstractOPTest.java
@@ -33,13 +33,16 @@ import org.slf4j.LoggerFactory;
import org.testcontainers.containers.Container.ExecResult;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Listeners;
import net.shibboleth.idp.integration.tests.BaseIntegrationTest;
+import net.shibboleth.idp.integration.tests.util.testng.IgnoreTestIntercepter;
import net.shibboleth.shared.component.ComponentInitializationException;
/**
* Abstract OIDC OP integration test.
*/
+ at Listeners(value = IgnoreTestIntercepter.class)
public class AbstractOPTest extends BaseIntegrationTest {
/** Class logger. */
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/oidc/OPConformanceTest.java b/src/test/java/net/shibboleth/idp/integration/tests/oidc/OPConformanceTest.java
index 4e050a3..e8111c1 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/oidc/OPConformanceTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/oidc/OPConformanceTest.java
@@ -30,6 +30,9 @@ import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import net.shibboleth.idp.integration.tests.util.testng.annotation.IdPV5OrLater;
+import net.shibboleth.idp.integration.tests.util.testng.annotation.LinuxOnly;
+import net.shibboleth.idp.integration.tests.util.testng.annotation.OPConformance;
import net.shibboleth.shared.component.ComponentInitializationException;
/**
@@ -236,13 +239,11 @@ public class OPConformanceTest extends AbstractOPTest {
}
@Test
+ @IdPV5OrLater
+ @LinuxOnly
+ @OPConformance
public void testBasicCertificationProfileAuthorization() throws Exception {
- if (isWindows() || idpVersion.startsWith("4")) {
- log.debug("Skipping OP conformance suite test, only runs IdP V5 on Linux with Jetty");
- return;
- }
-
final String description = "basic certification profile authorization test";
final String testPlan = //
@@ -255,13 +256,11 @@ public class OPConformanceTest extends AbstractOPTest {
}
@Test
+ @IdPV5OrLater
+ @LinuxOnly
+ @OPConformance
public void testConfigCertificationProfileAuthorization() throws Exception {
- if (isWindows() || idpVersion.startsWith("4")) {
- log.debug("Skipping OP conformance suite test, only runs IdP V5 on Linux with Jetty");
- return;
- }
-
final String description = "config certification profile authorization test";
final String testPlan = //
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/oidc/OPTest.java b/src/test/java/net/shibboleth/idp/integration/tests/oidc/OPTest.java
index 0b8279c..d650748 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/oidc/OPTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/oidc/OPTest.java
@@ -25,6 +25,9 @@ import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import net.shibboleth.idp.integration.tests.util.testng.annotation.IdPV5OrLater;
+import net.shibboleth.idp.integration.tests.util.testng.annotation.LinuxOnly;
+
/**
* Test the OIDC OP plugin for the IdP.
*/
@@ -48,14 +51,10 @@ public class OPTest extends AbstractOPTest {
* if an error occurs
*/
@Test
+ @IdPV5OrLater
+ @LinuxOnly
public void testSSO() throws Exception {
- // Only run if IdP V5 or later on Linux
- if (isWindows() || idpVersion.startsWith("4")) {
- log.debug("Skipping OIDC test, only runs IdP V5 on Linux with Jetty");
- return;
- }
-
// Install OIDC OP plugin
final String[] plugins = new String[] { //
"net.shibboleth.oidc.common", //
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/util/testng/IgnoreTestIntercepter.java b/src/test/java/net/shibboleth/idp/integration/tests/util/testng/IgnoreTestIntercepter.java
new file mode 100644
index 0000000..4e06479
--- /dev/null
+++ b/src/test/java/net/shibboleth/idp/integration/tests/util/testng/IgnoreTestIntercepter.java
@@ -0,0 +1,130 @@
+
+package net.shibboleth.idp.integration.tests.util.testng;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Nonnull;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.IMethodInstance;
+import org.testng.IMethodInterceptor;
+import org.testng.ITestContext;
+
+import net.shibboleth.idp.integration.tests.BaseIntegrationTest;
+import net.shibboleth.idp.integration.tests.util.testng.annotation.IdPV5OrLater;
+import net.shibboleth.idp.integration.tests.util.testng.annotation.LinuxOnly;
+import net.shibboleth.idp.integration.tests.util.testng.annotation.OPConformance;
+
+/**
+ * Ignore tests which do not satisfy custom annotations.
+ */
+public class IgnoreTestIntercepter implements IMethodInterceptor {
+
+ /** Class logger. */
+ @Nonnull
+ private final Logger log = LoggerFactory.getLogger(IgnoreTestIntercepter.class);
+
+ /**
+ * Ignore test methods which do not satisfy custom annotations.
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
+
+ final List<IMethodInstance> filteredTestMethods = new ArrayList<IMethodInstance>();
+
+ for (final IMethodInstance method : methods) {
+
+ if (!idpV5OrLater(method)) {
+ log.debug("Skipping IdP V5 or later test '{}'", method);
+ continue;
+ }
+
+ if (!linuxOnly(method)) {
+ log.debug("Skipping Linux only test '{}'", method);
+ continue;
+ }
+
+ if (!opConformance(method)) {
+ log.debug("Skipping OP Conformance test '{}'", method);
+ continue;
+ }
+
+ filteredTestMethods.add(method);
+ }
+
+ return filteredTestMethods;
+ }
+
+ /**
+ * Return false if test is annotated as {@link IdPV5OrLater} and IdP major
+ * version is less than 5.
+ *
+ * @param method
+ * the test method
+ * @return return false if test is annotated as {@link IdPV5OrLater} and IdP
+ * major version is less than 5, true otherwise.
+ */
+ public boolean idpV5OrLater(final IMethodInstance method) {
+
+ final IdPV5OrLater idpV5Only = method.getMethod()
+ .getConstructorOrMethod()
+ .getMethod()
+ .getAnnotation(IdPV5OrLater.class);
+
+ if (idpV5Only != null && Integer.parseInt(BaseIntegrationTest.idpVersion().substring(0, 1)) < 5) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Return false if test is annotated as {@link LinuxOnly} and OS is Windows.
+ *
+ * @param method
+ * the test method
+ * @return return false if test is annotated as LinuxOnly and OS is Windows,
+ * true otherwise.
+ */
+ public boolean linuxOnly(final IMethodInstance method) {
+
+ final LinuxOnly linuxOnly = method.getMethod()
+ .getConstructorOrMethod()
+ .getMethod()
+ .getAnnotation(LinuxOnly.class);
+
+ if (linuxOnly != null && BaseIntegrationTest.isWindows()) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Return false if test is annotated as {@link OPConformance} and
+ * 'OPConformance' system property is not 'true'.
+ *
+ * @param method
+ * the test method
+ * @return return false if test is annotated as OPConformance and
+ * 'OPConformance' system property is not 'true', true otherwise.
+ */
+ public boolean opConformance(final IMethodInstance method) {
+
+ final OPConformance opConformance = method.getMethod()
+ .getConstructorOrMethod()
+ .getMethod()
+ .getAnnotation(OPConformance.class);
+
+ if (opConformance != null && !Boolean.getBoolean("OPConformance")) {
+ return false;
+ }
+
+ return true;
+ }
+
+}
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/util/testng/annotation/IdPV5OrLater.java b/src/test/java/net/shibboleth/idp/integration/tests/util/testng/annotation/IdPV5OrLater.java
new file mode 100644
index 0000000..b000f82
--- /dev/null
+++ b/src/test/java/net/shibboleth/idp/integration/tests/util/testng/annotation/IdPV5OrLater.java
@@ -0,0 +1,13 @@
+
+package net.shibboleth.idp.integration.tests.util.testng.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target(ElementType.METHOD)
+public @interface IdPV5OrLater {
+
+}
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/util/testng/annotation/LinuxOnly.java b/src/test/java/net/shibboleth/idp/integration/tests/util/testng/annotation/LinuxOnly.java
new file mode 100644
index 0000000..00f920d
--- /dev/null
+++ b/src/test/java/net/shibboleth/idp/integration/tests/util/testng/annotation/LinuxOnly.java
@@ -0,0 +1,13 @@
+
+package net.shibboleth.idp.integration.tests.util.testng.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target(ElementType.METHOD)
+public @interface LinuxOnly {
+
+}
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/util/testng/annotation/OPConformance.java b/src/test/java/net/shibboleth/idp/integration/tests/util/testng/annotation/OPConformance.java
new file mode 100644
index 0000000..c2bc103
--- /dev/null
+++ b/src/test/java/net/shibboleth/idp/integration/tests/util/testng/annotation/OPConformance.java
@@ -0,0 +1,13 @@
+
+package net.shibboleth.idp.integration.tests.util.testng.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target(ElementType.METHOD)
+public @interface OPConformance {
+
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list