Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CEDB46A02 for ; Fri, 3 Jun 2011 17:28:33 +0000 (UTC) Received: (qmail 9636 invoked by uid 500); 3 Jun 2011 17:28:33 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 9594 invoked by uid 500); 3 Jun 2011 17:28:33 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 9587 invoked by uid 99); 3 Jun 2011 17:28:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Jun 2011 17:28:33 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Jun 2011 17:28:32 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 458712388A2C; Fri, 3 Jun 2011 17:28:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1131116 - in /sling/trunk/bundles/jcr/resource: pom.xml src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java Date: Fri, 03 Jun 2011 17:28:12 -0000 To: commits@sling.apache.org From: justin@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110603172812.458712388A2C@eris.apache.org> Author: justin Date: Fri Jun 3 17:28:11 2011 New Revision: 1131116 URL: http://svn.apache.org/viewvc?rev=1131116&view=rev Log: SLING-2093 - adding test Modified: sling/trunk/bundles/jcr/resource/pom.xml sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java Modified: sling/trunk/bundles/jcr/resource/pom.xml URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/pom.xml?rev=1131116&r1=1131115&r2=1131116&view=diff ============================================================================== --- sling/trunk/bundles/jcr/resource/pom.xml (original) +++ sling/trunk/bundles/jcr/resource/pom.xml Fri Jun 3 17:28:11 2011 @@ -214,5 +214,11 @@ 1.4 test + + org.apache.sling + org.apache.sling.jcr.base + 2.1.0 + test + Modified: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java?rev=1131116&r1=1131115&r2=1131116&view=diff ============================================================================== --- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java (original) +++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java Fri Jun 3 17:28:11 2011 @@ -41,6 +41,8 @@ import javax.servlet.http.HttpSession; import junitx.util.PrivateAccessor; +import org.apache.jackrabbit.api.security.principal.PrincipalManager; +import org.apache.jackrabbit.api.security.user.UserManager; import org.apache.sling.api.SlingConstants; import org.apache.sling.api.resource.NonExistingResource; import org.apache.sling.api.resource.Resource; @@ -51,6 +53,7 @@ import org.apache.sling.api.resource.Syn import org.apache.sling.api.resource.ValueMap; import org.apache.sling.commons.testing.jcr.RepositoryTestBase; import org.apache.sling.commons.testing.jcr.RepositoryUtil; +import org.apache.sling.jcr.base.util.AccessControlUtil; import org.apache.sling.jcr.resource.JcrResourceConstants; import org.apache.sling.jcr.resource.internal.helper.MapEntries; import org.apache.sling.jcr.resource.internal.helper.Mapping; @@ -77,6 +80,7 @@ public class JcrResourceResolverTest ext private Node rootWs2Node; + protected void setUp() throws Exception { super.setUp(); assertTrue(RepositoryUtil.registerNodeType(getSession(), @@ -163,6 +167,15 @@ public class JcrResourceResolverTest ext Node child = rootWs2Node.addNode("child1"); child.addNode("child2"); ws2Session.save(); + + UserManager userMan = AccessControlUtil.getUserManager(session); + try { + userMan.createUser("testuser", "test"); + } catch (Exception e) { + if (!e.getMessage().equals("User for 'testuser' already exists")) { + throw e; + } + } } @Override @@ -1826,6 +1839,62 @@ public class JcrResourceResolverTest ext assertEquals(grandchild.getPath(), resNodeEnkel.getPath()); } + public void test_resolve_with_sling_alias_limited_access() throws Exception { + Principal testUserPrincipal = AccessControlUtil.getPrincipalManager(session).getPrincipal("testuser"); + + Node child = rootNode.addNode("child"); + child.setProperty(JcrResourceResolver.PROP_ALIAS, "kind"); + AccessControlUtil.replaceAccessControlEntry(session, child.getPath(), testUserPrincipal, null, new String[] {"jcr:all"}, null, "last"); + session.save(); + + Session testUserSession = getRepository().login(new SimpleCredentials("testuser", "test".toCharArray())); + ResourceResolver testUserResolver = resFac.getResourceResolver(testUserSession); + + try { + // expect child due to the aliased not not being visible and no parent + // due to mapping the rootPath onto root + String path = "/child"; + String mapped = testUserResolver.map(child.getPath()); + assertEquals(path, mapped); + + Resource res = testUserResolver.resolve(null, path); + assertNotNull(res); + assertTrue(res instanceof NonExistingResource); + assertEquals("/child", + res.getResourceMetadata().getResolutionPath()); + // TODO - is this correct? + assertEquals(null, res.getResourceMetadata().getResolutionPathInfo()); + + // second level alias + Node grandchild = child.addNode("grandchild"); + grandchild.setProperty(JcrResourceResolver.PROP_ALIAS, "enkel"); + AccessControlUtil.replaceAccessControlEntry(session, grandchild.getPath(), testUserPrincipal, new String[] { "jcr:all" }, null, null, "first"); + session.save(); + + // expect /child/enkel due to alias and the child node not being + // visible to the test user and no parent due to mapping + // the rootPath onto root + String pathEnkel = "/child/grandchild"; + String mappedEnkel = testUserResolver.map(grandchild.getPath()); + assertEquals(pathEnkel, mappedEnkel); + + /* + Resource resEnkel = testUserResolver.resolve(null, pathEnkel); + assertNotNull(resEnkel); + assertEquals(rootNode.getPath() + "/kind/enkel", + resEnkel.getResourceMetadata().getResolutionPath()); + assertEquals("", resEnkel.getResourceMetadata().getResolutionPathInfo()); + + Node resNodeEnkel = resEnkel.adaptTo(Node.class); + assertNotNull(resNodeEnkel); + assertEquals(grandchild.getPath(), resNodeEnkel.getPath()); + */ + } finally { + testUserSession.logout(); + } + } + + public void test_resolve_with_sling_alias_ws() throws Exception { Node child = rootWs2Node.addNode("child");