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:06:07 UTC

[sling-org-apache-sling-resourceresolver] branch issue/SLING-11138 created (now a645bca)

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

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


      at a645bca  Fix MapEntry#replace() handling invalid substitutions

This branch includes the following new commits:

     new c5c648a  Mapping tests fail
     new d10cdc8  Fix MapEntries creation
     new a645bca  Fix MapEntry#replace() handling invalid substitutions

The 3 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/03: Mapping tests fail

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-11138
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git

commit c5c648a47d2c7c406d06e52b575430edf7c84273
Author: Dirk Rudolph <dr...@adobe.com>
AuthorDate: Fri Feb 11 15:46:21 2022 +0100

    Mapping tests fail
    
    Assert that the mock mappings are actually read by the RRF. This doesn't work currently.
---
 .../resourceresolver/impl/MockedResourceResolverImplTest.java     | 8 ++++++++
 1 file changed, 8 insertions(+)

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 d0c7b84..1be9116 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java
@@ -17,9 +17,11 @@
  */
 package org.apache.sling.resourceresolver.impl;
 
+import static org.apache.sling.resourceresolver.util.MockTestUtil.getInaccessibleField;
 import static org.apache.sling.resourceresolver.util.MockTestUtil.getResourceName;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
@@ -325,6 +327,11 @@ public class MockedResourceResolverImplTest {
         for (String path : activator.getAllowedAliasLocations()) {
             assertFalse("Path must not end with '/': " + path, StringUtils.endsWith(path, "/"));
         }
+
+        // ensure mappings are set
+        assertNotEquals("Mappings unavailable",
+            MapEntries.EMPTY,
+            getInaccessibleField("commonFactory",rrf,CommonResourceResolverFactoryImpl.class).getMapEntries());
     }
 
     public static ResourceProviderHandler createRPHandler(ResourceProvider<?> rp, String pid, long ranking,
@@ -541,6 +548,7 @@ public class MockedResourceResolverImplTest {
         Mockito.when(request.getScheme()).thenReturn("http");
         Mockito.when(request.getServerPort()).thenReturn(80);
         Mockito.when(request.getServerName()).thenReturn("localhost");
+
         String path = resourceResolver.map(request,"/single/test?q=123123");
         Assert.assertEquals("/single/test?q=123123", path);
         buildResource("/single/test", EMPTY_RESOURCE_LIST, resourceResolver, resourceProvider);

[sling-org-apache-sling-resourceresolver] 03/03: Fix MapEntry#replace() handling invalid substitutions

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-11138
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git

commit a645bca9f8f23e04c56166c2eff1385dc3bebb4f
Author: Dirk Rudolph <dr...@adobe.com>
AuthorDate: Fri Feb 11 16:05:57 2022 +0100

    Fix MapEntry#replace() handling invalid substitutions
---
 .../sling/resourceresolver/impl/mapping/MapEntry.java      | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntry.java b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntry.java
index 67553d8..1d595a1 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntry.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntry.java
@@ -279,7 +279,7 @@ public class MapEntry implements Comparable<MapEntry> {
         final Matcher m = urlPattern.matcher(value);
         if (m.find()) {
             final String[] redirects = getRedirect();
-            final String[] results = new String[redirects.length];
+            final List<String> results = new ArrayList<>(redirects.length);
             for (int i = 0; i < redirects.length; i++) {
             	try {
             		String redirect = redirects[i];
@@ -298,14 +298,12 @@ public class MapEntry implements Comparable<MapEntry> {
             				}
             			}
             		}
-            		results[i] = m.replaceFirst(redirect);
-            	} catch (final StringIndexOutOfBoundsException siob){
-            		log.debug("Exception while replacing, ignoring entry {} ", redirects[i], siob);
-                } catch (final IllegalArgumentException iae){
-                    log.debug("Exception while replacing, ignoring entry {} ", redirects[i], iae);
-             	}
+            		results.add(m.replaceFirst(redirect));
+            	} catch (final StringIndexOutOfBoundsException | IllegalArgumentException ex){
+            		log.debug("Exception while replacing, ignoring entry {} ", redirects[i], ex);
+                }
             }
-            return results;
+            return results.size() > 0 ? results.toArray(new String[0]) : null;
         }
 
         return null;

[sling-org-apache-sling-resourceresolver] 02/03: Fix MapEntries creation

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-11138
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git

commit d10cdc81444a3e4fa8ab9d9255ef5306b7a95355
Author: Dirk Rudolph <dr...@adobe.com>
AuthorDate: Fri Feb 11 15:53:47 2022 +0100

    Fix MapEntries creation
    
    This makes sure the MapEntries are correctly parsed when activating the RRF. Tests still fail.
