[java-plugin-shibd-oidc] branch main updated: Improve tests inline with the new SP base class for tests

Codeberg noreply at shibboleth.net
Fri Nov 28 10:56:45 UTC 2025


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

codeberg pushed a commit to branch main
in repository java-plugin-shibd-oidc.

View the commit online:
https://codeberg.org/Shibboleth/java-plugin-shibd-oidc/commit/b7feb9fbdc77f3ea8f9bca79ed375a96d3d38e43

The following commit(s) were added to refs/heads/main by this push:
     new b7feb9f  Improve tests inline with the new SP base class for tests
b7feb9f is described below

commit b7feb9fbdc77f3ea8f9bca79ed375a96d3d38e43
Author: Phil Smart <philip.smart at jisc.ac.uk>
AuthorDate: Fri Nov 28 10:56:36 2025 +0000

    Improve tests inline with the new SP base class for tests
---
 .../sp/oidc/flows/OIDCTokenConsumerFlowTest.java   | 43 +++++++++++++++++-----
 ...DCEnvironmentApplicationContextInitializer.java | 20 +++++-----
 2 files changed, 42 insertions(+), 21 deletions(-)

diff --git a/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/OIDCTokenConsumerFlowTest.java b/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/OIDCTokenConsumerFlowTest.java
index 7b46b36..6821e33 100644
--- a/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/OIDCTokenConsumerFlowTest.java
+++ b/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/OIDCTokenConsumerFlowTest.java
@@ -75,6 +75,8 @@ import com.nimbusds.openid.connect.sdk.token.OIDCTokens;
 
 import net.minidev.json.JSONObject;
 import net.shibboleth.idp.authn.AuthnEventIds;
+import net.shibboleth.idp.spring.IdPPropertiesApplicationContextInitializer;
+import net.shibboleth.idp.test.PreferFileSystemApplicationContextInitializer;
 import net.shibboleth.oidc.security.credential.JWKCredential;
 import net.shibboleth.shared.codec.Base64Support;
 import net.shibboleth.shared.codec.DecodingException;
@@ -97,7 +99,10 @@ import net.shibboleth.sp.profile.ConsumerConstants;
                 "classpath:/net/shibboleth/sp/oidc-test-beans.xml", },
         initializers = {
                 TestSPOIDCEnvironmentApplicationContextInitializer.class,
-                }
+                PreferFileSystemApplicationContextInitializer.class,
+                IdPPropertiesApplicationContextInitializer.class
+                },
+        inheritInitializers = false
         )
 @WebAppConfiguration
 @SuppressWarnings({ "unchecked", "rawtypes", "null" })
@@ -196,7 +201,7 @@ public class OIDCTokenConsumerFlowTest extends AbstractSPFlowTest {
         final DDF output = assertOutputMessageSuccess(result);
         assert output != null;
         System.out.println("testSuccess output: " + output.toString());
-        validateOutputMessage(result, CollectionSupport.singleton("mail"), TestConstants.RESOURCE_URL);
+        validateOutputMessage(result, CollectionSupport.setOf("mail","displayName","eduPersonScopedAffiliation"), TestConstants.RESOURCE_URL);
     }
     
     /**
@@ -313,8 +318,8 @@ public class OIDCTokenConsumerFlowTest extends AbstractSPFlowTest {
      */
     private UserInfoSuccessResponse constructJSONUserInfoResponse() {
         final JSONObject json = new JSONObject();
-        json.appendField("sub", "fake-user");
-        json.appendField("name", "Fake User");
+        json.appendField("sub", "jdoe");
+        json.appendField("name", "John Doe");
         return  new UserInfoSuccessResponse(new UserInfo(json));
     }
     
