[java-plugin-shibd] branch main updated: Fix some tests, prevent overwrite of output on errors.

Scott Cantor cantor.2 at osu.edu
Fri Oct 4 19:44:01 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=8a10ddbc669b3efac0545df52cb01f78b4f2b605

The following commit(s) were added to refs/heads/main by this push:
     new 8a10ddb  Fix some tests, prevent overwrite of output on errors.
8a10ddb is described below

commit 8a10ddbc669b3efac0545df52cb01f78b4f2b605
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Fri Oct 4 15:43:58 2024 -0400

    Fix some tests, prevent overwrite of output on errors.
---
 .../shibboleth/idp/flows/sp/consumer/consumer-flow.xml    |  2 ++
 .../sp/messaging/RemotedHttpServletRequest.java           |  7 +++++--
 .../java/net/shibboleth/sp/profile/ConsumerConstants.java |  3 +++
 .../sp/profile/impl/PrepareAgentErrorResponse.java        | 15 +++++++--------
 .../sp/messaging/impl/RemotedHttpServletRequestTest.java  |  2 +-
 .../sp/messaging/impl/RemotedHttpServletResponseTest.java | 12 +++++++-----
 6 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/sp-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/consumer/consumer-flow.xml b/sp-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/consumer/consumer-flow.xml
index 0dd581b..46f34cb 100644
--- a/sp-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/consumer/consumer-flow.xml
+++ b/sp-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/consumer/consumer-flow.xml
@@ -19,6 +19,7 @@
     <end-state id="InvalidRelyingPartyContext" />
     <end-state id="InvalidRelyingPartyConfiguration" />
     <end-state id="InvalidSecurityConfiguration" />
+    <end-state id="MessageProcessingError" />
     <end-state id="ReselectFlow" />
     <end-state id="RuntimeException" />
 
@@ -40,6 +41,7 @@
         <transition on="InvalidRelyingPartyConfiguration" to="InvalidRelyingPartyConfiguration" />
         <transition on="InvalidSecurityConfiguration" to="InvalidSecurityConfiguration" />
         <transition on="ReselectFlow" to="ReselectFlow" />
+        <transition on="MessageProcessingError" to="MessageProcessingError" />
         <transition on="RuntimeException" to="RuntimeException" />
     </global-transitions>
 
