Repository: curator Updated Branches: refs/heads/CURATOR-132 [created] 973513855
CURATOR-132 - Modified the NamespaceFacade so that it does not proxy getACL() and setACL() calls to the underlying client (which is not namespace aware), and instead handles them itself. Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/97351385 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/97351385 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/97351385 Branch: refs/heads/CURATOR-132 Commit: 97351385561f3038b2aba9a25a617a204a14e023 Parents: f5767c8 Author: Cam McKenzie <[email protected]> Authored: Mon Aug 4 10:04:22 2014 +1000 Committer: Cam McKenzie <[email protected]> Committed: Mon Aug 4 10:04:22 2014 +1000 ---------------------------------------------------------------------- .../curator/framework/imps/NamespaceFacade.java | 12 ----- .../framework/imps/TestNamespaceFacade.java | 46 ++++++++++++++++++++ 2 files changed, 46 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/97351385/curator-framework/src/main/java/org/apache/curator/framework/imps/NamespaceFacade.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/NamespaceFacade.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/NamespaceFacade.java index 3584ff9..818fe5f 100644 --- a/curator-framework/src/main/java/org/apache/curator/framework/imps/NamespaceFacade.java +++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/NamespaceFacade.java @@ -71,18 +71,6 @@ class NamespaceFacade extends CuratorFrameworkImpl } @Override - public GetACLBuilder getACL() - { - return client.getACL(); - } - - @Override - public SetACLBuilder setACL() - { - return client.setACL(); - } - - @Override public Listenable<ConnectionStateListener> getConnectionStateListenable() { return client.getConnectionStateListenable(); http://git-wip-us.apache.org/repos/asf/curator/blob/97351385/curator-framework/src/test/java/org/apache/curator/framework/imps/TestNamespaceFacade.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestNamespaceFacade.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestNamespaceFacade.java index f67c603..475e7e9 100644 --- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestNamespaceFacade.java +++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestNamespaceFacade.java @@ -18,11 +18,18 @@ */ package org.apache.curator.framework.imps; +import java.util.Collections; +import java.util.List; + import org.apache.curator.test.BaseClassForTests; import org.apache.curator.utils.CloseableUtils; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.retry.ExponentialBackoffRetry; import org.apache.curator.retry.RetryOneTime; +import org.apache.zookeeper.ZooDefs; +import org.apache.zookeeper.KeeperException.NoAuthException; +import org.apache.zookeeper.data.ACL; import org.testng.Assert; import org.testng.annotations.Test; @@ -183,4 +190,43 @@ public class TestNamespaceFacade extends BaseClassForTests client.close(); Assert.assertEquals(client.isStarted(), namespaced.isStarted()); } + + /** + * Test that ACLs work on a NamespaceFacade. See CURATOR-132 + * @throws Exception + */ + @Test + public void testACL() throws Exception + { + CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); + client.start(); + client.getZookeeperClient().blockUntilConnectedOrTimedOut(); + + client.create().creatingParentsIfNeeded().forPath("/parent/child", "A string".getBytes()); + CuratorFramework client2 = client.usingNamespace("parent"); + + Assert.assertNotNull(client2.getData().forPath("/child")); + client.setACL().withACL(Collections.singletonList( + new ACL(ZooDefs.Perms.WRITE, ZooDefs.Ids.ANYONE_ID_UNSAFE))). + forPath("/parent/child"); + // This will attempt to setACL on /parent/child, Previously this failed because /child + // isn't present. Using "child" would case a failure because the path didn't start with + // a slash + try + { + List<ACL> acls = client2.getACL().forPath("/child"); + Assert.assertNotNull(acls); + Assert.assertEquals(acls.size(), 1); + Assert.assertEquals(acls.get(0).getId(), ZooDefs.Ids.ANYONE_ID_UNSAFE); + Assert.assertEquals(acls.get(0).getPerms(), ZooDefs.Perms.WRITE); + client2.setACL().withACL(Collections.singletonList( + new ACL(ZooDefs.Perms.DELETE, ZooDefs.Ids.ANYONE_ID_UNSAFE))). + forPath("/child"); + Assert.fail("Expected auth exception was not thrown"); + } + catch(NoAuthException e) + { + //Expected + } + } }
