You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by jo...@apache.org on 2023/01/19 09:55:24 UTC

[sling-org-apache-sling-resourceresolver] branch master updated: SLING-11755: resource resolver: improve test coverage for vanity path targets (#92)

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

joerghoh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git


The following commit(s) were added to refs/heads/master by this push:
     new 11ba5e9  SLING-11755: resource resolver: improve test coverage for vanity path targets (#92)
11ba5e9 is described below

commit 11ba5e9ce8b091b43fbaee355bb67ea7edcd74d9
Author: Julian Reschke <ju...@gmx.de>
AuthorDate: Thu Jan 19 10:55:17 2023 +0100

    SLING-11755: resource resolver: improve test coverage for vanity path targets (#92)
    
    * SLING-11755: resource resolver: add test coverage for URL patterns in vanity paths
    * SLING-11755: resource resolver: add test coverage for edge cases in vanity paths
    * SLING-11755: fix host names
    * SLING-11755: reformat/comment
    * SLING-11755: add test for path-less URL pattern
---
 .../impl/mapping/ResourceMapperImplTest.java       | 80 ++++++++++++++++++++--
 1 file changed, 75 insertions(+), 5 deletions(-)

diff --git a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java
index 88f610e..e0094ca 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java
@@ -114,8 +114,15 @@ public class ResourceMapperImplTest {
         resourceProvider.putResource("/parent/child", PROP_ALIAS, "alias-child"); // child has alias
         resourceProvider.putResource("/parent/child-multiple", PROP_ALIAS, "alias-child-1", "alias-child-2"); // child has multiple alias
         resourceProvider.putResource("/vain", "sling:vanityPath", "/vanity-a", "/vanity-b"); // vanity path
-        // vanity path with URL shaped target, see SLING-11749
-        resourceProvider.putResource("/vain-url", "sling:vanityPath", /* "https://example.com", TODO: NPE*/ "https://example/", "https://example/foo"); 
+
+        // Tests to complete coverage of vanity path formats; test expectations based on behavior as of Jan 2023, not necessarily common sense 
+        resourceProvider.putResource("/vain-ext", "sling:vanityPath", "/vanity-a/foo.txt", "/vanity.bar/foo"); // vanity path with extensions
+        resourceProvider.putResource("/vain-empty", "sling:vanityPath", ""); // vanity path empty
+        resourceProvider.putResource("/vain-relative", "sling:vanityPath", "foobar"); // vanity path not absolute
+        resourceProvider.putResource("/vain-url", "sling:vanityPath", "https://example.com/", "https://example.com/foo"); 
+        resourceProvider.putResource("/vain-url-invalid", "sling:vanityPath", "://pathOfMalformed"); 
+        resourceProvider.putResource("/vain-url-nopath", "sling:vanityPath", "https://example.com"); 
+
         // build /etc/map structure
         resourceProvider.putResource("/etc");
         resourceProvider.putResource("/etc/map");
@@ -330,11 +337,47 @@ public class ResourceMapperImplTest {
             .verify(resolver, req);
     }
 
+    /**
+     * Validates that vanity paths are returned as mappings; test removal of extensions.
+     */
+    @Test
+    public void mapResourceWithVanityPathsWithExt() {
+        ExpectedMappings.existingResource("/vain-ext")
+            .singleMapping("/vain-ext")
+            .singleMappingWithRequest("/app/vain-ext")
+            .allMappings("/vain-ext", "/vanity.bar/foo", "/vanity-a/foo")
+            .allMappingsWithRequest("/app/vain-ext", "/app/vanity.bar/foo", "/app/vanity-a/foo")
+            .verify(resolver, req);
+    }
+
+    /**
+     * Validates that vanity paths are returned as mappings; test empty target
+     */
+    @Test
+    public void mapResourceWithVanityPathsTargetEmpty() {
+        ExpectedMappings.existingResource("/vain-empty")
+            .singleMapping("/vain-empty")
+            .singleMappingWithRequest("/app/vain-empty")
+            .allMappings("/vain-empty")
+            .allMappingsWithRequest("/app/vain-empty")
+            .verify(resolver, req);
+    }
+
+    /**
+     * Validates that vanity paths are returned as mappings; test non-abs target
+     */
+    @Test
+    public void mapResourceWithVanityPathsTargetNonAbs() {
+        ExpectedMappings.existingResource("/vain-relative")
+            .singleMapping("/vain-relative")
+            .singleMappingWithRequest("/app/vain-relative")
+            .allMappings("/vain-relative", "/foobar")
+            .allMappingsWithRequest("/app/vain-relative", "/app/foobar")
+            .verify(resolver, req);
+    }
+
     /**
      * Validates that vanity paths are returned as mappings, URL shaped variants (see see SLING-11749)
-     *
-     * <p>As vanity paths are alternate paths rather than variations so they will not be returned
-     * from the singleMapping() methods.</p>
      */
     @Test
     public void mapResourceWithVanityPathsURLTarget() {
@@ -346,6 +389,33 @@ public class ResourceMapperImplTest {
             .verify(resolver, req);
     }
 
+    /**
+     * Validates that vanity paths are returned as mappings, URL shaped variants, empty path (see see SLING-11757)
+     */
+    @Test(expected = NullPointerException.class)
+    public void mapResourceWithVanityPathsURLTargetNoPath() {
+        ExpectedMappings.existingResource("/vain-url-nopath")
+            .singleMapping("/vain-url-nopath")
+            .singleMappingWithRequest("/app/vain-url-nopath")
+            .allMappings("/vain-url-nopath", "see SLING-11757")
+            .allMappingsWithRequest("/app/vain-url-nopath", "see SLING-11757")
+            .verify(resolver, req);
+    }
+
+    /**
+     * Validates that vanity paths are returned as mappings, invalid URL shaped variants (see see SLING-11749)
+     * @throws MalformedURLException 
+     */
+    @Test
+    public void mapResourceWithVanityPathsInvalidURLTarget() {
+        ExpectedMappings.existingResource("/vain-url-invalid")
+            .singleMapping("/vain-url-invalid")
+            .singleMappingWithRequest("/app/vain-url-invalid")
+            .allMappings("/vain-url-invalid")
+            .allMappingsWithRequest("/app/vain-url-invalid")
+            .verify(resolver, req);
+    }
+
     /**
      * Validates that the mapping for a non-existing resource that is the target of an alias
      * is the alias itself