use of org.apache.zookeeper.KeeperException.NoAuthException in project xian by happyyangyuan.
the class TestNamespaceFacade method testACL.
/**
* 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");
// 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
}
}
Aggregations