Jelajahi Sumber

ZOOKEEPER-3891: ZKCli commands give wrong error message "Authenticati…

…on is not valid" for insufficient permissions

Author: Mohammad Arshad <arshad@apache.org>

Reviewers: Enrico Olivelli <eolivelli@apache.org>, Mate Szalay-Beko <symat@apache.org>

Closes #1404 from arshadmohammad/ZOOKEEPER-3891-master
Mohammad Arshad 4 tahun lalu
induk
melakukan
8a72a6e6c3

+ 2 - 2
zookeeper-docs/src/main/resources/markdown/zookeeperCLI.md

@@ -68,7 +68,7 @@ Add a authorized user for ACL
 
 ```bash
 [zkshell: 9] getAcl /acl_digest_test
-    Authentication is not valid : /acl_digest_test
+    Insufficient permission : /acl_digest_test
 [zkshell: 10] addauth digest user1:12345
 [zkshell: 11] getAcl /acl_digest_test
     'digest,'user1:+owfoSBn/am19roBPzR1/MfCblE=
@@ -354,7 +354,7 @@ Pre-requisites:
 
 1. set reconfigEnabled=true in the zoo.cfg
 
-2. add a super user or skipAcl,otherwise will get “Authentication is not valid”. e.g. addauth digest zookeeper:admin
+2. add a super user or skipAcl,otherwise will get “Insufficient permission”. e.g. addauth digest zookeeper:admin
 
 ```bash
 # Change follower 2 to an observer and change its port from 2182 to 12182

+ 1 - 1
zookeeper-server/src/main/java/org/apache/zookeeper/cli/CliWrapperException.java

@@ -43,7 +43,7 @@ public class CliWrapperException extends CliException {
             } else if (keeperException instanceof KeeperException.InvalidACLException) {
                 return "Acl is not valid : " + keeperException.getPath();
             } else if (keeperException instanceof KeeperException.NoAuthException) {
-                return "Authentication is not valid : " + keeperException.getPath();
+                return "Insufficient permission : " + keeperException.getPath();
             } else if (keeperException instanceof KeeperException.BadArgumentsException) {
                 return "Arguments are not valid : " + keeperException.getPath();
             } else if (keeperException instanceof KeeperException.BadVersionException) {

+ 17 - 2
zookeeper-server/src/test/java/org/apache/zookeeper/ZooKeeperTest.java

@@ -498,15 +498,20 @@ public class ZooKeeperTest extends ClientBase {
         final ZooKeeper zk = createClient();
         ZooKeeperMain zkMain = new ZooKeeperMain(zk);
         String cmd1 = "redo -1";
+        String result = executeLine(zkMain, cmd1);
+        assertEquals("Command index out of range", result);
+    }
 
+    private String executeLine(ZooKeeperMain zkMain, String cmd)
+        throws InterruptedException, IOException {
         // setup redirect out/err streams to get System.in/err, use this
         // judiciously!
         final PrintStream systemErr = System.err; // get current err
         final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
         System.setErr(new PrintStream(errContent));
         try {
-            zkMain.executeLine(cmd1);
-            assertEquals("Command index out of range", errContent.toString().trim());
+            zkMain.executeLine(cmd);
+            return errContent.toString().trim();
         } finally {
             // revert redirect of out/err streams - important step!
             System.setErr(systemErr);
@@ -685,4 +690,14 @@ public class ZooKeeperTest extends ClientBase {
         runCommandExpect(cmd, expected);
     }
 
+    @Test
+    public void testInsufficientPermission() throws Exception {
+        final ZooKeeper zk = createClient();
+        zk.create("/permZNode", "".getBytes(), Ids.READ_ACL_UNSAFE, CreateMode.PERSISTENT);
+        ZooKeeperMain zkMain = new ZooKeeperMain(zk);
+        String zNodeToBeCreated = "/permZNode/child1";
+        String errorMessage = executeLine(zkMain, "create " + zNodeToBeCreated);
+        assertEquals("Insufficient permission : " + zNodeToBeCreated, errorMessage);
+    }
+
 }