[java-plugin-shibd] branch main updated: Adjust message decoding again to account for servlet API foibles.
Scott Cantor
cantor.2 at osu.edu
Wed Jul 3 19:16:35 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=34950e0b8f75f86260ce48da8a54358bca096f20
The following commit(s) were added to refs/heads/main by this push:
new 34950e0 Adjust message decoding again to account for servlet API foibles.
34950e0 is described below
commit 34950e0b8f75f86260ce48da8a54358bca096f20
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Jul 3 15:16:32 2024 -0400
Adjust message decoding again to account for servlet API foibles.
---
.../test/java/net/shibboleth/sp/flows/AbstractSPFlowTest.java | 11 +++--------
.../src/test/java/net/shibboleth/sp/flows/PingFlowTest.java | 10 +++++++---
.../src/test/java/net/shibboleth/sp/flows/SealerFlowTest.java | 11 ++++++-----
.../net/shibboleth/sp/profile/impl/DecodeAgentRequest.java | 11 ++++-------
4 files changed, 20 insertions(+), 23 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 6419ed3..0241495 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
@@ -26,9 +26,6 @@ import javax.annotation.Nullable;
import org.apache.commons.codec.binary.Base64;
import org.opensaml.profile.context.ProfileRequestContext;
-import org.opensaml.storage.StorageService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
@@ -68,10 +65,6 @@ public abstract class AbstractSPFlowTest extends AbstractFlowTest {
protected String endStateId;
- @Autowired
- @Qualifier("shibboleth.StorageService")
- StorageService storageService;
-
protected AbstractSPFlowTest(final String id) {
this(id, END_STATE_ID);
}
@@ -155,14 +148,16 @@ public abstract class AbstractSPFlowTest extends AbstractFlowTest {
*/
@Nullable protected DDF assertOutputMessageEvent(@Nonnull final FlowExecutionResult result, @Nullable final String eventId) {
final ProfileRequestContext prc = retrieveProfileRequestContext(result);
+ assert prc != null;
final AgentRequestContext arc = prc.ensureSubcontext(AgentRequestContext.class);
final DDF output = arc.getOutput();
if (eventId != null) {
+ assert output != null;
Assert.assertTrue(output.isstruct());
Assert.assertEquals(output.getmember(EVENT_MEMBER_NAME).string(), eventId);
} else {
- Assert.assertTrue(!output.isstruct() || output.getmember(EVENT_MEMBER_NAME).isnull());
+ Assert.assertTrue(output == null || !output.isstruct() || output.getmember(EVENT_MEMBER_NAME).isnull());
}
Assert.assertEquals(response.getContentType(), "text/plain");
diff --git a/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/PingFlowTest.java b/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/PingFlowTest.java
index 01fbc3c..0d2e2f5 100644
--- a/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/PingFlowTest.java
+++ b/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/PingFlowTest.java
@@ -14,6 +14,7 @@
package net.shibboleth.sp.flows;
+import java.io.IOException;
import java.time.Instant;
import javax.annotation.Nonnull;
@@ -41,7 +42,7 @@ public class PingFlowTest extends AbstractSPFlowTest {
* Test flow without authentication.
*/
@Test
- public void testUnauhenticated() {
+ public void testUnauthenticated() {
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertFlowExecutionResult(result, FLOW_ID);
assertFlowExecutionOutcome(result.getOutcome());
@@ -74,15 +75,18 @@ public class PingFlowTest extends AbstractSPFlowTest {
/**
* Test flow success.
+ * @throws IOException
*/
@Test
- public void testSuccess() {
+ public void testSuccess() throws IOException {
setDefaultAuth();
+ setRequest("GET", new DDF(null), "text/plain");
final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
assertFlowExecutionResult(result, FLOW_ID);
assertFlowExecutionOutcome(result.getOutcome());
final DDF obj = assertOutputMessageEvent(result, null);
- Assert.assertTrue(obj.longinteger() <= Instant.now().toEpochMilli() / 1000);
+ final Long time = obj != null ? obj.longinteger() : null;
+ Assert.assertTrue(time != null && time <= Instant.now().toEpochMilli() / 1000);
}
}
\ No newline at end of file
diff --git a/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/SealerFlowTest.java b/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/SealerFlowTest.java
index 633f2fb..7d73956 100644
--- a/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/SealerFlowTest.java
+++ b/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/SealerFlowTest.java
@@ -18,6 +18,7 @@ import java.io.IOException;
import java.time.Instant;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.opensaml.profile.action.EventIds;
import org.springframework.beans.factory.annotation.Autowired;
@@ -45,7 +46,7 @@ public class SealerFlowTest extends AbstractSPFlowTest {
@Autowired
@Qualifier("shibboleth.DataSealer")
- private DataSealer dataSealer;
+ @Nullable private DataSealer dataSealer;
protected SealerFlowTest() {
super(FLOW_ID);
@@ -93,7 +94,7 @@ public class SealerFlowTest extends AbstractSPFlowTest {
final String wrapped = obj.getmember("value").string();
assert wrapped != null;
try {
- dataSealer.unwrap(wrapped);
+ getDataSealer().unwrap(wrapped);
Assert.fail("Exception should have been raised");
} catch (DataExpiredException e) {
// expected
@@ -122,7 +123,7 @@ public class SealerFlowTest extends AbstractSPFlowTest {
final String wrapped = obj.getmember("value").string();
assert wrapped != null;
- Assert.assertEquals(dataSealer.unwrap(wrapped), AGENT_ID + '!' + TEST_VALUE);
+ Assert.assertEquals(getDataSealer().unwrap(wrapped), AGENT_ID + '!' + TEST_VALUE);
}
/**
@@ -148,7 +149,7 @@ public class SealerFlowTest extends AbstractSPFlowTest {
public void testUnrrapExpired() throws IOException, DataSealerException {
setDefaultAuth();
- final String wrapped = dataSealer.wrap(AGENT_ID + '!' + TEST_VALUE, Instant.now().minusSeconds(3600));
+ final String wrapped = getDataSealer().wrap(AGENT_ID + '!' + TEST_VALUE, Instant.now().minusSeconds(3600));
final DDF input = new DDF().structure();
input.addmember(DoSealerOperation.VALUE).string(wrapped);
@@ -170,7 +171,7 @@ public class SealerFlowTest extends AbstractSPFlowTest {
public void testUnwrapSuccess() throws IOException, DataSealerException {
setDefaultAuth();
- final String wrapped = dataSealer.wrap(AGENT_ID + '!' + TEST_VALUE, Instant.now().plusSeconds(3600));
+ final String wrapped = getDataSealer().wrap(AGENT_ID + '!' + TEST_VALUE, Instant.now().plusSeconds(3600));
final DDF input = new DDF().structure();
input.addmember(DoSealerOperation.VALUE).string(wrapped);
diff --git a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/DecodeAgentRequest.java b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/DecodeAgentRequest.java
index 09b02c2..ccac3fe 100644
--- a/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/DecodeAgentRequest.java
+++ b/sp-server-impl/src/main/java/net/shibboleth/sp/profile/impl/DecodeAgentRequest.java
@@ -38,8 +38,6 @@ import net.shibboleth.sp.messaging.impl.RemotedHttpServletRequest;
* to use. The only supported type at present is "text/plain" representing a record-oriented
* syntax.</p>
*
- * <p>An empty output message is also created and stored in the context.</p>
- *
* <p>If the input message is a structure containing an "http" member, then a wrapped
* {@link HttpServletRequest} object backed by the input message is constructed and stored
* in the {@link AgentRequestContext}.</p>
@@ -68,9 +66,8 @@ public class DecodeAgentRequest extends AbstractAgentRequestAction {
final int contentLength = request.getContentLength();
if (contentLength != 0) {
final String contentType = request.getContentType();
- if (contentType != null && !"text/plain".equals(contentType)) {
- log.warn("{} Invalid HTTP content type ({}), only text/plain supported", getLogPrefix(),
- contentType != null ? contentType : "none");
+ if (!"text/plain".equals(contentType)) {
+ log.warn("{} Invalid HTTP content type ({}), only text/plain supported", getLogPrefix(), contentType);
ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_MESSAGE);
return;
}
@@ -93,10 +90,10 @@ public class DecodeAgentRequest extends AbstractAgentRequestAction {
} catch (final IOException e) {
log.warn("{} Unable to parse input message from HttpServletRequest", getLogPrefix(), e);
ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_MESSAGE);
- return;
}
} else {
- log.debug("{} No request body", getLogPrefix());
+ log.warn("{} Content-Length was zero", getLogPrefix());
+ ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_MESSAGE);
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list