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

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

commit 9800e4f7a7aadee212c3acfdcfb34fb40634cede
Author: Bertrand Delacretaz <[email protected]>
AuthorDate: Thu Feb 20 12:12:36 2020 +0100

    SLING-8757 - add integration tests for the home() functions syntax
---
 pom.xml                                             |  2 +-
 .../sling/jcr/repoinit/it/RepoInitTestSupport.java  |  2 +-
 .../sling/jcr/repoinit/it/RepoInitTextIT.java       | 21 ++++++++++++++++++++-
 .../java/org/apache/sling/jcr/repoinit/it/U.java    | 13 +++++++++++++
 src/test/resources/repoinit.txt                     |  9 +++++++++
 5 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/pom.xml b/pom.xml
index 840f1c7..b580379 100644
--- a/pom.xml
+++ b/pom.xml
@@ -219,7 +219,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.repoinit.parser</artifactId>
-            <version>1.4.0</version>
+            <version>1.4.1-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
diff --git 
a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java 
b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java
index 8c13b07..4019d65 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java
@@ -63,6 +63,7 @@ public abstract class RepoInitTestSupport extends TestSupport 
{
     @Configuration
     public Option[] configuration() {
         
SlingOptions.versionResolver.setVersionFromProject("org.apache.jackrabbit", 
"jackrabbit-api");
+        SlingOptions.versionResolver.setVersionFromProject("org.apache.sling", 
"org.apache.sling.repoinit.parser");
         final String localRepo = System.getProperty("maven.repo.local", "");
         final Option[] options = 
         remove(new Option[] {
@@ -75,7 +76,6 @@ public abstract class RepoInitTestSupport extends TestSupport 
{
             when(localRepo.length() > 0).useOptions(
                 
systemProperty("org.ops4j.pax.url.mvn.localRepository").value(localRepo)
             ),
-            
mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.repoinit.parser").versionAsInProject(),
             junitBundles(),
             
newConfiguration("org.apache.sling.jcr.base.internal.LoginAdminWhitelist")
                 .put("whitelist.bundles.regexp", "^PAXEXAM.*$")
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTextIT.java 
b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTextIT.java
index 4903b7d..10b363f 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTextIT.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTextIT.java
@@ -44,6 +44,8 @@ public class RepoInitTextIT extends RepoInitTestSupport {
 
     private static final String FRED_WILMA = "fredWilmaService";
     private static final String ANOTHER = "anotherService";
+    private static final String ALICE = "alice";
+    private static final String BOB = "bob";
 
     public static final String REPO_INIT_FILE = "/repoinit.txt";
 
@@ -72,11 +74,13 @@ public class RepoInitTextIT extends RepoInitTestSupport {
     }
 
     @Test
-    public void serviceUserCreated() throws Exception {
+    public void serviceUserCreatedWithHomePath() throws Exception {
         new Retry() {
             @Override
             public Void call() throws Exception {
                 assertTrue("Expecting user " + FRED_WILMA, 
U.userExists(session, FRED_WILMA));
+                final String path = U.getHomePath(session, FRED_WILMA);
+                assertTrue("Expecting path " + path, session.itemExists(path));
                 return null;
             }
         };
@@ -112,4 +116,19 @@ public class RepoInitTextIT extends RepoInitTestSupport {
         session.getRootNode().addNode(nodeName, "slingtest:unstructured");
         session.save();
     }
+
+    @Test
+    public void fredWilmaHomeAcl() throws Exception {
+        new Retry() {
+            @Override
+            public Void call() throws Exception {
+                assertTrue("Expecting user " + FRED_WILMA, 
U.userExists(session, FRED_WILMA));
+                final String path = U.getHomePath(session, FRED_WILMA);
+                assertTrue("Expecting path " + path, session.itemExists(path));
+                assertTrue("Expecting write access for alice", 
U.canWrite(session, ALICE, path));
+                assertFalse("Expecting no access for bob", U.canRead(session, 
BOB, path));
+                return null;
+            }
+        };
+    }
 }
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/U.java 
b/src/test/java/org/apache/sling/jcr/repoinit/it/U.java
index cf834a3..499e94f 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/it/U.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/U.java
@@ -25,6 +25,7 @@ import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
+import javax.jcr.UnsupportedRepositoryOperationException;
 
 import org.apache.jackrabbit.api.JackrabbitSession;
 import org.apache.jackrabbit.api.security.user.Authorizable;
@@ -66,6 +67,9 @@ public class U {
             serviceSession.save();
         } catch(AccessDeniedException ade) {
             return false;
+        } catch(PathNotFoundException pnf) {
+            // Thrown when access is denied to a user's home node
+            return false;
         } finally {
             serviceSession.logout();
         }
@@ -84,9 +88,18 @@ public class U {
             serviceSession.getItem(path);
         } catch(AccessDeniedException ade) {
             return false;
+        } catch(PathNotFoundException pnf) {
+            // Thrown when access is denied to a user's home node
+            return false;
         } finally {
             serviceSession.logout();
         }
         return true;
     }
+
+    public static String getHomePath(Session session, String userId)
+    throws UnsupportedRepositoryOperationException, RepositoryException {
+        final Authorizable a = 
((JackrabbitSession)session).getUserManager().getAuthorizable(userId);
+        return a.getPath();
+    }
 }
\ No newline at end of file
diff --git a/src/test/resources/repoinit.txt b/src/test/resources/repoinit.txt
index 17d892d..897f262 100644
--- a/src/test/resources/repoinit.txt
+++ b/src/test/resources/repoinit.txt
@@ -47,3 +47,12 @@ register nodetypes
 << <slingtest='http://sling.apache.org/ns/test/repoinit-it/v1.0'>
 << [slingtest:unstructured] > nt:unstructured
 ===>>
+
+# SLING-8757 home() functions
+create user alice
+create user bob
+
+set ACL on home(fredWilmaService)
+  allow jcr:all for alice
+  deny jcr:all for bob
+end
\ No newline at end of file

Reply via email to