{"action":"created","comment":{"url":"https://api.github.com/repos/apache/zookeeper/pulls/comments/116581847","pull_request_review_id":38196456,"id":116581847,"diff_hunk":"@@ -0,0 +1,187 @@\n+/**\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License.  You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.apache.zookeeper;\n+\n+import java.io.File;\n+import java.io.FileWriter;\n+import java.io.IOException;\n+import java.lang.reflect.Field;\n+import java.util.ArrayList;\n+import java.util.List;\n+import java.util.concurrent.atomic.AtomicInteger;\n+import static org.junit.Assert.assertTrue;\n+\n+import org.apache.zookeeper.ClientCnxn.SendThread;\n+import org.apache.zookeeper.Watcher.Event.KeeperState;\n+import org.apache.zookeeper.ZooDefs.Ids;\n+import org.apache.zookeeper.data.ACL;\n+import org.apache.zookeeper.data.Id;\n+import org.apache.zookeeper.test.ClientBase;\n+import org.junit.AfterClass;\n+import org.junit.Assert;\n+import org.junit.BeforeClass;\n+import org.junit.Test;\n+\n+public class SaslAuthTest extends ClientBase {\n+\n+    @BeforeClass\n+    public static void init() {\n+        System.setProperty(\"zookeeper.authProvider.1\", \"org.apache.zookeeper.server.auth.SASLAuthenticationProvider\");\n+        try {\n+            File tmpDir = createTmpDir();\n+            File saslConfFile = new File(tmpDir, \"jaas.conf\");\n+            FileWriter fwriter = new FileWriter(saslConfFile);\n+\n+            fwriter.write(\"\" + \"Server {\\n\" + \"          org.apache.zookeeper.server.auth.DigestLoginModule required\\n\"\n+                    + \"          user_super=\\\"test\\\";\\n\" + \"};\\n\" + \"Client {\\n\"\n+                    + \"       org.apache.zookeeper.server.auth.DigestLoginModule required\\n\"\n+                    + \"       username=\\\"super\\\"\\n\" + \"       password=\\\"test\\\";\\n\" + \"};\" + \"\\n\");\n+            fwriter.close();\n+            System.setProperty(\"java.security.auth.login.config\", saslConfFile.getAbsolutePath());\n+        } catch (IOException e) {\n+            // could not create tmp directory to hold JAAS conf file : test will\n+            // fail now.\n+        }\n+    }\n+\n+    @AfterClass\n+    public static void clean() {\n+        System.clearProperty(\"zookeeper.authProvider.1\");\n+        System.clearProperty(\"java.security.auth.login.config\");\n+    }\n+\n+    private AtomicInteger authFailed = new AtomicInteger(0);\n+\n+    @Override\n+    protected TestableZooKeeper createClient(String hp) throws IOException, InterruptedException {\n+        MyWatcher watcher = new MyWatcher();\n+        return createClient(watcher, hp);\n+    }\n+\n+    private class MyWatcher extends CountdownWatcher {\n+        @Override\n+        public synchronized void process(WatchedEvent event) {\n+            if (event.getState() == KeeperState.AuthFailed) {\n+                authFailed.incrementAndGet();\n+            } else {\n+                super.process(event);\n+            }\n+        }\n+    }\n+\n+    @Test\n+    public void testAuth() throws Exception {\n+        ZooKeeper zk = createClient();\n+        try {\n+            zk.create(\"/path1\", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);\n+            Thread.sleep(1000);\n+        } finally {\n+            zk.close();\n+        }\n+    }\n+\n+    @Test\n+    public void testValidSaslIds() throws Exception {\n+        ZooKeeper zk = createClient();\n+\n+        List<String> validIds = new ArrayList<String>();\n+        validIds.add(\"user\");\n+        validIds.add(\"service/host.name.com\");\n+        validIds.add(\"user@KERB.REALM\");\n+        validIds.add(\"service/host.name.com@KERB.REALM\");\n+\n+        int i = 0;\n+        for (String validId : validIds) {\n+            List<ACL> aclList = new ArrayList<ACL>();\n+            ACL acl = new ACL(0, new Id(\"sasl\", validId));\n+            aclList.add(acl);\n+            zk.create(\"/valid\" + i, null, aclList, CreateMode.PERSISTENT);\n+            i++;\n+        }\n+    }\n+\n+    @Test\n+    public void testInvalidSaslIds() throws Exception {\n+        ZooKeeper zk = createClient();\n+\n+        List<String> invalidIds = new ArrayList<String>();\n+        invalidIds.add(\"user@KERB.REALM/server.com\");\n+        invalidIds.add(\"user@KERB.REALM1@KERB.REALM2\");\n+\n+        int i = 0;\n+        for (String invalidId : invalidIds) {\n+            List<ACL> aclList = new ArrayList<ACL>();\n+            try {\n+                ACL acl = new ACL(0, new Id(\"sasl\", invalidId));\n+                aclList.add(acl);\n+                zk.create(\"/invalid\" + i, null, aclList, CreateMode.PERSISTENT);\n+                Assert.fail(\"SASLAuthenticationProvider.isValid() failed to catch invalid Id.\");\n+            } catch (KeeperException.InvalidACLException e) {\n+                // ok.\n+            } finally {\n+                i++;\n+            }\n+        }\n+    }\n+\n+    @Test\n+    public void testZKOperationsAfterClientSaslAuthFailure() throws Exception {\n+        CountdownWatcher watcher = new CountdownWatcher();\n+        ZooKeeper zk = new ZooKeeper(hostPort, CONNECTION_TIMEOUT, watcher);\n+        watcher.waitForConnected(CONNECTION_TIMEOUT);\n+        try {\n+            setSaslFailureFlag(zk);\n+\n+            // try node creation for around 15 second,\n+            int totalTry = 10;\n+            int tryCount = 0;\n+\n+            boolean success = false;\n+            while (!success && tryCount++ <= totalTry) {\n+                try {\n+                    zk.create(\"/saslAuthFail\", \"data\".getBytes(), Ids.OPEN_ACL_UNSAFE,\n+                            CreateMode.PERSISTENT_SEQUENTIAL);\n+                    success = true;\n+                } catch (KeeperException.ConnectionLossException e) {\n+                    Thread.sleep(1000);\n+                    // do nothing\n+                }\n+            }\n+            assertTrue(\"ZNode creation is failing continusly after Sasl auth failure.\", success);\n+\n+        } finally {\n+            zk.close();\n+        }\n+    }\n+\n+    // set saslLoginFailed to true to simulate SASL login failure,\n+    // LoginException\n+    private void setSaslFailureFlag(ZooKeeper zk) throws Exception {","path":"src/java/test/org/apache/zookeeper/SaslAuthTest.java","position":175,"original_position":175,"commit_id":"9c43b5e10b2542b2c3571fdd18fa8d33db30f9b5","original_commit_id":"9c43b5e10b2542b2c3571fdd18fa8d33db30f9b5","user":{"login":"afine","id":223386,"avatar_url":"https://avatars0.githubusercontent.com/u/223386?v=3","gravatar_id":"","url":"https://api.github.com/users/afine","html_url":"https://github.com/afine","followers_url":"https://api.github.com/users/afine/followers","following_url":"https://api.github.com/users/afine/following{/other_user}","gists_url":"https://api.github.com/users/afine/gists{/gist_id}","starred_url":"https://api.github.com/users/afine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/afine/subscriptions","organizations_url":"https://api.github.com/users/afine/orgs","repos_url":"https://api.github.com/users/afine/repos","events_url":"https://api.github.com/users/afine/events{/privacy}","received_events_url":"https://api.github.com/users/afine/received_events","type":"User","site_admin":false},"body":"would it be possible to inject a mock ZooKeeperSaslClient for the test, it may be cleaner and more maintainable than reflection?","created_at":"2017-05-15T19:36:54Z","updated_at":"2017-05-15T19:37:08Z","html_url":"https://github.com/apache/zookeeper/pull/254#discussion_r116581847","pull_request_url":"https://api.github.com/repos/apache/zookeeper/pulls/254","_links":{"self":{"href":"https://api.github.com/repos/apache/zookeeper/pulls/comments/116581847"},"html":{"href":"https://github.com/apache/zookeeper/pull/254#discussion_r116581847"},"pull_request":{"href":"https://api.github.com/repos/apache/zookeeper/pulls/254"}}},"pull_request":{"url":"https://api.github.com/repos/apache/zookeeper/pulls/254","id":120622528,"html_url":"https://github.com/apache/zookeeper/pull/254","diff_url":"https://github.com/apache/zookeeper/pull/254.diff","patch_url":"https://github.com/apache/zookeeper/pull/254.patch","issue_url":"https://api.github.com/repos/apache/zookeeper/issues/254","number":254,"state":"open","locked":false,"title":"ZOOKEEPER-2775: ZK Client not able to connect with Xid out of order error","user":{"login":"arshadmohammad","id":5720433,"avatar_url":"https://avatars0.githubusercontent.com/u/5720433?v=3","gravatar_id":"","url":"https://api.github.com/users/arshadmohammad","html_url":"https://github.com/arshadmohammad","followers_url":"https://api.github.com/users/arshadmohammad/followers","following_url":"https://api.github.com/users/arshadmohammad/following{/other_user}","gists_url":"https://api.github.com/users/arshadmohammad/gists{/gist_id}","starred_url":"https://api.github.com/users/arshadmohammad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arshadmohammad/subscriptions","organizations_url":"https://api.github.com/users/arshadmohammad/orgs","repos_url":"https://api.github.com/users/arshadmohammad/repos","events_url":"https://api.github.com/users/arshadmohammad/events{/privacy}","received_events_url":"https://api.github.com/users/arshadmohammad/received_events","type":"User","site_admin":false},"body":"Once client enters into Xid out of order issue, It never comes to normal state. It keeps trying to connect and  fail with the same error.  Recreating/Restarting is the only solution as of now. This happens because of bug in the ZK client code. This MR provides the fix. ","created_at":"2017-05-15T15:00:24Z","updated_at":"2017-05-15T19:37:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b2a21ef18f94409bb6e2b66ac98a3c3d270eee01","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/zookeeper/pulls/254/commits","review_comments_url":"https://api.github.com/repos/apache/zookeeper/pulls/254/comments","review_comment_url":"https://api.github.com/repos/apache/zookeeper/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/zookeeper/issues/254/comments","statuses_url":"https://api.github.com/repos/apache/zookeeper/statuses/9c43b5e10b2542b2c3571fdd18fa8d33db30f9b5","head":{"label":"arshadmohammad:ZOOKEEPER-2775-XidOutOfOrder","ref":"ZOOKEEPER-2775-XidOutOfOrder","sha":"9c43b5e10b2542b2c3571fdd18fa8d33db30f9b5","user":{"login":"arshadmohammad","id":5720433,"avatar_url":"https://avatars0.githubusercontent.com/u/5720433?v=3","gravatar_id":"","url":"https://api.github.com/users/arshadmohammad","html_url":"https://github.com/arshadmohammad","followers_url":"https://api.github.com/users/arshadmohammad/followers","following_url":"https://api.github.com/users/arshadmohammad/following{/other_user}","gists_url":"https://api.github.com/users/arshadmohammad/gists{/gist_id}","starred_url":"https://api.github.com/users/arshadmohammad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arshadmohammad/subscriptions","organizations_url":"https://api.github.com/users/arshadmohammad/orgs","repos_url":"https://api.github.com/users/arshadmohammad/repos","events_url":"https://api.github.com/users/arshadmohammad/events{/privacy}","received_events_url":"https://api.github.com/users/arshadmohammad/received_events","type":"User","site_admin":false},"repo":{"id":74392683,"name":"zookeeper","full_name":"arshadmohammad/zookeeper","owner":{"login":"arshadmohammad","id":5720433,"avatar_url":"https://avatars0.githubusercontent.com/u/5720433?v=3","gravatar_id":"","url":"https://api.github.com/users/arshadmohammad","html_url":"https://github.com/arshadmohammad","followers_url":"https://api.github.com/users/arshadmohammad/followers","following_url":"https://api.github.com/users/arshadmohammad/following{/other_user}","gists_url":"https://api.github.com/users/arshadmohammad/gists{/gist_id}","starred_url":"https://api.github.com/users/arshadmohammad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arshadmohammad/subscriptions","organizations_url":"https://api.github.com/users/arshadmohammad/orgs","repos_url":"https://api.github.com/users/arshadmohammad/repos","events_url":"https://api.github.com/users/arshadmohammad/events{/privacy}","received_events_url":"https://api.github.com/users/arshadmohammad/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/arshadmohammad/zookeeper","description":"Mirror of Apache Hadoop ZooKeeper","fork":true,"url":"https://api.github.com/repos/arshadmohammad/zookeeper","forks_url":"https://api.github.com/repos/arshadmohammad/zookeeper/forks","keys_url":"https://api.github.com/repos/arshadmohammad/zookeeper/keys{/key_id}","collaborators_url":"https://api.github.com/repos/arshadmohammad/zookeeper/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/arshadmohammad/zookeeper/teams","hooks_url":"https://api.github.com/repos/arshadmohammad/zookeeper/hooks","issue_events_url":"https://api.github.com/repos/arshadmohammad/zookeeper/issues/events{/number}","events_url":"https://api.github.com/repos/arshadmohammad/zookeeper/events","assignees_url":"https://api.github.com/repos/arshadmohammad/zookeeper/assignees{/user}","branches_url":"https://api.github.com/repos/arshadmohammad/zookeeper/branches{/branch}","tags_url":"https://api.github.com/repos/arshadmohammad/zookeeper/tags","blobs_url":"https://api.github.com/repos/arshadmohammad/zookeeper/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/arshadmohammad/zookeeper/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/arshadmohammad/zookeeper/git/refs{/sha}","trees_url":"https://api.github.com/repos/arshadmohammad/zookeeper/git/trees{/sha}","statuses_url":"https://api.github.com/repos/arshadmohammad/zookeeper/statuses/{sha}","languages_url":"https://api.github.com/repos/arshadmohammad/zookeeper/languages","stargazers_url":"https://api.github.com/repos/arshadmohammad/zookeeper/stargazers","contributors_url":"https://api.github.com/repos/arshadmohammad/zookeeper/contributors","subscribers_url":"https://api.github.com/repos/arshadmohammad/zookeeper/subscribers","subscription_url":"https://api.github.com/repos/arshadmohammad/zookeeper/subscription","commits_url":"https://api.github.com/repos/arshadmohammad/zookeeper/commits{/sha}","git_commits_url":"https://api.github.com/repos/arshadmohammad/zookeeper/git/commits{/sha}","comments_url":"https://api.github.com/repos/arshadmohammad/zookeeper/comments{/number}","issue_comment_url":"https://api.github.com/repos/arshadmohammad/zookeeper/issues/comments{/number}","contents_url":"https://api.github.com/repos/arshadmohammad/zookeeper/contents/{+path}","compare_url":"https://api.github.com/repos/arshadmohammad/zookeeper/compare/{base}...{head}","merges_url":"https://api.github.com/repos/arshadmohammad/zookeeper/merges","archive_url":"https://api.github.com/repos/arshadmohammad/zookeeper/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/arshadmohammad/zookeeper/downloads","issues_url":"https://api.github.com/repos/arshadmohammad/zookeeper/issues{/number}","pulls_url":"https://api.github.com/repos/arshadmohammad/zookeeper/pulls{/number}","milestones_url":"https://api.github.com/repos/arshadmohammad/zookeeper/milestones{/number}","notifications_url":"https://api.github.com/repos/arshadmohammad/zookeeper/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/arshadmohammad/zookeeper/labels{/name}","releases_url":"https://api.github.com/repos/arshadmohammad/zookeeper/releases{/id}","deployments_url":"https://api.github.com/repos/arshadmohammad/zookeeper/deployments","created_at":"2016-11-21T18:20:45Z","updated_at":"2016-11-21T18:20:53Z","pushed_at":"2017-05-15T14:51:18Z","git_url":"git://github.com/arshadmohammad/zookeeper.git","ssh_url":"git@github.com:arshadmohammad/zookeeper.git","clone_url":"https://github.com/arshadmohammad/zookeeper.git","svn_url":"https://github.com/arshadmohammad/zookeeper","homepage":null,"size":28373,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"a680655a3569bfc546712cb85eeaea8c9b7de3ad","user":{"login":"apache","id":47359,"avatar_url":"https://avatars3.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":160999,"name":"zookeeper","full_name":"apache/zookeeper","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars3.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/zookeeper","description":"Mirror of Apache Hadoop ZooKeeper","fork":false,"url":"https://api.github.com/repos/apache/zookeeper","forks_url":"https://api.github.com/repos/apache/zookeeper/forks","keys_url":"https://api.github.com/repos/apache/zookeeper/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/zookeeper/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/zookeeper/teams","hooks_url":"https://api.github.com/repos/apache/zookeeper/hooks","issue_events_url":"https://api.github.com/repos/apache/zookeeper/issues/events{/number}","events_url":"https://api.github.com/repos/apache/zookeeper/events","assignees_url":"https://api.github.com/repos/apache/zookeeper/assignees{/user}","branches_url":"https://api.github.com/repos/apache/zookeeper/branches{/branch}","tags_url":"https://api.github.com/repos/apache/zookeeper/tags","blobs_url":"https://api.github.com/repos/apache/zookeeper/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/zookeeper/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/zookeeper/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/zookeeper/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/zookeeper/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/zookeeper/languages","stargazers_url":"https://api.github.com/repos/apache/zookeeper/stargazers","contributors_url":"https://api.github.com/repos/apache/zookeeper/contributors","subscribers_url":"https://api.github.com/repos/apache/zookeeper/subscribers","subscription_url":"https://api.github.com/repos/apache/zookeeper/subscription","commits_url":"https://api.github.com/repos/apache/zookeeper/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/zookeeper/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/zookeeper/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/zookeeper/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/zookeeper/contents/{+path}","compare_url":"https://api.github.com/repos/apache/zookeeper/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/zookeeper/merges","archive_url":"https://api.github.com/repos/apache/zookeeper/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/zookeeper/downloads","issues_url":"https://api.github.com/repos/apache/zookeeper/issues{/number}","pulls_url":"https://api.github.com/repos/apache/zookeeper/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/zookeeper/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/zookeeper/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/zookeeper/labels{/name}","releases_url":"https://api.github.com/repos/apache/zookeeper/releases{/id}","deployments_url":"https://api.github.com/repos/apache/zookeeper/deployments","created_at":"2009-03-27T15:41:56Z","updated_at":"2017-05-15T09:32:11Z","pushed_at":"2017-05-15T15:00:25Z","git_url":"git://github.com/apache/zookeeper.git","ssh_url":"git@github.com:apache/zookeeper.git","clone_url":"https://github.com/apache/zookeeper.git","svn_url":"https://github.com/apache/zookeeper","homepage":null,"size":28354,"stargazers_count":2887,"watchers_count":2887,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2091,"mirror_url":"git://git.apache.org/zookeeper.git","open_issues_count":93,"forks":2091,"open_issues":93,"watchers":2887,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/zookeeper/pulls/254"},"html":{"href":"https://github.com/apache/zookeeper/pull/254"},"issue":{"href":"https://api.github.com/repos/apache/zookeeper/issues/254"},"comments":{"href":"https://api.github.com/repos/apache/zookeeper/issues/254/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/zookeeper/pulls/254/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/zookeeper/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/zookeeper/pulls/254/commits"},"statuses":{"href":"https://api.github.com/repos/apache/zookeeper/statuses/9c43b5e10b2542b2c3571fdd18fa8d33db30f9b5"}}}}
{"actor":{"display_login":"afine"}}