[java-idp-plugin-oidc-op-oidfed] 02/03: Initialize keys statically in the abstract flow test class

Codeberg noreply at shibboleth.net
Wed May 6 12:57:05 UTC 2026


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

codeberg pushed a commit to branch dev/CACHE-REFACTOR
in repository java-idp-plugin-oidc-op-oidfed.

View the commit online:
https://codeberg.org/Shibboleth/java-idp-plugin-oidc-op-oidfed/commit/f3bda34ffc6536037b7680cad4eb8e09581b6b04

commit f3bda34ffc6536037b7680cad4eb8e09581b6b04
Author: Henri Mikkonen <henri.mikkonen at iki.fi>
AuthorDate: Wed May 6 15:49:09 2026 +0300

    Initialize keys statically in the abstract flow test class
    
    - Otherwise they get re-initialized for each extending flow test class
---
 .../flow/oidfed/AbstractFederationFlowTest.java    | 63 ++++++++++++----------
 1 file changed, 34 insertions(+), 29 deletions(-)

diff --git a/idp-oidfed-op-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/oidfed/AbstractFederationFlowTest.java b/idp-oidfed-op-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/oidfed/AbstractFederationFlowTest.java
index 47432de..c002e5f 100644
--- a/idp-oidfed-op-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/oidfed/AbstractFederationFlowTest.java
+++ b/idp-oidfed-op-impl/src/test/java/net/shibboleth/idp/plugin/oidc/op/profile/flow/oidfed/AbstractFederationFlowTest.java
@@ -26,6 +26,7 @@ import java.net.URISyntaxException;
 import java.net.URLEncoder;
 import java.nio.charset.Charset;
 import java.security.KeyPair;
+import java.security.KeyPairGenerator;
 import java.security.NoSuchAlgorithmException;
 import java.security.interfaces.RSAPublicKey;
 import java.time.Instant;
@@ -49,7 +50,6 @@ import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.Resource;
 import org.springframework.webflow.executor.FlowExecutionResult;
 import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
 import org.testng.annotations.BeforeMethod;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -104,13 +104,13 @@ public class AbstractFederationFlowTest extends AbstractOidcFlowTest {
     protected final String trustMarkStatusEndpoint = "https://trust-mark-issuer.federation.local/status";
     protected final String issuer = "https://op.example.org";
 
-    protected JWK rpKey;
-    protected JWK leafKey;
-    protected JWK anchorKey;
-    protected JWK trustedAnchorKey;
-    protected JWK intermediateKey;
-    protected JWK trustedIntermediateKey;
-    protected JWK trustMarkIssuerKey;
+    protected static JWK rpKey;
+    protected static JWK leafKey;
+    protected static JWK anchorKey;
+    protected static JWK trustedAnchorKey;
+    protected static JWK intermediateKey;
+    protected static JWK trustedIntermediateKey;
+    protected static JWK trustMarkIssuerKey;
 
     protected String subject = "jdoe";
 
@@ -122,27 +122,30 @@ public class AbstractFederationFlowTest extends AbstractOidcFlowTest {
     @Qualifier("shibboleth.oidc.NonBrowser.HttpClient")
     protected HttpClient vanillaOidcHttpClient;
 
-    protected AbstractFederationFlowTest(final String flowId) {
-        super(flowId);
+    static {
+        try {
+            rpKey = initializeNewJwk("RSA", 2048, "mockRpKey");
+            leafKey = initializeNewJwk("RSA", 2048, "mockLeafKey");
+            anchorKey = initializeNewJwk("RSA", 2048, "mockAnchorKey");
+            final BasicJWKCredential localAnchor = loadCredential("/credentials/fed-local-anchor.jwk");
+            trustedAnchorKey = new RSAKey.Builder((RSAPublicKey) localAnchor.getPublicKey())
+                    .privateKey(localAnchor.getPrivateKey())
+                    .keyID("locallyTrustedAnchorKey")
+                    .build();
+            final BasicJWKCredential localIntermediate = loadCredential("/credentials/fed-local-intermediate.jwk");
+            trustedIntermediateKey = new RSAKey.Builder((RSAPublicKey) localIntermediate.getPublicKey())
+                    .privateKey(localIntermediate.getPrivateKey())
+                    .keyID("locallyTrustedIntermediateKey")
+                    .build();
+            intermediateKey = initializeNewJwk("RSA", 2048, "mockIntermediateKey");
+            trustMarkIssuerKey = initializeNewJwk("RSA", 2048, "mockTrustMarkIssuerKey");
+        } catch (final NoSuchAlgorithmException e) {
+            Assert.fail("Could not initialize keys for the tests", e);
+        }
     }
 
-    @BeforeClass
-    public void initKeys() throws NoSuchAlgorithmException {
-        rpKey = initializeNewJwk("RSA", 2048, "mockRpKey");
-        leafKey = initializeNewJwk("RSA", 2048, "mockLeafKey");
-        anchorKey = initializeNewJwk("RSA", 2048, "mockAnchorKey");
-        final BasicJWKCredential localAnchor = loadCredential("/credentials/fed-local-anchor.jwk");
-        trustedAnchorKey = new RSAKey.Builder((RSAPublicKey) localAnchor.getPublicKey())
-                .privateKey(localAnchor.getPrivateKey())
-                .keyID("locallyTrustedAnchorKey")
-                .build();
-        final BasicJWKCredential localIntermediate = loadCredential("/credentials/fed-local-intermediate.jwk");
-        trustedIntermediateKey = new RSAKey.Builder((RSAPublicKey) localIntermediate.getPublicKey())
-                .privateKey(localIntermediate.getPrivateKey())
-                .keyID("locallyTrustedIntermediateKey")
-                .build();
-        intermediateKey = initializeNewJwk("RSA", 2048, "mockIntermediateKey");
-        trustMarkIssuerKey = initializeNewJwk("RSA", 2048, "mockTrustMarkIssuerKey");
+    protected AbstractFederationFlowTest(final String flowId) {
+        super(flowId);
     }
 
     @BeforeMethod
@@ -151,10 +154,12 @@ public class AbstractFederationFlowTest extends AbstractOidcFlowTest {
         request.removeHeader(USE_CUSTOM_FAILBACK_TO_LOCAL_CONDITION);
     }
 
-    protected JWK initializeNewJwk(final String algorithm, final int size, final String kid)
+    protected static JWK initializeNewJwk(final String algorithm, final int size, final String kid)
             throws NoSuchAlgorithmException {
         if ("RSA".equals(algorithm)) {
-            final KeyPair keyPair = generateNewKeyPair(algorithm, size);
+            final KeyPairGenerator keyGen = KeyPairGenerator.getInstance(algorithm);
+            keyGen.initialize(size);
+            final KeyPair keyPair = keyGen.generateKeyPair();
             return new RSAKey.Builder((RSAPublicKey) keyPair.getPublic())
                     .privateKey(keyPair.getPrivate())
                     .keyID(kid)

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


More information about the commits mailing list