[java-plugin-shibd] branch main updated: Unit tests for parse-request-map flow.
Scott Cantor
cantor.2 at osu.edu
Fri Jul 5 17:04:06 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=b345d5e3e1cab6e94cd8dac8437bec8f769b3460
The following commit(s) were added to refs/heads/main by this push:
new b345d5e Unit tests for parse-request-map flow.
b345d5e is described below
commit b345d5e3e1cab6e94cd8dac8437bec8f769b3460
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Fri Jul 5 13:03:43 2024 -0400
Unit tests for parse-request-map flow.
---
.../sp/flows/ParseRequestMapFlowTest.java | 143 +++++++++++++++++++++
.../net/shibboleth/sp/config/impl/example-map.ddf | 0
.../net/shibboleth/sp/config/impl/example-map.xml | 9 ++
3 files changed, 152 insertions(+)
diff --git a/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/ParseRequestMapFlowTest.java b/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/ParseRequestMapFlowTest.java
new file mode 100644
index 0000000..e3e1c39
--- /dev/null
+++ b/sp-conf-impl/src/test/java/net/shibboleth/sp/flows/ParseRequestMapFlowTest.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.sp.flows;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+
+import javax.annotation.Nonnull;
+
+import org.opensaml.profile.action.EventIds;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.webflow.executor.FlowExecutionResult;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import net.shibboleth.sp.SPConstants;
+import net.shibboleth.sp.ddf.DDF;
+import net.shibboleth.sp.ddf.DDFSupport;
+
+/**
+ * Unit test for the SP RequestMap-parsing flow.
+ */
+ at SuppressWarnings("javadoc")
+public class ParseRequestMapFlowTest extends AbstractSPFlowTest {
+
+ /** Flow ID. */
+ @Nonnull public static final String FLOW_ID = "sp/parse-request-map";
+
+ protected ParseRequestMapFlowTest() {
+ super(FLOW_ID);
+ }
+
+ @Test
+ public void testWrapNoInput() {
+ setDefaultAuth();
+ request.setMethod("POST");
+ final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
+ assertFlowExecutionResult(result, FLOW_ID);
+ assertFlowExecutionOutcome(result.getOutcome());
+ assertOutputMessageEvent(result, EventIds.INVALID_MESSAGE);
+ }
+
+ @Test
+ public void testNonWellFormed() throws IOException {
+ setDefaultAuth();
+
+ final DDF input = new DDF().unsafe_string("<RequestMap".getBytes(Charset.forName("UTF-8")));
+ setRequest("POST", input);
+
+ final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
+ assertFlowExecutionResult(result, FLOW_ID);
+ assertFlowExecutionOutcome(result.getOutcome());
+ assertOutputMessageEvent(result, EventIds.INVALID_MESSAGE);
+ }
+
+ @Test
+ public void testInvalid() throws IOException {
+ setDefaultAuth();
+
+ final DDF input = new DDF().unsafe_string("<RequestMap/>".getBytes(Charset.forName("UTF-8")));
+ setRequest("POST", input);
+
+ final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
+ assertFlowExecutionResult(result, FLOW_ID);
+ assertFlowExecutionOutcome(result.getOutcome());
+ assertOutputMessageEvent(result, EventIds.INVALID_MESSAGE);
+ }
+
+ @Test
+ public void testEmpty() throws IOException {
+ setDefaultAuth();
+
+ final DDF input = new DDF().unsafe_string("<RequestMap xmlns='urn:mace:shibboleth:sp:requestmap:4.0'/>".getBytes(Charset.forName("UTF-8")));
+ setRequest("POST", input);
+
+ final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
+ assertFlowExecutionResult(result, FLOW_ID);
+ assertFlowExecutionOutcome(result.getOutcome());
+ final DDF output = assertOutputMessageEvent(result, null);
+
+ assert output != null;
+ Assert.assertTrue(output.isstruct());
+ Assert.assertTrue(output.getmember("RequestMap").isstruct());
+ Assert.assertEquals(output.getmember("RequestMap.xmlns").string(), SPConstants.SHIBSP4_REQUESTMAP_NS);
+ }
+
+ @Test
+ public void testFull() throws IOException {
+ setDefaultAuth();
+
+ final ClassPathResource resource = new ClassPathResource("/net/shibboleth/sp/config/impl/example-map.xml");
+ try (final InputStream in = resource.getInputStream()) {
+ assert in != null;
+ final byte[] bytes = in.readAllBytes();
+ final DDF input = new DDF().unsafe_string(bytes);
+ setRequest("POST", input);
+ }
+
+ // To capture wire input needed to drive flow.
+ // arc.getInput().serialize(System.err);
+
+ // Sample command to run flow:
+ // $ cd sp-server-impl/src/test/resources/net/shibboleth/sp/config/impl/
+ // $ curl -k -X POST -H "Content-Type: text/plain" --data-binary @example-map.ddf -u sp.example.org:foo https://localhost/idp/profile/sp/parse-request-map
+
+ final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
+ assertFlowExecutionResult(result, FLOW_ID);
+ assertFlowExecutionOutcome(result.getOutcome());
+ final DDF output = assertOutputMessageEvent(result, null);
+
+ assert output != null;
+ Assert.assertTrue(output.isstruct());
+ Assert.assertTrue(output.getmember("RequestMap").isstruct());
+
+ final DDF nestedPath = output.getmember("RequestMap")
+ .getmember(DDFSupport.CHILD_ELEMENTS_MEMBER)
+ .asList().get(0)
+ .getmember(DDFSupport.CHILD_ELEMENTS_MEMBER)
+ .asList().get(0)
+ .getmember(DDFSupport.CHILD_ELEMENTS_MEMBER)
+ .asList().get(0)
+ .getmember(DDFSupport.CHILD_ELEMENTS_MEMBER)
+ .asList().get(0);
+
+ Assert.assertEquals(nestedPath.name(), "Path");
+ Assert.assertTrue(nestedPath.isstruct());
+ Assert.assertEquals(nestedPath.getmember("applicationId").string(), "example-special");
+ }
+
+}
\ No newline at end of file
diff --git a/sp-server-impl/src/test/resources/net/shibboleth/sp/config/impl/example-map.ddf b/sp-conf-impl/src/test/resources/net/shibboleth/sp/config/impl/example-map.ddf
similarity index 100%
rename from sp-server-impl/src/test/resources/net/shibboleth/sp/config/impl/example-map.ddf
rename to sp-conf-impl/src/test/resources/net/shibboleth/sp/config/impl/example-map.ddf
diff --git a/sp-conf-impl/src/test/resources/net/shibboleth/sp/config/impl/example-map.xml b/sp-conf-impl/src/test/resources/net/shibboleth/sp/config/impl/example-map.xml
new file mode 100644
index 0000000..ec8f7d4
--- /dev/null
+++ b/sp-conf-impl/src/test/resources/net/shibboleth/sp/config/impl/example-map.xml
@@ -0,0 +1,9 @@
+<RequestMap xmlns="urn:mace:shibboleth:sp:requestmap:4.0" applicationId="default">
+ <Host name="www.example.org">
+ <Path name="secure" requireSession="true">
+ <Path name="apps">
+ <Path name="special" applicationId="example-special"/>
+ </Path>
+ </Path>
+ </Host>
+</RequestMap>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list