This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch resolver-2.x
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-resolver.git


The following commit(s) were added to refs/heads/resolver-2.x by this push:
     new 84d43fa  SLING-12739 - verify that predicate name is checked
84d43fa is described below

commit 84d43fa6448e907f98799ff6b7d678071b746636
Author: Bertrand Delacretaz <[email protected]>
AuthorDate: Thu Jul 10 16:29:11 2025 +0200

    SLING-12739 - verify that predicate name is checked
---
 .../it/resourcehiding/BadPredicateNameIT.java      | 59 ++++++++++++++++++++++
 .../it/resourcehiding/ResourceHidingITBase.java    |  9 +++-
 2 files changed, 67 insertions(+), 1 deletion(-)

diff --git 
a/src/test/java/org/apache/sling/servlets/resolver/it/resourcehiding/BadPredicateNameIT.java
 
b/src/test/java/org/apache/sling/servlets/resolver/it/resourcehiding/BadPredicateNameIT.java
new file mode 100644
index 0000000..d8e8f7b
--- /dev/null
+++ 
b/src/test/java/org/apache/sling/servlets/resolver/it/resourcehiding/BadPredicateNameIT.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.sling.servlets.resolver.it.resourcehiding;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class BadPredicateNameIT extends ResourceHidingITBase {
+
+    @Before
+    public void setupPredicate() {
+        registerPredicate(path -> true, 
"invalid.name.that.causes.the.predicate.to.be.ignored");
+    }
+
+    @After
+    public void checkNothingHidden() {
+        assertEquals(0, hiddenResourcesCount);
+    }
+
+    @Test
+    public void testExtApresent() throws Exception {
+        assertTestServlet("/." + EXT_A, EXT_A);
+    }
+
+    @Test
+    public void testExtBpresent() throws Exception {
+        assertTestServlet("/." + EXT_B, EXT_B);
+    }
+
+    @Test
+    public void testSelApresent() throws Exception {
+        assertTestServlet("/." + SEL_A + "." + EXT_A, SEL_A);
+    }
+}
diff --git 
a/src/test/java/org/apache/sling/servlets/resolver/it/resourcehiding/ResourceHidingITBase.java
 
b/src/test/java/org/apache/sling/servlets/resolver/it/resourcehiding/ResourceHidingITBase.java
index 86cd3bb..5d8631c 100644
--- 
a/src/test/java/org/apache/sling/servlets/resolver/it/resourcehiding/ResourceHidingITBase.java
+++ 
b/src/test/java/org/apache/sling/servlets/resolver/it/resourcehiding/ResourceHidingITBase.java
@@ -24,6 +24,7 @@ import java.util.function.Predicate;
 
 import org.apache.sling.servlets.resolver.it.ServletResolverTestSupport;
 import org.apache.sling.servlets.resolver.it.TestServlet;
+import org.jetbrains.annotations.Nullable;
 import org.junit.Before;
 
 /** Base for all our hiding tests, so that they all use the same set of 
servlets  */
@@ -34,6 +35,8 @@ public class ResourceHidingITBase extends 
ServletResolverTestSupport {
     protected final static String SEL_A = "SEL_A" + UUID.randomUUID();
     protected int hiddenResourcesCount = 0;
 
+    public final static String PREDICATE_NAME = 
"sling.servlet.resolver.resource.hiding";
+
     @Before
     public void reset() {
         hiddenResourcesCount = 0;
@@ -65,6 +68,10 @@ public class ResourceHidingITBase extends 
ServletResolverTestSupport {
     }
 
     protected void registerPredicate(Predicate<String> p) {
+        registerPredicate(p, null);
+    }
+
+    protected void registerPredicate(Predicate<String> p, @Nullable String 
name) {
         final Predicate<String> wrappedPredicate = new Predicate<String>() {
             @Override
             public boolean test(String path) {
@@ -76,7 +83,7 @@ public class ResourceHidingITBase extends 
ServletResolverTestSupport {
             }
         };
         final Hashtable<String,String> props = new Hashtable<>();
-        props.put("name","sling.servlet.resolver.resource.hiding");
+        props.put("name", name != null ? name : PREDICATE_NAME);
         bundleContext.registerService(Predicate.class.getName(), 
wrappedPredicate, props);
     }
 }
\ No newline at end of file

Reply via email to