[java-plugin-shibd] branch main updated: Flesh out test a bit more.

Scott Cantor cantor.2 at osu.edu
Tue Jul 30 17:29:19 UTC 2024


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

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

View the commit online:
http://git.shibboleth.net/view/?p=java-plugin-shibd.git;a=commit;h=bf052306b84f9876f2ce29ebcbacad696137893c

The following commit(s) were added to refs/heads/main by this push:
     new bf05230  Flesh out test a bit more.
bf05230 is described below

commit bf052306b84f9876f2ce29ebcbacad696137893c
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Jul 30 13:29:17 2024 -0400

    Flesh out test a bit more.
---
 .../shibboleth/sp/flows/AbstractSPFlowTest.java    | 22 ++++++++++-
 .../flows/saml2/SAML2SessionInitiatorFlowTest.java | 46 ++++++++++++++++------
 2 files changed, 54 insertions(+), 14 deletions(-)

diff --git a/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/AbstractSPFlowTest.java b/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/AbstractSPFlowTest.java
index dd0e00a..12f4492 100644
--- a/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/AbstractSPFlowTest.java
+++ b/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/AbstractSPFlowTest.java
@@ -209,7 +209,7 @@ public abstract class AbstractSPFlowTest extends AbstractFlowTest {
     }
     
     /**
-     * Decodes the SAML message encoded via HTTP-Redirect binding.
+     * Decodes a SAML message encoded via HTTP-Redirect binding.
      * 
      * @param url the encoded redirect
      * 
@@ -217,7 +217,7 @@ public abstract class AbstractSPFlowTest extends AbstractFlowTest {
      * @throws MessageDecodingException 
      */
     @Nonnull protected SAMLObject decodeRedirect(@Nullable final String url) throws MessageDecodingException {
-        final MockHttpServletRequest mock = new MockHttpServletRequest("GET", "url");
+        final MockHttpServletRequest mock = new MockHttpServletRequest("GET", url);
         final int index = url != null ? url.indexOf('?') : -1;
         if (url == null || index < 0) {
             throw new MessageDecodingException("No query string");
@@ -251,4 +251,22 @@ public abstract class AbstractSPFlowTest extends AbstractFlowTest {
         throw new MessageDecodingException("No message, or incorrect type.");
     }
 
+    /**
+     * Test whether a flag is non-null and true.
+     * 
+     * @param flag input flag
+     */
+    protected void assertTrue(@Nullable final Boolean flag) {
+        Assert.assertTrue(flag != null && flag);
+    }
+    
+    /**
+     * Test whether a flag is null or false.
+     * 
+     * @param flag input flag
+     */
+    protected void assertFalse(@Nullable final Boolean flag) {
+        Assert.assertTrue(flag == null || !flag);
+    }
+
 }
\ No newline at end of file
diff --git a/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/saml2/SAML2SessionInitiatorFlowTest.java b/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/saml2/SAML2SessionInitiatorFlowTest.java
index 465fff0..fc56c29 100644
--- a/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/saml2/SAML2SessionInitiatorFlowTest.java
+++ b/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/saml2/SAML2SessionInitiatorFlowTest.java
@@ -15,23 +15,23 @@
 package net.shibboleth.sp.flows.saml2;
 
 import java.io.IOException;
-import java.nio.charset.Charset;
 import java.time.Instant;
 
 import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
 
 import org.opensaml.messaging.decoder.MessageDecodingException;
+import org.opensaml.profile.context.ProfileRequestContext;
 import org.opensaml.saml.common.SAMLObject;
 import org.opensaml.saml.saml2.core.AuthnRequest;
+import org.opensaml.saml.saml2.core.NameIDPolicy;
 import org.springframework.webflow.executor.FlowExecutionResult;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
 import net.shibboleth.idp.authn.AuthnEventIds;
+import net.shibboleth.sp.context.AgentRequestContext;
 import net.shibboleth.sp.ddf.DDF;
 import net.shibboleth.sp.flows.AbstractSPFlowTest;
-import net.shibboleth.sp.messaging.RemotedHttpServletResponse;
 
 /**
  * Unit test for the SP session-initiator flow.
@@ -94,13 +94,13 @@ public class SAML2SessionInitiatorFlowTest extends AbstractSPFlowTest {
     }
 
     /**
-     * Test basic use of flow.
+     * Test simple success case.
      * 
      * @throws IOException 
      * @throws MessageDecodingException 
      */
     @Test
-    public void testRedirect() throws IOException, MessageDecodingException {
+    public void testSimple() throws IOException, MessageDecodingException {
         setDefaultAuth();
         setApplicationRequest(APPLICATION_ID);
 
@@ -108,18 +108,29 @@ public class SAML2SessionInitiatorFlowTest extends AbstractSPFlowTest {
         assertFlowExecutionResult(result, FLOW_ID);
         assertFlowExecutionOutcome(result.getOutcome());
         
-        final DDF output = assertOutputMessageEvent(result, null);
-        assertOutputMessage(output);
+        assertOutputMessageEvent(result, null);
+        final AuthnRequest req = validateOutputMessage(result);
+        Assert.assertNull(req.getSubject());
+        Assert.assertNull(req.getRequestedAuthnContext());
+        Assert.assertNull(req.getScoping());
+        assertFalse(req.isForceAuthn());
+        assertFalse(req.isPassive());
     }
-
+    
     /**
      * Decode an encoded response and run sanity checks against it.
      * 
-     * @param output the wrapped output message from the flow
+     * @param result flow execution result
+     * @return the request object
      * 
      * @throws MessageDecodingException
      */
-    private void assertOutputMessage(@Nullable final DDF output) throws MessageDecodingException {
+    @Nonnull private AuthnRequest validateOutputMessage(@Nonnull final FlowExecutionResult result) throws MessageDecodingException {
+        final ProfileRequestContext prc = retrieveProfileRequestContext(result);
+        assert prc != null;
+        final AgentRequestContext arc = prc.ensureSubcontext(AgentRequestContext.class);
+        final DDF output = arc.getOutput();
+
         assert output != null;
         Assert.assertTrue(output.isstruct());
         final DDF http = output.getmember("http");
@@ -133,13 +144,24 @@ public class SAML2SessionInitiatorFlowTest extends AbstractSPFlowTest {
             authnRequest = (AuthnRequest) saml;
             Assert.assertTrue(redirect.startsWith(authnRequest.getDestination()));
         } else {
-            // TODO POST
-            authnRequest = null;
+            final byte[] body = http.getmember("response.data").unsafe_string();
+            Assert.assertNotNull(body);
+            // Not trivial to consider parsing the form, so just bypass that step.
+            final Object saml = prc.ensureOutboundMessageContext().ensureMessage();
+            assert saml instanceof AuthnRequest;
+            authnRequest = (AuthnRequest) saml;
         }
         
         assert authnRequest != null;
         Assert.assertNotNull(authnRequest.getID());
         Assert.assertTrue(Instant.now().isAfter(authnRequest.getIssueInstant()));
+        Assert.assertFalse(authnRequest.isSigned());
+        
+        final NameIDPolicy pol = authnRequest.getNameIDPolicy();
+        assert pol != null;
+        assertTrue(pol.getAllowCreate());
+        
+        return authnRequest;
     }
     
 }
\ No newline at end of file

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


More information about the commits mailing list