|
@@ -54,6 +54,7 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
|
public class ClientTest extends ClientBase {
|
|
|
protected static final Logger LOG = LoggerFactory.getLogger(ClientTest.class);
|
|
|
+ private boolean skipACL = System.getProperty("zookeeper.skipACL", "no").equals("yes");
|
|
|
|
|
|
/** Verify that pings are sent, keeping the "idle" client alive */
|
|
|
@Test
|
|
@@ -142,23 +143,43 @@ public class ClientTest extends ClientBase {
|
|
|
LOG.info("Test successful, invalid acl received : "
|
|
|
+ e.getMessage());
|
|
|
}
|
|
|
+ try {
|
|
|
+ ArrayList<ACL> testACL = new ArrayList<ACL>();
|
|
|
+ testACL.add(new ACL(Perms.ALL | Perms.ADMIN, new Id()));
|
|
|
+ zk.create("/nullidtest", new byte[0], testACL, CreateMode.PERSISTENT);
|
|
|
+ Assert.fail("Should have received an invalid acl error");
|
|
|
+ } catch(InvalidACLException e) {
|
|
|
+ LOG.info("Test successful, invalid acl received : "
|
|
|
+ + e.getMessage());
|
|
|
+ }
|
|
|
zk.addAuthInfo("digest", "ben:passwd".getBytes());
|
|
|
- zk.create("/acltest", new byte[0], Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
|
|
|
+ ArrayList<ACL> testACL = new ArrayList<ACL>();
|
|
|
+ testACL.add(new ACL(Perms.ALL, new Id("auth","")));
|
|
|
+ testACL.add(new ACL(Perms.WRITE, new Id("ip", "127.0.0.1")));
|
|
|
+ zk.create("/acltest", new byte[0], testACL, CreateMode.PERSISTENT);
|
|
|
zk.close();
|
|
|
zk = createClient();
|
|
|
zk.addAuthInfo("digest", "ben:passwd2".getBytes());
|
|
|
- try {
|
|
|
- zk.getData("/acltest", false, new Stat());
|
|
|
- Assert.fail("Should have received a permission error");
|
|
|
- } catch (KeeperException e) {
|
|
|
- Assert.assertEquals(Code.NOAUTH, e.code());
|
|
|
+ if (skipACL) {
|
|
|
+ try {
|
|
|
+ zk.getData("/acltest", false, null);
|
|
|
+ } catch (KeeperException e) {
|
|
|
+ Assert.fail("Badauth reads should succeed with skipACL.");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ zk.getData("/acltest", false, null);
|
|
|
+ Assert.fail("Should have received a permission error");
|
|
|
+ } catch (KeeperException e) {
|
|
|
+ Assert.assertEquals(Code.NOAUTH, e.code());
|
|
|
+ }
|
|
|
}
|
|
|
zk.addAuthInfo("digest", "ben:passwd".getBytes());
|
|
|
- zk.getData("/acltest", false, new Stat());
|
|
|
+ zk.getData("/acltest", false, null);
|
|
|
zk.setACL("/acltest", Ids.OPEN_ACL_UNSAFE, -1);
|
|
|
zk.close();
|
|
|
zk = createClient();
|
|
|
- zk.getData("/acltest", false, new Stat());
|
|
|
+ zk.getData("/acltest", false, null);
|
|
|
List<ACL> acls = zk.getACL("/acltest", new Stat());
|
|
|
Assert.assertEquals(1, acls.size());
|
|
|
Assert.assertEquals(Ids.OPEN_ACL_UNSAFE, acls);
|
|
@@ -176,6 +197,48 @@ public class ClientTest extends ClientBase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testNullAuthId() throws Exception {
|
|
|
+ ZooKeeper zk = null;
|
|
|
+ try {
|
|
|
+ zk = createClient();
|
|
|
+ zk.addAuthInfo("digest", "ben:passwd".getBytes());
|
|
|
+ ArrayList<ACL> testACL = new ArrayList<ACL>();
|
|
|
+ testACL.add(new ACL(Perms.ALL, new Id("auth", null)));
|
|
|
+ zk.create("/acltest", new byte[0], testACL, CreateMode.PERSISTENT);
|
|
|
+ zk.close();
|
|
|
+ zk = createClient();
|
|
|
+ zk.addAuthInfo("digest", "ben:passwd2".getBytes());
|
|
|
+ if (skipACL) {
|
|
|
+ try {
|
|
|
+ zk.getData("/acltest", false, null);
|
|
|
+ } catch (KeeperException e) {
|
|
|
+ Assert.fail("Badauth reads should succeed with skipACL.");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ zk.getData("/acltest", false, null);
|
|
|
+ Assert.fail("Should have received a permission error");
|
|
|
+ } catch (KeeperException e) {
|
|
|
+ Assert.assertEquals(Code.NOAUTH, e.code());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ zk.addAuthInfo("digest", "ben:passwd".getBytes());
|
|
|
+ zk.getData("/acltest", false, null);
|
|
|
+ zk.setACL("/acltest", Ids.OPEN_ACL_UNSAFE, -1);
|
|
|
+ zk.close();
|
|
|
+ zk = createClient();
|
|
|
+ zk.getData("/acltest", false, null);
|
|
|
+ List<ACL> acls = zk.getACL("/acltest", new Stat());
|
|
|
+ Assert.assertEquals(1, acls.size());
|
|
|
+ Assert.assertEquals(Ids.OPEN_ACL_UNSAFE, acls);
|
|
|
+ } finally {
|
|
|
+ if (zk != null) {
|
|
|
+ zk.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private class MyWatcher extends CountdownWatcher {
|
|
|
LinkedBlockingQueue<WatchedEvent> events =
|
|
|
new LinkedBlockingQueue<WatchedEvent>();
|