diff --git a/sp-server-api/src/main/java/net/shibboleth/sp/messaging/RemotedHttpServletRequest.java b/sp-server-api/src/main/java/net/shibboleth/sp/messaging/RemotedHttpServletRequest.java
index d3e8a44..f58e3ab 100644
--- a/sp-server-api/src/main/java/net/shibboleth/sp/messaging/RemotedHttpServletRequest.java
+++ b/sp-server-api/src/main/java/net/shibboleth/sp/messaging/RemotedHttpServletRequest.java
@@ -92,6 +92,9 @@ public class RemotedHttpServletRequest implements HttpServletRequest {
     /** Field holding method. */
     @Nonnull @NotEmpty public static final String METHOD = "method";
 
+    /** Field holding client address. */
+    @Nonnull @NotEmpty public static final String REMOTE_ADDR = "remote_addr";
+
     /** Field holding query string. */
     @Nonnull @NotEmpty public static final String QUERY_STRING = "query";
 
@@ -291,12 +294,12 @@ public class RemotedHttpServletRequest implements HttpServletRequest {
 
     /** {@inheritDoc} */
     public String getRemoteAddr() {
-        return obj.getmember("client_addr").string();
+        return obj.getmember(REMOTE_ADDR).string();
     }
 
     /** {@inheritDoc} */
     public String getRemoteHost() {
-        return obj.getmember("client_addr").string();
+        return obj.getmember(REMOTE_ADDR).string();
     }
 
     /** {@inheritDoc} */
diff --git a/sp-server-api/src/main/java/net/shibboleth/sp/profile/ConsumerConstants.java b/sp-server-api/src/main/java/net/shibboleth/sp/profile/ConsumerConstants.java
index aecc24f..d6fd70a 100644
--- a/sp-server-api/src/main/java/net/shibboleth/sp/profile/ConsumerConstants.java
+++ b/sp-server-api/src/main/java/net/shibboleth/sp/profile/ConsumerConstants.java
@@ -26,6 +26,9 @@ public final class ConsumerConstants {
     /** Base URL input parameter name. */
     @Nonnull @NotEmpty public static final String BASE_URL = "base_url";
 
+    /** Token validation errors data member. */
+    @Nonnull @NotEmpty public static final String VALIDATION_ERRORS = "validation_errors";
+    
     /** Opaque session data member. */
     @Nonnull @NotEmpty public static final String SESSION_OPAQUE = "session.opaque";
 
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/PrepareAgentErrorResponse.java b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/PrepareAgentErrorResponse.java
index c27cbdb..726674b 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/PrepareAgentErrorResponse.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/PrepareAgentErrorResponse.java
@@ -24,7 +24,6 @@ import org.opensaml.profile.context.EventContext;
 import org.opensaml.profile.context.ProfileRequestContext;
 import org.opensaml.profile.context.navigate.CurrentOrPreviousEventLookup;
 
-import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
 import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.sp.context.AgentRequestContext;
 import net.shibboleth.sp.ddf.DDF;
@@ -45,9 +44,6 @@ public class PrepareAgentErrorResponse extends AbstractAgentRequestAction {
     /** Strategy function for access to {@link EventContext} to check. */
     @Nonnull private Function<ProfileRequestContext,EventContext> eventContextLookupStrategy;
     
-    /** Cached context containing the output message. */
-    @NonnullBeforeExec private DDF outputMessage;
-    
     /** Constructor. */
     public PrepareAgentErrorResponse() {
         setAgentRequestContextLookupStrategy(new ChildContextLookup<>(AgentRequestContext.class, true));
@@ -68,17 +64,20 @@ public class PrepareAgentErrorResponse extends AbstractAgentRequestAction {
     /** {@inheritDoc} */
     @Override
     protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
-        outputMessage = new DDF().structure();
-        ensureAgentRequestContext().setOutput(outputMessage);
         
+        DDF output = ensureAgentRequestContext().getOutput();
+        if (output == null) {
+            output = new DDF().structure();
+            ensureAgentRequestContext().setOutput(output);
+        }
 
         final EventContext eventCtx = eventContextLookupStrategy.apply(profileRequestContext);
         final Object event = eventCtx != null ? eventCtx.getEvent() : null;
         if (event != null) {
             final String eventString = event.toString();
-            outputMessage.addmember("event").string(eventString);
+            output.addmember("event").string(eventString);
         } else {
-            outputMessage.addmember("event").string(EventIds.MESSAGE_PROC_ERROR);
+            output.addmember("event").string(EventIds.MESSAGE_PROC_ERROR);
         }
     }
 
diff --git a/sp-server-impl/src/test/java/net/shibboleth/sp/messaging/impl/RemotedHttpServletRequestTest.java b/sp-server-impl/src/test/java/net/shibboleth/sp/messaging/impl/RemotedHttpServletRequestTest.java
index c2d50ac..0e2436a 100644
--- a/sp-server-impl/src/test/java/net/shibboleth/sp/messaging/impl/RemotedHttpServletRequestTest.java
+++ b/sp-server-impl/src/test/java/net/shibboleth/sp/messaging/impl/RemotedHttpServletRequestTest.java
@@ -69,7 +69,7 @@ public class RemotedHttpServletRequestTest {
         obj.addmember("method").string("POST");
         obj.addmember("body").string("<foo/>");
         obj.addmember("port").integer(80);
-        obj.addmember("client_addr").string("127.0.0.1");
+        obj.addmember("remote_addr").string("127.0.0.1");
         obj.addmember("remote_user").string("jdoe");
         obj.addmember("hostname").unsafe_string("localhost".getBytes("UTF-8"));
         obj.addmember("uri").unsafe_string("/endpoint".getBytes("UTF-8"));
diff --git a/sp-server-impl/src/test/java/net/shibboleth/sp/messaging/impl/RemotedHttpServletResponseTest.java b/sp-server-impl/src/test/java/net/shibboleth/sp/messaging/impl/RemotedHttpServletResponseTest.java
index ef7884f..b7c93f0 100644
--- a/sp-server-impl/src/test/java/net/shibboleth/sp/messaging/impl/RemotedHttpServletResponseTest.java
+++ b/sp-server-impl/src/test/java/net/shibboleth/sp/messaging/impl/RemotedHttpServletResponseTest.java
@@ -19,6 +19,7 @@ import static org.testng.Assert.*;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
 import java.time.Instant;
 import java.util.Set;
 
@@ -77,7 +78,8 @@ public class RemotedHttpServletResponseTest {
         resp.sendRedirect("http://localhost");
 
         assertTrue(resp.isCommitted());
-        assertEquals(obj.getmember("redirect").string(), "http://localhost");
+        assertEquals(obj.getmember(RemotedHttpServletResponse.REDIRECT).unsafe_string(),
+                "http://localhost".getBytes(StandardCharsets.UTF_8));
         
         try {
             resp.getOutputStream();
@@ -97,7 +99,7 @@ public class RemotedHttpServletResponseTest {
         
         assertTrue(resp.isCommitted());
         assertEquals(obj.getmember("response.status").integer(), Integer.valueOf(200));
-        assertEquals(obj.getmember("response.data").unsafe_string(), "zorkmid".getBytes("UTF-8"));
+        assertEquals(obj.getmember("response.data").unsafe_string(), "zorkmid".getBytes(StandardCharsets.UTF_8));
     }
     
     @Test
@@ -110,7 +112,7 @@ public class RemotedHttpServletResponseTest {
         
         assertTrue(resp.isCommitted());
         assertEquals(obj.getmember("response.status").integer(), Integer.valueOf(200));
-        assertEquals(obj.getmember("response.data").unsafe_string(), "zorkmid☯️".getBytes("ISO-8859-1"));
+        assertEquals(obj.getmember("response.data").unsafe_string(), "zorkmid☯️".getBytes(StandardCharsets.ISO_8859_1));
     }
     
     @Test
@@ -123,7 +125,7 @@ public class RemotedHttpServletResponseTest {
         
         assertTrue(resp.isCommitted());
         assertEquals(obj.getmember("response.status").integer(), Integer.valueOf(200));
-        assertEquals(obj.getmember("response.data").unsafe_string(), "zorkmid".getBytes("UTF-8"));
+        assertEquals(obj.getmember("response.data").unsafe_string(), "zorkmid".getBytes(StandardCharsets.UTF_8));
     }
 
     @Test
@@ -136,6 +138,6 @@ public class RemotedHttpServletResponseTest {
         
         assertTrue(resp.isCommitted());
         assertEquals(obj.getmember("response.status").integer(), Integer.valueOf(200));
-        assertEquals(obj.getmember("response.data").unsafe_string(), "zorkmid☯️".getBytes("UTF-8"));
+        assertEquals(obj.getmember("response.data").unsafe_string(), "zorkmid☯️".getBytes(StandardCharsets.UTF_8));
     }
 }
\ 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