[java-oidfed-common] 01/03: Improve flow tests especially for content fetching verifications
Codeberg
noreply at shibboleth.net
Fri Nov 13 16:46:58 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch main
in repository java-oidfed-common.
View the commit online:
https://codeberg.org/Shibboleth/java-oidfed-common/commit/95b67ae872719845db0f896acf74ad9406036aa9
commit 95b67ae872719845db0f896acf74ad9406036aa9
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Fri Nov 13 14:49:05 2026 +0200
Improve flow tests especially for content fetching verifications
- Reset the mocked HTTP client before the tests
- Return the mocked content only once
- Verify that the content was called by the negative tests
- Reset metadata caches before any test
---
.../shibboleth/oidfed/flow/AbstractFederationFlowTest.java | 5 ++++-
.../oidfed/flow/TestTrustChainResolutionFlowTest.java | 6 ++++++
.../flow/cache/EntityConfigurationMetadataCacheTest.java | 11 ++++++++++-
.../oidfed/flow/cache/SignedKeysetMetadataCacheTest.java | 14 +++++++++++++-
.../flow/cache/SubordinateStatementMetadataCacheTest.java | 11 ++++++++++-
.../oidfed/flow/cache/TrustChainMetadataCacheTest.java | 8 ++++++++
6 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/AbstractFederationFlowTest.java b/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/AbstractFederationFlowTest.java
index 4e96698..c1e56c0 100644
--- a/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/AbstractFederationFlowTest.java
+++ b/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/AbstractFederationFlowTest.java
@@ -44,6 +44,7 @@ import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HttpEntity;
import org.mockito.ArgumentMatcher;
+import org.mockito.Mockito;
import org.opensaml.profile.context.ProfileRequestContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -170,6 +171,8 @@ public class AbstractFederationFlowTest extends AbstractFlowTest {
externalContext = new MockExternalContext();
externalContext.setNativeRequest(request);
externalContext.setNativeResponse(response);
+
+ Mockito.reset(federationHttpClient);
}
/**
@@ -275,7 +278,7 @@ public class AbstractFederationFlowTest extends AbstractFlowTest {
when(classicResponse.getCode()).thenReturn(code);
final HttpEntity responseEntity = mock(HttpEntity.class);
when(responseEntity.getContentType()).thenReturn(contentType);
- when(responseEntity.getContent()).thenReturn(new ByteArrayInputStream(contents.getBytes()));
+ when(responseEntity.getContent()).thenAnswer(invocation -> new ByteArrayInputStream(contents.getBytes()));
when(classicResponse.getEntity()).thenReturn(responseEntity);
return classicResponse;
}
diff --git a/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/TestTrustChainResolutionFlowTest.java b/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/TestTrustChainResolutionFlowTest.java
index 3aec485..682721d 100644
--- a/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/TestTrustChainResolutionFlowTest.java
+++ b/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/TestTrustChainResolutionFlowTest.java
@@ -31,6 +31,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.webflow.execution.FlowExecutionOutcome;
import org.springframework.webflow.executor.FlowExecutionResult;
import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -64,6 +65,11 @@ public class TestTrustChainResolutionFlowTest extends AbstractFederationFlowTest
super(FLOW_ID, "ResponseView");
}
+ @BeforeMethod
+ public void resetEntityConfigurationCache() {
+ entityConfigurationCache.clearAll();
+ }
+
/**
* Test the flow without any parameters.
*
diff --git a/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/cache/EntityConfigurationMetadataCacheTest.java b/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/cache/EntityConfigurationMetadataCacheTest.java
index f1dc35a..53f7112 100644
--- a/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/cache/EntityConfigurationMetadataCacheTest.java
+++ b/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/cache/EntityConfigurationMetadataCacheTest.java
@@ -16,6 +16,7 @@ package net.shibboleth.oidfed.flow.cache;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.IOException;
@@ -30,6 +31,7 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.nimbusds.jose.EncryptionMethod;
@@ -74,6 +76,11 @@ public class EntityConfigurationMetadataCacheTest extends AbstractFederationFlow
@Qualifier("shibboleth.oidfed.EntityConfigurationMetadataCache")
MetadataCache<EntityConfigurationContainer> entityConfigurationCache;
+ @BeforeMethod
+ public void resetEntityConfigurationCache() {
+ entityConfigurationCache.clearAll();
+ }
+
@Test
public void testValidEntityConfiguration()
throws MetadataCacheException, UnsupportedOperationException, IOException, URISyntaxException {
@@ -595,13 +602,15 @@ public class EntityConfigurationMetadataCacheTest extends AbstractFederationFlow
assertNoEntityConfiguration(entityId);
}
- protected void assertNoEntityConfiguration(final String entityId) {
+ protected void assertNoEntityConfiguration(final String entityId) throws IOException {
try {
final List<EntityConfigurationContainer> result =
entityConfigurationCache.get(new CriteriaSet(new SubjectEntityIDCriterion(entityId),
new ResponseContainerExpirationCriterion(Instant.now().plusSeconds(300))));
Assert.assertNotNull(result);
Assert.assertTrue(result.size() == 0 || result.get(0).getStatement() == null);
+ verify(federationHttpClient).executeOpen(any(),
+ argThat(new RequestUriMatcher(entityConfigurationUrl(entityId))), any());
} catch (MetadataCacheException e) {
Assert.fail("Could not resolve entity configuration", e);
}
diff --git a/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/cache/SignedKeysetMetadataCacheTest.java b/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/cache/SignedKeysetMetadataCacheTest.java
index d4248b7..123d86e 100644
--- a/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/cache/SignedKeysetMetadataCacheTest.java
+++ b/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/cache/SignedKeysetMetadataCacheTest.java
@@ -14,6 +14,10 @@
package net.shibboleth.oidfed.flow.cache;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.Mockito.verify;
+
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -25,6 +29,7 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -61,6 +66,11 @@ public class SignedKeysetMetadataCacheTest extends AbstractFederationFlowTest {
@Qualifier("shibboleth.oidfed.SignedKeysetMetadataCache")
MetadataCache<SignedKeysetContainer> signedKeysetCache;
+ @BeforeMethod
+ public void resetSignedKeysetCache() {
+ signedKeysetCache.clearAll();
+ }
+
@Test
public void testValidSignedKeyset()
throws MetadataCacheException, UnsupportedOperationException, IOException, URISyntaxException {
@@ -241,7 +251,8 @@ public class SignedKeysetMetadataCacheTest extends AbstractFederationFlowTest {
return null;
}
- protected void assertNoSignedKeyset(final String signedJwksUri, final EntityConfiguration entityConfiguration) {
+ protected void assertNoSignedKeyset(final String signedJwksUri, final EntityConfiguration entityConfiguration)
+ throws IOException {
try {
final List<SignedKeysetContainer> result =
signedKeysetCache.get(new CriteriaSet(
@@ -249,6 +260,7 @@ public class SignedKeysetMetadataCacheTest extends AbstractFederationFlowTest {
new SubjectEntityStatementCriterion(entityConfiguration)));
Assert.assertNotNull(result);
Assert.assertTrue(result.size() == 0 || result.get(0).getStatement() == null);
+ verify(federationHttpClient).executeOpen(any(), argThat(new RequestUriMatcher(signedJwksUri)), any());
} catch (MetadataCacheException e) {
Assert.fail("Could not resolve signed keyset", e);
}
diff --git a/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/cache/SubordinateStatementMetadataCacheTest.java b/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/cache/SubordinateStatementMetadataCacheTest.java
index 594603c..ddf8fb1 100644
--- a/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/cache/SubordinateStatementMetadataCacheTest.java
+++ b/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/cache/SubordinateStatementMetadataCacheTest.java
@@ -16,6 +16,7 @@ package net.shibboleth.oidfed.flow.cache;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.IOException;
@@ -30,6 +31,7 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.nimbusds.jose.EncryptionMethod;
@@ -74,6 +76,11 @@ public class SubordinateStatementMetadataCacheTest extends AbstractFederationFlo
@Qualifier("shibboleth.oidfed.SubordinateEntityStatementMetadataCache")
MetadataCache<SubordinateStatementContainer> subordinateStatementCache;
+ @BeforeMethod
+ public void resetSubordinateStatementCache() {
+ subordinateStatementCache.clearAll();
+ }
+
@Test
public void testValidSubordinateStatement()
throws MetadataCacheException, UnsupportedOperationException, IOException, URISyntaxException {
@@ -676,7 +683,7 @@ public class SubordinateStatementMetadataCacheTest extends AbstractFederationFlo
assertNoSubordinateStatement(entityId);
}
- protected void assertNoSubordinateStatement(final String entityId) {
+ protected void assertNoSubordinateStatement(final String entityId) throws IOException {
try {
final List<SubordinateStatementContainer> result =
subordinateStatementCache.get(new CriteriaSet(new SubjectEntityIDCriterion(entityId),
@@ -684,6 +691,8 @@ public class SubordinateStatementMetadataCacheTest extends AbstractFederationFlo
new IssuerEntityIDCriterion(anchorId)));
Assert.assertNotNull(result);
Assert.assertTrue(result.size() == 0 || result.get(0).getStatement() == null);
+ verify(federationHttpClient).executeOpen(any(),
+ argThat(new RequestUriMatcher(subordinateStatementUrl(anchorFetchEndpoint, entityId))), any());
} catch (MetadataCacheException e) {
Assert.fail("Could not resolve entity configuration", e);
}
diff --git a/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/cache/TrustChainMetadataCacheTest.java b/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/cache/TrustChainMetadataCacheTest.java
index 379b7c2..f30c754 100644
--- a/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/cache/TrustChainMetadataCacheTest.java
+++ b/oidfed-common-conf-impl/src/test/java/net/shibboleth/oidfed/flow/cache/TrustChainMetadataCacheTest.java
@@ -25,6 +25,7 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.nimbusds.jose.JWSAlgorithm;
@@ -66,6 +67,13 @@ public class TrustChainMetadataCacheTest extends AbstractFederationFlowTest {
@Qualifier("shibboleth.oidfed.SubordinateEntityStatementMetadataCache")
MetadataCache<SubordinateStatementContainer> subordinateStatementCache;
+ @BeforeMethod
+ public void resetAllCaches() {
+ trustChainCache.clearAll();
+ entityConfigurationCache.clearAll();
+ subordinateStatementCache.clearAll();
+ }
+
@Test
public void testValidTrustChainResolved()
throws MetadataCacheException, UnsupportedOperationException, IOException, URISyntaxException {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list