---
 .../impl/MockedResourceResolverImplTest.java       | 23 +++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

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 1be9116..1205b91 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/MockedResourceResolverImplTest.java
@@ -24,6 +24,10 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 import java.lang.annotation.Annotation;
 import java.util.ArrayList;
@@ -48,6 +52,7 @@ import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.api.wrappers.ValueMapDecorator;
 import org.apache.sling.resourceresolver.impl.mapping.MapEntries;
+import org.apache.sling.resourceresolver.impl.mapping.StringInterpolationProvider;
 import org.apache.sling.resourceresolver.impl.observation.ResourceChangeListenerWhiteboard;
 import org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler;
 import org.apache.sling.resourceresolver.impl.providers.ResourceProviderInfo;
@@ -148,13 +153,12 @@ public class MockedResourceResolverImplTest {
         activator = new ResourceResolverFactoryActivator();
 
         // system bundle access
-        final Bundle systemBundle = Mockito.mock(Bundle.class);
+        final Bundle systemBundle = mock(Bundle.class);
         Mockito.when(systemBundle.getState()).thenReturn(Bundle.ACTIVE);
         Mockito.when(bundleContext.getBundle(Constants.SYSTEM_BUNDLE_LOCATION)).thenReturn(systemBundle);
         activator.resourceAccessSecurityTracker = new ResourceAccessSecurityTracker();
         activator.resourceProviderTracker = resourceProviderTracker;
         activator.changeListenerWhiteboard = resourceChangeListenerWhiteboard;
-        activator.serviceUserMapper = Mockito.mock(ServiceUserMapper.class);
         handlers.add(createRPHandler(resourceProvider, "org.apache.sling.resourceresolver.impl.DummyTestProvider", 10L, "/"));
 
         // setup mapping resources at /etc/map to exercise vanity etc.
@@ -169,9 +173,14 @@ public class MockedResourceResolverImplTest {
         Mockito.when(queriableResourceProviderA.getQueryLanguageProvider()).thenReturn(queryProvider);
 
         ResourceProviderStorage storage = new ResourceProviderStorage(handlers);
-
         Mockito.when(resourceProviderTracker.getResourceProviderStorage()).thenReturn(storage);
 
+        activator.serviceUserMapper = mock(ServiceUserMapper.class);
+        when(activator.serviceUserMapper.getServicePrincipalNames(any(), any())).thenReturn(Collections.singletonList("user"));
+
+        activator.stringInterpolationProvider = mock(StringInterpolationProvider.class);
+        when(activator.stringInterpolationProvider.substitute(anyString())).thenAnswer(inv -> (String) inv.getArguments()[0]);
+
         // activate the components.
         activator.activate(bundleContext, new ResourceResolverFactoryConfig() {
             @Override
@@ -336,8 +345,8 @@ public class MockedResourceResolverImplTest {
 
     public static ResourceProviderHandler createRPHandler(ResourceProvider<?> rp, String pid, long ranking,
             String path) {
-        ServiceReference ref = Mockito.mock(ServiceReference.class);
-        BundleContext bc = Mockito.mock(BundleContext.class);
+        ServiceReference ref = mock(ServiceReference.class);
+        BundleContext bc = mock(BundleContext.class);
         Mockito.when(bc.getService(Mockito.eq(ref))).thenReturn(rp);
         Mockito.when(ref.getProperty(Mockito.eq(Constants.SERVICE_ID))).thenReturn(new Random().nextLong());
         Mockito.when(ref.getProperty(Mockito.eq(Constants.SERVICE_PID))).thenReturn(pid);
@@ -419,7 +428,7 @@ public class MockedResourceResolverImplTest {
      */
     @SuppressWarnings("unchecked")
     private Resource buildResource(String fullpath, Iterable<Resource> children, ResourceResolver resourceResolver, ResourceProvider<?> provider, String ... properties) {
-        Resource resource = Mockito.mock(Resource.class);
+        Resource resource = mock(Resource.class);
         Mockito.when(resource.getName()).thenReturn(getResourceName(fullpath));
         Mockito.when(resource.getPath()).thenReturn(fullpath);
         ResourceMetadata resourceMetadata = new ResourceMetadata();
@@ -544,7 +553,7 @@ public class MockedResourceResolverImplTest {
     public void testMapping() throws LoginException {
         ResourceResolver resourceResolver = resourceResolverFactory.getResourceResolver(null);
         buildResource("/single/test", EMPTY_RESOURCE_LIST, resourceResolver, resourceProvider);
-        HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+        HttpServletRequest request = mock(HttpServletRequest.class);
         Mockito.when(request.getScheme()).thenReturn("http");
         Mockito.when(request.getServerPort()).thenReturn(80);
         Mockito.when(request.getServerName()).thenReturn("localhost");