@Test public void testEnsurePath() throws Exception { ZooKeeperClient zkClient = createZkClient(); zkClient.get().addAuthInfo("digest", "client1:boo".getBytes(Charsets.UTF_8)); assertNull(zkClient.get().exists("/foo", false)); ZooKeeperUtils.ensurePath(zkClient, ZooDefs.Ids.CREATOR_ALL_ACL, "/foo/bar/baz"); zkClient = createZkClient(); zkClient.get().addAuthInfo("digest", "client2:bap".getBytes(Charsets.UTF_8)); // Anyone can check for existence in ZK assertNotNull(zkClient.get().exists("/foo", false)); assertNotNull(zkClient.get().exists("/foo/bar", false)); assertNotNull(zkClient.get().exists("/foo/bar/baz", false)); try { zkClient.get().delete("/foo/bar/baz", -1 /* delete no matter what */); fail("Expected CREATOR_ALL_ACL to be applied to created path and client2 mutations to be " + "rejected"); } catch (NoAuthException e) { // expected } }
@Test(expected = NoAuthException.class) public void assertInitWithDigestFailure() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(EmbedTestingServer.getConnectionString(), new RetryOneTime(2000)); client.start(); client.blockUntilConnected(); client.getData().forPath("/" + ZookeeperRegistryCenterForAuthTest.class.getName() + "/test/deep/nested"); }
@Test(expected = NoAuthException.class) public void assertInitWithDigestFailure() throws Exception { zkRegCenter.init(); zkRegCenter.close(); CuratorFramework client = CuratorFrameworkFactory.newClient(ZK_CONNECTION_STRING, new RetryOneTime(2000)); client.start(); client.blockUntilConnected(); client.getData().forPath("/" + ZookeeperRegistryCenterForAuthTest.class.getName() + "/test/deep/nested"); }
/** * 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 } }
@Test public void testClientWithoutZKSecret() { try (FluoClient client = FluoFactory.newClient(miniFluo.getClientConfiguration())) { try (Transaction tx = client.newTransaction()) { tx.set("node08", new Column("edge", "forward"), "node75"); tx.commit(); } miniFluo.waitForObservers(); } FluoConfiguration conf = new FluoConfiguration(miniFluo.getClientConfiguration()); conf.setZookeeperSecret(""); try (FluoClient client = FluoFactory.newClient(conf)) { Assert.fail("Expected client creation to fail. " + client); } catch (Exception e) { boolean sawNoAuth = false; Throwable throwable = e; while (throwable != null) { if (throwable instanceof NoAuthException) { sawNoAuth = true; break; } throwable = throwable.getCause(); } Assert.assertTrue(sawNoAuth); } }
public static void reportError(Throwable t) { Throwable cause = t.getCause(); if (cause != null && cause != t) { reportError(cause); return; } boolean showCustomErrorMessageDialog = false; int style = StatusManager.LOG; String title = "Error"; String message = t.getLocalizedMessage(); if (t instanceof KeeperException) { KeeperException ke = (KeeperException) t; title = "ZooKeeper Error"; showCustomErrorMessageDialog = true; if (ke instanceof InvalidACLException) { title = "Invalid ACL"; message = "ACL is invalid for '" + ke.getPath() + "'."; } else if (ke instanceof NodeExistsException) { title = "Znode Exists"; message = "Znode '" + ke.getPath() + "' already exists."; } else if (ke instanceof NoAuthException) { title = "Not Authorized"; message = "Not authorized to perform this action on '" + ke.getPath() + "'."; } else if (ke instanceof NoNodeException) { title = "No Znode"; message = "Znode '" + ke.getPath() + "' does not exist."; } else if (ke instanceof NotEmptyException) { title = "Not Empty"; message = "Znode '" + ke.getPath() + "' has children."; } } if (showCustomErrorMessageDialog) { MessageDialog.openError(Display.getCurrent().getActiveShell(), title, message); } else { style = style | StatusManager.BLOCK; } Status status = new Status(IStatus.ERROR, PLUGIN_ID, message, t); StatusManager.getManager().handle(status, style); }