[java-plugin-shibd] branch main updated: Unit test for criteria comparisons.

Codeberg noreply at shibboleth.net
Mon Aug 31 13:40:28 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/77e776e20740fe10258318079ab5b63d209cf85d

The following commit(s) were added to refs/heads/main by this push:
     new 77e776e  Unit test for criteria comparisons.
77e776e is described below

commit 77e776e20740fe10258318079ab5b63d209cf85d
Author: Scott Cantor <scott at restingparrotsoftware.com>
AuthorDate: Mon Aug 31 09:40:18 2026 -0400

    Unit test for criteria comparisons.
---
 .../net/shibboleth/sp/criteria/CriteriaTest.java   | 207 +++++++++++++++++++++
 1 file changed, 207 insertions(+)

diff --git a/sp-server-api/src/test/java/net/shibboleth/sp/criteria/CriteriaTest.java b/sp-server-api/src/test/java/net/shibboleth/sp/criteria/CriteriaTest.java
new file mode 100644
index 0000000..ffc8642
--- /dev/null
+++ b/sp-server-api/src/test/java/net/shibboleth/sp/criteria/CriteriaTest.java
@@ -0,0 +1,207 @@
+/*
+ * 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.criteria;
+
+import javax.annotation.Nonnull;
+
+import org.opensaml.core.criterion.EntityIdCriterion;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.profile.criterion.ProfileRequestContextCriterion;
+import org.opensaml.saml.criterion.ProtocolCriterion;
+import org.opensaml.security.credential.UsageType;
+import org.opensaml.security.criteria.UsageCriterion;
+import org.opensaml.security.x509.X509Credential;
+import org.testng.Assert;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import net.shibboleth.shared.collection.Pair;
+import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.resolver.ClassCriterion;
+import net.shibboleth.shared.resolver.CriteriaSet;
+
+/**
+ * Tests for comparison of criteria classes.
+ * 
+ * <p>Notably, {@link ClassCriterion} is broken for this API version
+ * and doesn't override equals, so we have to omit it from the test.</p>
+ */
+ at SuppressWarnings("javadoc")
+public class CriteriaTest {
+
+    @Test(dataProvider="criteria")
+    public void testComparison(@Nonnull Pair<CriteriaSet,CriteriaSet> criteria,
+            @Nonnull final Pair<String,String> agent, @Nonnull final Pair<String,String> application,
+            @Nonnull final Pair<String,String> entityID, @Nonnull final Pair<String,String> protocol,
+            @Nonnull final Pair<UsageType,UsageType> usage, @Nonnull final Pair<Class<?>,Class<?>> type,
+            final boolean equal) {
+
+        final CriteriaSet criteria1 = criteria.getFirst();
+        final CriteriaSet criteria2 = criteria.getSecond();
+        assert criteria1 != null && criteria2 != null;
+        
+        if (agent.getFirst() != null) {
+            criteria1.add(new AgentIDCriterion(Constraint.isNotNull(agent.getFirst(), "null?")));
+        }
+        if (agent.getSecond() != null) {
+            criteria2.add(new AgentIDCriterion(Constraint.isNotNull(agent.getSecond(), "null?")));
+        }
+        
+        if (application.getFirst() != null) {
+            criteria1.add(new ApplicationIDCriterion(Constraint.isNotNull(application.getFirst(), "null?")));
+        }
+        if (application.getSecond() != null) {
+            criteria2.add(new ApplicationIDCriterion(Constraint.isNotNull(application.getSecond(), "null?")));
+        }
+
+        if (entityID.getFirst() != null) {
+            criteria1.add(new EntityIdCriterion(Constraint.isNotNull(entityID.getFirst(), "null?")));
+        }
+        if (entityID.getSecond() != null) {
+            criteria2.add(new EntityIdCriterion(Constraint.isNotNull(entityID.getSecond(), "null?")));
+        }
+        
+        if (protocol.getFirst() != null) {
+            criteria1.add(new ProtocolCriterion(Constraint.isNotNull(protocol.getFirst(), "null?")));
+        }
+        if (protocol.getSecond() != null) {
+            criteria2.add(new ProtocolCriterion(Constraint.isNotNull(protocol.getSecond(), "null?")));
+        }
+        
+        if (usage.getFirst() != null) {
+            criteria1.add(new UsageCriterion(Constraint.isNotNull(usage.getFirst(), "null?")));
+        }
+        if (usage.getSecond() != null) {
+            criteria2.add(new UsageCriterion(Constraint.isNotNull(usage.getSecond(), "null?")));
+        }
+
+        /*
+        if (type.getFirst() != null) {
+            criteria1.add(new ClassCriterion<>(Constraint.isNotNull(type.getFirst(), "null?")));
+        }
+        if (type.getSecond() != null) {
+            criteria2.add(new ClassCriterion<>(Constraint.isNotNull(type.getSecond(), "null?")));
+        }
+        */
+        
+        if (equal) {
+            Assert.assertEquals(criteria1, criteria2);
+        } else {
+            Assert.assertNotEquals(criteria1, criteria2);
+        }
+     }
+    
+    @DataProvider(name = "criteria")
+    public Object[][] getCriteria() throws Exception {
+        final ProfileRequestContext prc1 = new ProfileRequestContext();
+        final ProfileRequestContext prc2 = new ProfileRequestContext();
+        
+        final String agent1 = "localhost1";
+        final String agent2 = "localhost2";
+        
+        final String app1 = "default";
+        final String app2 = "override";
+        
+        final String entity1 = "https://sp.example.org/1";
+        final String entity2 = "https://sp.example.org/2";
+        
+        final String protocol1 = "foo1";
+        final String protocol2 = "foo2";
+        
+        return new Object[][] {
+            new Object[] {
+                    new Pair<>(new CriteriaSet(), new CriteriaSet()),
+                    new Pair<>(agent1, agent1),
+                    new Pair<>(app1, app1),
+                    new Pair<>(entity1, entity1),
+                    new Pair<>(protocol1, protocol1),
+                    new Pair<>(UsageType.SIGNING, UsageType.SIGNING),
+                    new Pair<>(X509Credential.class, X509Credential.class),
+                    true
+            },
+            new Object[] {
+                    new Pair<>(new CriteriaSet(), new CriteriaSet()),
+                    new Pair<>(agent1, agent2),
+                    new Pair<>(app1, app1),
+                    new Pair<>(entity1, entity1),
+                    new Pair<>(protocol1, protocol1),
+                    new Pair<>(UsageType.SIGNING, UsageType.SIGNING),
+                    new Pair<>(X509Credential.class, X509Credential.class),
+                    false
+            },
+            new Object[] {
+                    new Pair<>(new CriteriaSet(), new CriteriaSet()),
+                    new Pair<>(agent1, agent1),
+                    new Pair<>(app1, app2),
+                    new Pair<>(entity1, entity1),
+                    new Pair<>(protocol1, protocol1),
+                    new Pair<>(UsageType.SIGNING, UsageType.SIGNING),
+                    new Pair<>(X509Credential.class, X509Credential.class),
+                    false
+            },
+            new Object[] {
+                    new Pair<>(new CriteriaSet(), new CriteriaSet()),
+                    new Pair<>(agent1, agent1),
+                    new Pair<>(app1, app1),
+                    new Pair<>(entity1, entity2),
+                    new Pair<>(protocol1, protocol1),
+                    new Pair<>(UsageType.SIGNING, UsageType.SIGNING),
+                    new Pair<>(X509Credential.class, X509Credential.class),
+                    false
+            },
+            new Object[] {
+                    new Pair<>(new CriteriaSet(), new CriteriaSet()),
+                    new Pair<>(agent1, agent1),
+                    new Pair<>(app1, app1),
+                    new Pair<>(entity1, entity1),
+                    new Pair<>(protocol1, protocol2),
+                    new Pair<>(UsageType.SIGNING, UsageType.SIGNING),
+                    new Pair<>(X509Credential.class, X509Credential.class),
+                    false
+            },
+            new Object[] {
+                    new Pair<>(new CriteriaSet(), new CriteriaSet()),
+                    new Pair<>(agent1, agent1),
+                    new Pair<>(app1, app1),
+                    new Pair<>(entity1, entity1),
+                    new Pair<>(protocol1, protocol1),
+                    new Pair<>(UsageType.SIGNING, UsageType.ENCRYPTION),
+                    new Pair<>(X509Credential.class, X509Credential.class),
+                    false
+            },
+            new Object[] {
+                    new Pair<>(new CriteriaSet(new ProfileRequestContextCriterion(prc1)), new CriteriaSet(new ProfileRequestContextCriterion(prc1))),
+                    new Pair<>(agent1, agent1),
+                    new Pair<>(app1, app1),
+                    new Pair<>(entity1, entity1),
+                    new Pair<>(protocol1, protocol1),
+                    new Pair<>(UsageType.SIGNING, UsageType.SIGNING),
+                    new Pair<>(X509Credential.class, X509Credential.class),
+                    true
+            },
+            new Object[] {
+                    new Pair<>(new CriteriaSet(new ProfileRequestContextCriterion(prc1)), new CriteriaSet(new ProfileRequestContextCriterion(prc2))),
+                    new Pair<>(agent1, agent1),
+                    new Pair<>(app1, app1),
+                    new Pair<>(entity1, entity1),
+                    new Pair<>(protocol1, protocol1),
+                    new Pair<>(UsageType.SIGNING, UsageType.SIGNING),
+                    new Pair<>(X509Credential.class, X509Credential.class),
+                    false
+            },
+        };
+    }    
+
+}
\ 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