@@ -327,10 +332,10 @@ public class OIDCTokenConsumerFlowTest extends AbstractSPFlowTest {
      */
     private UserInfoSuccessResponse constructJWTUserInfoResponseSigned() throws JOSEException, ParseException {
         final JWTClaimsSet claimsSet = new JWTClaimsSet.Builder()
-                .subject("fake-user")
+                .subject("jdoe")
                 .issuer("https://op.example.org")
                 .audience("mock-client-id")
-                .claim("name", "Fake User").build();
+                .claim("name", "John Doe").build();
        
         final JWT signedUserInfoToken = 
                 TestTokenHelper.createJWT(claimsSet, JWSAlgorithm.RS256, null, null, opSigningCredential, null);
@@ -383,7 +388,7 @@ public class OIDCTokenConsumerFlowTest extends AbstractSPFlowTest {
      * 
      * @param result
      *            flow execution result
-     * @param claims
+     * @param claimNames
      *            set of claims to check for
      * @param resource
      *            resource URL used in final redirect
@@ -391,7 +396,7 @@ public class OIDCTokenConsumerFlowTest extends AbstractSPFlowTest {
      * @return the output object
      */
     @Nonnull private DDF validateOutputMessage(@Nonnull final FlowExecutionResult result,
-            @Nullable final Set<String> claims, @Nullable final String resource) {
+            @Nullable final Set<String> claimNames, @Nullable final String resource) {
         
         final ProfileRequestContext prc = retrieveProfileRequestContext(result);
         assert prc != null;
@@ -406,6 +411,24 @@ public class OIDCTokenConsumerFlowTest extends AbstractSPFlowTest {
         final byte[] redirect = http.getmember(RemotedHttpServletResponse.REDIRECT).unsafe_string();
         Assert.assertEquals(resource != null ? resource.getBytes(StandardCharsets.UTF_8) : null,  redirect);
         
+        final Set<String> mutableIds = new HashSet<>(claimNames);
+        for (final DDF attr : output.getmember(ConsumerConstants.SESSION_ATTRIBUTES).asList()) {
+            Assert.assertTrue(mutableIds.contains(attr.name()));
+            mutableIds.remove(attr.name());
+            if ("mail".equals(attr.name())) {
+                Assert.assertEquals(attr.asList().stream().map(DDF::string).toList(),
+                        CollectionSupport.singletonList("jdoe at example.org"));
+            } else if ("displayName".equals(attr.name())) {
+                Assert.assertEquals(attr.asList().stream().map(DDF::string).toList(),
+                        CollectionSupport.singletonList("John Doe"));
+            } else if ("eduPersonScopedAffiliation".equals(attr.name())) {
+                Assert.assertEquals(attr.asList().stream().map(ddf -> {return ddf.getmember("value").string();}).toList(),
+                        CollectionSupport.listOf("member"));
+                Assert.assertEquals(attr.asList().stream().map(ddf -> {return ddf.getmember("scope").string();}).toList(),
+                        CollectionSupport.listOf("example.org"));
+            }
+        }
+        
         return output;
         
     }
@@ -451,9 +474,9 @@ public class OIDCTokenConsumerFlowTest extends AbstractSPFlowTest {
                         CollectionSupport.singletonList("John Doe"));
             } else if ("eduPersonScopedAffiliation".equals(attr.name())) {
                 Assert.assertEquals(attr.asList().stream().map(ddf -> {return ddf.getmember("value").string();}).toList(),
-                        CollectionSupport.listOf("staff", "employee"));
+                        CollectionSupport.listOf("member"));
                 Assert.assertEquals(attr.asList().stream().map(ddf -> {return ddf.getmember("scope").string();}).toList(),
-                        CollectionSupport.listOf("example.org", "example.org"));
+                        CollectionSupport.listOf("example.org"));
             }
         }
         Assert.assertTrue(mutableIds.isEmpty());
diff --git a/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/TestSPOIDCEnvironmentApplicationContextInitializer.java b/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/TestSPOIDCEnvironmentApplicationContextInitializer.java
index 652b34f..b595e57 100644
--- a/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/TestSPOIDCEnvironmentApplicationContextInitializer.java
+++ b/sp-oidc-conf-impl/src/test/java/net/shibboleth/sp/oidc/flows/TestSPOIDCEnvironmentApplicationContextInitializer.java
@@ -19,21 +19,16 @@ import javax.annotation.Nonnull;
 import org.slf4j.Logger;
 import org.springframework.context.ApplicationContextInitializer;
 import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.core.Ordered;
-import org.springframework.core.annotation.Order;
 import org.springframework.mock.env.MockPropertySource;
 
 import net.shibboleth.shared.primitive.LoggerFactory;
+import net.shibboleth.sp.flows.TestSPEnvironmentApplicationContextInitializer;
 
 /**
- * An {@link ApplicationContextInitializer} which prepends properties.
- *
- * <p>This needs to include the original IdP-test-layer properties and has to be
- * set to {@link Ordered#LOWEST_PRECEDENCE} or things blow up.</p>
+/**
+ * An {@link ApplicationContextInitializer} which extends the parent plugin's test initializer.
  */
- at Order(Ordered.LOWEST_PRECEDENCE)
-public class TestSPOIDCEnvironmentApplicationContextInitializer
-        implements ApplicationContextInitializer<ConfigurableApplicationContext> {
+public class TestSPOIDCEnvironmentApplicationContextInitializer extends TestSPEnvironmentApplicationContextInitializer {
 
     /** Class logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(TestSPOIDCEnvironmentApplicationContextInitializer.class);
@@ -44,11 +39,14 @@ public class TestSPOIDCEnvironmentApplicationContextInitializer
         mock.setProperty("idp.home", "classpath:/net/shibboleth/idp/module");
         mock.setProperty("idp.webflows", "classpath*:/flows");
         mock.setProperty("sp.service.agents.resources", "test.sp.oidc.AgentResolverResources");
+        // Use cookie based state managment
         mock.setProperty("sp.stateToken.Manager","shibboleth.sp.CookieStateTokenManager");
-        // Use the mocked HTTP client
+        // Use a mocked HTTP client
         mock.setProperty("sp.oidc.HttpClient","Mock.HttpClient");
+        // Set agent auth to basic
         mock.setProperty("sp.agent.authn.method", "basic");
-        //mock.setProperty("idp.service.logging.resource", "/logback-webauthn-flow-test.xml");
+        // Resolve attributes, to test attribute resolution
+        mock.setProperty("sp.oidc.resolveAttributes", "true");
         mock.setProperty("idp.additionalProperties",
                 "/conf/ldap.properties, /conf/saml-nameid.properties, /conf/services.properties, /conf/admin/admin.properties, /conf/authn/authn.properties, /conf/c14n/subject-c14n.properties, /credentials/secrets.properties, /conf/sp/sp.properties, /conf/sp/oidc.properties,  /conf/sp/oidc-test.properties");
         applicationContext.getEnvironment().getPropertySources().addFirst(mock);

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


More information about the commits mailing list