[java-plugin-shibd] branch main updated: Add unit tests for lookup strategy class.

Codeberg noreply at shibboleth.net
Wed Jun 3 16:18:13 UTC 2026


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

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

View the commit online:
https://codeberg.org/Shibboleth/java-plugin-shibd/commit/34c12757f56722454ffb9e16228c463d6b39fb16

The following commit(s) were added to refs/heads/main by this push:
     new 34c1275  Add unit tests for lookup strategy class.
34c1275 is described below

commit 34c12757f56722454ffb9e16228c463d6b39fb16
Author: Scott Cantor <scott at restingparrotsoftware.com>
AuthorDate: Wed Jun 3 12:18:01 2026 -0400

    Add unit tests for lookup strategy class.
---
 .../testing/TemplatedStringLookupStrategyTest.java | 99 ++++++++++++++++++++++
 .../sp/profile/util/testing/package-info.java      | 18 ++++
 2 files changed, 117 insertions(+)

diff --git a/sp-server-impl/src/test/java/net/shibboleth/sp/profile/util/testing/TemplatedStringLookupStrategyTest.java b/sp-server-impl/src/test/java/net/shibboleth/sp/profile/util/testing/TemplatedStringLookupStrategyTest.java
new file mode 100644
index 0000000..5591aaa
--- /dev/null
+++ b/sp-server-impl/src/test/java/net/shibboleth/sp/profile/util/testing/TemplatedStringLookupStrategyTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.profile.util.testing;
+
+import java.nio.charset.StandardCharsets;
+
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.testing.VelocityEngine;
+import net.shibboleth.sp.ddf.DDF;
+import net.shibboleth.sp.messaging.RemotedHttpServletRequest;
+import net.shibboleth.sp.profile.impl.BaseApplicationActionTest;
+import net.shibboleth.sp.profile.util.TemplatedStringLookupStrategy;
+
+/**
+ * Unit test for {@link TemplatedStringLookupStrategy} class.
+ */
+public class TemplatedStringLookupStrategyTest extends BaseApplicationActionTest {
+
+    private TemplatedStringLookupStrategy function;
+
+    /**
+     * Set up test.
+     * 
+     * @throws ComponentInitializationException
+     */
+    @BeforeMethod
+    public void setUp() throws ComponentInitializationException {
+        super.beforeMethod();
+        function = new TemplatedStringLookupStrategy();
+        function.setVelocityEngine(VelocityEngine.newVelocityEngine());
+    }
+    
+    /**
+     * Tear down test.
+     */
+    @AfterMethod
+    public void tearDown() {
+        function.destroy();
+        function = null;
+    }
+    
+    /**
+     * Test failure if template absent.
+     * 
+     * @throws ComponentInitializationException
+     */
+    @Test(expectedExceptions=ComponentInitializationException.class)
+    public void testNoTemplate() throws ComponentInitializationException {
+        function.initialize();
+    }
+    
+    /**
+     * Test a literal template.
+     * 
+     * @throws ComponentInitializationException
+     */
+    @Test
+    public void testLiteral() throws ComponentInitializationException {
+        function.setTemplateText("foo");
+        function.initialize();
+        
+        Assert.assertEquals(function.apply(prc), "foo");
+    }
+
+    /**
+     * Test a substitution template.
+     * 
+     * @throws ComponentInitializationException
+     */
+    @Test
+    public void testSubstitutionl() throws ComponentInitializationException {
+        function.setTemplateText("https://$agentRequestContext.getRemotedHttpServletRequest().getServerName()/sp");
+        function.initialize();
+        
+        final DDF request = new DDF().structure();
+        request.addmember("hostname").unsafe_string("sp.example.org".getBytes(StandardCharsets.UTF_8));
+        arc.setRemotedHttpServletRequest(new RemotedHttpServletRequest(request));
+        
+        Assert.assertEquals(function.apply(prc), "https://sp.example.org/sp");
+    }
+
+}
\ No newline at end of file
diff --git a/sp-server-impl/src/test/java/net/shibboleth/sp/profile/util/testing/package-info.java b/sp-server-impl/src/test/java/net/shibboleth/sp/profile/util/testing/package-info.java
new file mode 100644
index 0000000..a269102
--- /dev/null
+++ b/sp-server-impl/src/test/java/net/shibboleth/sp/profile/util/testing/package-info.java
@@ -0,0 +1,18 @@
+/*
+ * 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.
+ */
+
+/**
+ * Testing for classes in util API package to avoid sealing violation.
+ */
+package net.shibboleth.sp.profile.util.testing;
\ 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