You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by an...@apache.org on 2021/01/28 12:58:50 UTC

[sling-org-apache-sling-serviceusermapper] branch issues/SLING-10099 created (now 228889c)

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

angela pushed a change to branch issues/SLING-10099
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-serviceusermapper.git.


      at 228889c  SLING-10099 : Validators should all agree for a service user to be valid and should be configurable (tests with 2 validators)

This branch includes the following new commits:

     new 228889c  SLING-10099 : Validators should all agree for a service user to be valid and should be configurable (tests with 2 validators)

The 1 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-serviceusermapper] 01/01: SLING-10099 : Validators should all agree for a service user to be valid and should be configurable (tests with 2 validators)

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

angela pushed a commit to branch issues/SLING-10099
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-serviceusermapper.git

commit 228889cbdc50367c5656dc14b85c6ed6603eb1a0
Author: angela <an...@adobe.com>
AuthorDate: Thu Jan 28 13:58:29 2021 +0100

    SLING-10099 : Validators should all agree for a service user to be valid and should be configurable (tests with 2 validators)
---
 .../impl/ServiceUserMapperImplTest.java            | 67 ++++++++++++++++++----
 1 file changed, 57 insertions(+), 10 deletions(-)

diff --git a/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java b/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java
index 92c8abf..f94b8af 100644
--- a/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java
+++ b/src/test/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImplTest.java
@@ -34,6 +34,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
+import java.util.stream.StreamSupport;
 
 import org.apache.sling.serviceusermapping.ServicePrincipalsValidator;
 import org.apache.sling.serviceusermapping.ServiceUserValidator;
@@ -205,6 +206,33 @@ public class ServiceUserMapperImplTest {
     }
 
     @Test
+    public void test_getServiceUserID_WithMultipleValidators() {
+        ServiceUserMapperImpl.Config config = mock(ServiceUserMapperImpl.Config.class);
+        when(config.user_mapping()).thenReturn(new String[] {
+                BUNDLE_SYMBOLIC1 + "=" + SAMPLE, //
+                BUNDLE_SYMBOLIC2 + "=" + ANOTHER, //
+                BUNDLE_SYMBOLIC1 + ":" + SUB + "=" + SAMPLE_SUB, //
+                BUNDLE_SYMBOLIC2 + ":" + SUB + "=" + ANOTHER_SUB //
+        });
+        when(config.user_default()).thenReturn(NONE);
+        when(config.user_enable_default_mapping()).thenReturn(false);
+
+        final ServiceUserMapperImpl sum = new ServiceUserMapperImpl(null, config);
+        ServiceUserValidator sampleInvalid = (serviceUserId, serviceName, subServiceName) -> !SAMPLE.equals(serviceUserId);
+        sum.bindServiceUserValidator(sampleInvalid);
+
+        ServiceUserValidator anotherInvalid = (serviceUserId, serviceName, subServiceName) -> !ANOTHER.equals(serviceUserId);
+        sum.bindServiceUserValidator(anotherInvalid);
+
+        assertNull(sum.getServiceUserID(BUNDLE1, null));
+        assertNull(sum.getServiceUserID(BUNDLE2, null));
+        assertNull(sum.getServiceUserID(BUNDLE1, ""));
+        assertNull(sum.getServiceUserID(BUNDLE2, ""));
+        assertEquals(SAMPLE_SUB, sum.getServiceUserID(BUNDLE1, SUB));
+        assertEquals(ANOTHER_SUB, sum.getServiceUserID(BUNDLE2, SUB));
+    }
+
+    @Test
     public void test_getServicePrincipalNames() {
         ServiceUserMapperImpl.Config config = mock(ServiceUserMapperImpl.Config.class);
         when(config.user_mapping()).thenReturn(new String[] {
@@ -281,16 +309,8 @@ public class ServiceUserMapperImplTest {
         });
 
         final ServiceUserMapperImpl sum = new ServiceUserMapperImpl(null, config);
-        ServicePrincipalsValidator validator = new ServicePrincipalsValidator() {
-            @Override
-            public boolean isValid(Iterable<String> servicePrincipalNames, String serviceName, String subServiceName) {
-                for (String pName : servicePrincipalNames) {
-                    if (SAMPLE.equals(pName)) {
-                        return false;
-                    }
-                }
-                return true;
-            }
+        ServicePrincipalsValidator validator = (servicePrincipalNames, serviceName, subServiceName) -> {
+            return StreamSupport.stream(servicePrincipalNames.spliterator(), false).noneMatch(SAMPLE::equals);
         };
         sum.bindServicePrincipalsValidator(validator);
 
@@ -300,6 +320,33 @@ public class ServiceUserMapperImplTest {
         assertNull(sum.getServicePrincipalNames(BUNDLE2, SUB));
     }
 
+    @Test
+    public void test_getServicePrincipalnames_WithMultipleValidators() {
+        ServiceUserMapperImpl.Config config = mock(ServiceUserMapperImpl.Config.class);
+        when(config.user_mapping()).thenReturn(new String[] {
+                BUNDLE_SYMBOLIC1 + "=[" + SAMPLE + "]", //
+                BUNDLE_SYMBOLIC2 + "=[" + ANOTHER + "," + SAMPLE + "]", //
+                BUNDLE_SYMBOLIC1 + ":" + SUB + "=[validPrincipal," + SAMPLE + "]", //
+                BUNDLE_SYMBOLIC2 + ":" + SUB + "=[validPrincipal," + SAMPLE_SUB + "," + ANOTHER + "]"//
+        });
+
+        final ServiceUserMapperImpl sum = new ServiceUserMapperImpl(null, config);
+        ServicePrincipalsValidator sampleInvalid = (servicePrincipalNames, serviceName, subServiceName) -> {
+            return StreamSupport.stream(servicePrincipalNames.spliterator(), false).noneMatch(SAMPLE::equals);
+        };
+        sum.bindServicePrincipalsValidator(sampleInvalid);
+
+        ServicePrincipalsValidator anotherInvalid = (servicePrincipalNames, serviceName, subServiceName) -> {
+            return StreamSupport.stream(servicePrincipalNames.spliterator(), false).noneMatch(ANOTHER::equals);
+        };
+        sum.bindServicePrincipalsValidator(anotherInvalid);
+
+        assertNull(sum.getServicePrincipalNames(BUNDLE1, null));
+        assertNull(sum.getServicePrincipalNames(BUNDLE2, null));
+        assertNull(sum.getServicePrincipalNames(BUNDLE1, SUB));
+        assertNull(sum.getServicePrincipalNames(BUNDLE2, SUB));
+    }
+
     private static void assertEqualPrincipalNames(Iterable<String> result, String... expected) {
         if (expected == null) {
             assertNull(result);