You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by di...@apache.org on 2022/02/11 15:52:36 UTC

[sling-org-apache-sling-resourceresolver] branch issue/SLING-4856 created (now 8b21f69)

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

diru pushed a change to branch issue/SLING-4856
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git.


      at 8b21f69  Merge branch 'issue/SLING-11138' into issue/SLING-4856

This branch includes the following new commits:

     new 7b7367b  Add tests for un-normalized paths being returned from mappings
     new 8b21f69  Merge branch 'issue/SLING-11138' into issue/SLING-4856

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[sling-org-apache-sling-resourceresolver] 01/02: Add tests for un-normalized paths being returned from mappings

Posted by di...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

diru pushed a commit to branch issue/SLING-4856
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git

commit 7b7367bca782295801bf7f286441448d01c08fa2
Author: Dirk Rudolph <dr...@adobe.com>
AuthorDate: Fri Feb 11 16:39:13 2022 +0100

    Add tests for un-normalized paths being returned from mappings
---
 .../resourceresolver/impl/mapping/Mapping.java     |  2 +-
 .../impl/EtcMappingResourceResolverTest.java       | 21 ++++++++++++
 .../impl/MockedResourceResolverImplTest.java       | 39 ++++++++++++++++++++--
 .../sling/resourceresolver/util/MockTestUtil.java  |  6 ++--
 4 files changed, 61 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/Mapping.java b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/Mapping.java
index 4d4f0d9..1e0d5f6 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/Mapping.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/Mapping.java
@@ -66,7 +66,7 @@ public class Mapping {
     // Regular expression to split mapping configuration strings into three
     // groups:
     // 1 - external path prefix
-    // 2 - direction (Outbound (>), Bidirectional (:), Inbound (>))
+    // 2 - direction (Outbound (<), Bidirectional (:), Inbound (>))
     // 3 - internap path prefix
     private static final Pattern CONFIG_SPLITTER = Pattern
             .compile("(.+)([:<>])(.+)");
diff --git a/src/test/java/org/apache/sling/resourceresolver/impl/EtcMappingResourceResolverTest.java b/src/test/java/org/apache/sling/resourceresolver/impl/EtcMappingResourceResolverTest.java
index 3a19ce1..36f53d4 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/EtcMappingResourceResolverTest.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/EtcMappingResourceResolverTest.java
@@ -104,6 +104,7 @@ public class EtcMappingResourceResolverTest {
 
     CommonResourceResolverFactoryImpl commonFactory;
 
+    Resource content;
     Resource etc;
     Resource map;
     Resource http;
@@ -148,6 +149,7 @@ public class EtcMappingResourceResolverTest {
         etc = buildResource("/etc", null, resourceResolver, resourceProvider);
         map = buildResource("/etc/map", etc, resourceResolver, resourceProvider);
         http = buildResource("/etc/map/http", map, resourceResolver, resourceProvider);
+        content = buildResource("/content", null, resourceResolver, resourceProvider);
     }
 
     List<MapConfigurationProvider.VanityPathConfig> getVanityPathConfigs() {
@@ -324,6 +326,25 @@ public class EtcMappingResourceResolverTest {
         checkRedirectResource(resolvedResource, "/content/simple-match/", 302);
     }
 
+    @Test
+    public void match_un_normalized_path() throws Exception {
+        buildResource("test-node", http, resourceResolver, resourceProvider,
+            PROP_REG_EXP, "domain.\\d+",
+            PROP_REDIRECT_INTERNAL, new String[] { "/", "/content/simple-match" }
+        );
+        Resource simpleMatch = buildResource("/content/simple-match", content, resourceResolver, resourceProvider);
+        Resource en = buildResource("/content/simple-match/en", simpleMatch, resourceResolver, resourceProvider);
+
+        refreshMapEntries("/etc/map", true);
+
+        HttpServletRequest request = createRequestFromUrl("http://domain:80/");
+
+        Resource resolvedResource = resourceResolver.resolve(request, "/en.html");
+        checkInternalResource(resolvedResource, "/content/simple-match/en");
+        resolvedResource = resourceResolver.resolve(request, "/etc.clientlibs/foobar.js");
+        checkInternalResource(resolvedResource, "/etc");
+    }
+
     /**
      * ATTENTION: this tests showcases an erroneous condition of an endless circular mapping in the /etc/map. When
      * this test passes this condition is present. After a fix this test must be adjusted.
diff --git a/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java b/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java
index 1205b91..9d1e849 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java
@@ -256,8 +256,13 @@ public class MockedResourceResolverImplTest {
 
             @Override
             public String[] resource_resolver_mapping() {
-                return new String[] { "/:/",
-                        "/content/:/", "/system/docroot/:/", "/content.html-/$" };
+                return new String[] {
+                    "/:/",
+                    "/content/:/",
+                    "/system/docroot/:/",
+                    "/content.html-/$",
+                    "/>/inbound"
+                };
             }
 
             @Override
@@ -431,7 +436,11 @@ public class MockedResourceResolverImplTest {
         Resource resource = mock(Resource.class);
         Mockito.when(resource.getName()).thenReturn(getResourceName(fullpath));
         Mockito.when(resource.getPath()).thenReturn(fullpath);
-        ResourceMetadata resourceMetadata = new ResourceMetadata();
+        ResourceMetadata resourceMetadata = new ResourceMetadata() {
+            @Override public void lock() {
+                // noop, make sure the mock resources can be returned multiple times
+            }
+        };
         Mockito.when(resource.getResourceMetadata()).thenReturn(resourceMetadata);
         Mockito.when(resource.listChildren()).thenReturn(children.iterator());
         Mockito.when(resource.getResourceResolver()).thenReturn(resourceResolver);
@@ -583,6 +592,30 @@ public class MockedResourceResolverImplTest {
         Assert.assertEquals("/single/test.html", path);
     }
 
+    @Test
+    public void testResolve() throws LoginException {
+        ResourceResolver resourceResolver = resourceResolverFactory.getResourceResolver(null);
+        buildResource("/single/test", EMPTY_RESOURCE_LIST, resourceResolver, resourceProvider);
+        buildResource("/content/test", EMPTY_RESOURCE_LIST, resourceResolver, resourceProvider);
+
+        HttpServletRequest request = mock(HttpServletRequest.class);
+        Mockito.when(request.getScheme()).thenReturn("http");
+        Mockito.when(request.getServerPort()).thenReturn(80);
+        Mockito.when(request.getServerName()).thenReturn("localhost");
+
+        Resource resource = resourceResolver.resolve(request,"/single/test");
+        assertEquals("/single/test", resource.getPath());
+
+        resource = resourceResolver.resolve(request,"/content/test");
+        assertEquals("/content/test", resource.getPath());
+
+        resource = resourceResolver.resolve(request,"/test");
+        assertEquals("/content/test", resource.getPath());
+
+        // the mapping />/inbound is actually broken, it should be />/inbound/
+        resource = resourceResolver.resolve(request, "/inbound/content/test");
+        assertEquals("/content/test", resource.getPath());
+    }
 
     /**
      * Tests list children via the resource (NB, this doesn't really test the
diff --git a/src/test/java/org/apache/sling/resourceresolver/util/MockTestUtil.java b/src/test/java/org/apache/sling/resourceresolver/util/MockTestUtil.java
index 5291b5b..b8e15f1 100644
--- a/src/test/java/org/apache/sling/resourceresolver/util/MockTestUtil.java
+++ b/src/test/java/org/apache/sling/resourceresolver/util/MockTestUtil.java
@@ -132,7 +132,7 @@ public class MockTestUtil {
      * @return Mock Resource able to handle addition of children later on
      */
     @SuppressWarnings("unchecked")
-    public static Resource buildResource(String fullPath, Resource parent, ResourceResolver resourceResolver, ResourceProvider<?> provider, String... properties) {
+    public static Resource buildResource(String fullPath, Resource parent, ResourceResolver resourceResolver, ResourceProvider<?> provider, Object... properties) {
         if (properties != null && properties.length % 2 != 0) {
             throw new IllegalArgumentException("List of Resource Properties must be an even number: " + asList(properties));
         }
@@ -172,8 +172,8 @@ public class MockTestUtil {
         if (properties != null) {
             ValueMap vm = new SimpleValueMapImpl();
             for (int i = 0; i < properties.length; i += 2) {
-                resourceMetadata.put(properties[i], properties[i + 1]);
-                vm.put(properties[i], properties[i + 1]);
+                resourceMetadata.put((String) properties[i], properties[i + 1]);
+                vm.put((String) properties[i], properties[i + 1]);
             }
             when(resource.getValueMap()).thenReturn(vm);
             when(resource.adaptTo(Mockito.eq(ValueMap.class))).thenReturn(vm);

[sling-org-apache-sling-resourceresolver] 02/02: Merge branch 'issue/SLING-11138' into issue/SLING-4856

Posted by di...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

diru pushed a commit to branch issue/SLING-4856
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git

commit 8b21f69a8b42a9c1fc5517d91a37852f32a4909b
Merge: 7b7367b 9e59c98
Author: Dirk Rudolph <dr...@adobe.com>
AuthorDate: Fri Feb 11 16:52:22 2022 +0100

    Merge branch 'issue/SLING-11138' into issue/SLING-4856

 .../org/apache/sling/resourceresolver/impl/mapping/MapEntry.java  | 2 +-
 .../sling/resourceresolver/impl/mapping/ResourceMapperImpl.java   | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)