knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pzamp...@apache.org
Subject [knox] branch master updated: KNOX-2127 - ZooKeeperAliasService mishandles mixed-case alias keys properly (#202)
Date Tue, 19 Nov 2019 01:55:17 GMT
This is an automated email from the ASF dual-hosted git repository.

pzampino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new 029c9b8  KNOX-2127 - ZooKeeperAliasService mishandles mixed-case alias keys properly
(#202)
029c9b8 is described below

commit 029c9b8d64605dd3d09ea22b0d2b7e6818f05300
Author: Phil Zampino <pzampino@apache.org>
AuthorDate: Mon Nov 18 20:55:10 2019 -0500

    KNOX-2127 - ZooKeeperAliasService mishandles mixed-case alias keys properly (#202)
---
 .../security/impl/ZookeeperRemoteAliasService.java     |  8 +++-----
 .../security/impl/ZookeeperRemoteAliasServiceTest.java | 18 +++++++++++-------
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/ZookeeperRemoteAliasService.java
b/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/ZookeeperRemoteAliasService.java
index f2327e8..cf096ac 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/ZookeeperRemoteAliasService.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/ZookeeperRemoteAliasService.java
@@ -102,7 +102,8 @@ public class ZookeeperRemoteAliasService implements AliasService {
    */
   private static String buildAliasEntryName(final String clusterName,
       final String alias) {
-    return buildClusterEntryName(clusterName) + PATH_SEPARATOR + alias;
+    // Convert all alias names to lower case (JDK-4891485)
+    return buildClusterEntryName(clusterName) + PATH_SEPARATOR + alias.toLowerCase(Locale.ROOT);
   }
 
   /**
@@ -228,10 +229,7 @@ public class ZookeeperRemoteAliasService implements AliasService {
 
   @Override
   public char[] getPasswordFromAliasForCluster(String clusterName,
-      String givenAlias, boolean generate) throws AliasServiceException {
-
-    /* convert all alias names to lower case since JDK expects the same behaviour */
-    final String alias = givenAlias.toLowerCase(Locale.ROOT);
+      String alias, boolean generate) throws AliasServiceException {
 
     char[] password = null;
 
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/services/security/impl/ZookeeperRemoteAliasServiceTest.java
b/gateway-server/src/test/java/org/apache/knox/gateway/services/security/impl/ZookeeperRemoteAliasServiceTest.java
index aeb6b1e..d49b0a1 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/services/security/impl/ZookeeperRemoteAliasServiceTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/services/security/impl/ZookeeperRemoteAliasServiceTest.java
@@ -36,6 +36,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 import static org.easymock.EasyMock.capture;
@@ -108,7 +109,7 @@ public class ZookeeperRemoteAliasServiceTest {
   @Test
   public void testAliasForCluster() throws Exception {
     final String expectedClusterName = "sandbox";
-    final String expectedAlias = "knox.test.alias";
+    final String expectedAlias = "knox.test.Alias";
     final String expectedPassword = "dummyPassword";
 
     final String expectedClusterNameDev = "development";
@@ -166,16 +167,19 @@ public class ZookeeperRemoteAliasServiceTest {
     Assert.assertEquals(aliases.size(), 1);
     Assert.assertEquals(aliasesDev.size(), 1);
 
-    Assert.assertTrue("Expected alias 'knox.test.alias' not found ",
-        aliases.contains(expectedAlias));
-    Assert.assertTrue("Expected alias 'knox.test.alias.dev' not found ",
+    Assert.assertTrue("Expected alias '" + expectedAlias + "' not found ",
+        aliases.contains(expectedAlias.toLowerCase(Locale.ROOT)));
+    Assert.assertTrue("Expected alias '" + expectedAliasDev + "' not found ",
         aliasesDev.contains(expectedAliasDev));
 
     final char[] result = zkAlias
         .getPasswordFromAliasForCluster(expectedClusterName, expectedAlias);
+    Assert.assertNotNull("Failed lookup for " + expectedAlias, result);
+
     final char[] result1 = zkAlias
         .getPasswordFromAliasForCluster(expectedClusterNameDev,
             expectedAliasDev);
+    Assert.assertNotNull("Failed lookup for " + expectedAliasDev, result1);
 
     Assert.assertEquals(expectedPassword, new String(result));
     Assert.assertEquals(expectedPasswordDev, new String(result1));
@@ -188,12 +192,12 @@ public class ZookeeperRemoteAliasServiceTest {
     aliasesDev = zkAlias.getAliasesForCluster(expectedClusterNameDev);
 
     Assert.assertEquals(aliasesDev.size(), 0);
-    Assert.assertFalse("Expected alias 'knox.test.alias.dev' to be removed but found.",
+    Assert.assertFalse("Expected alias '" + expectedAliasDev + "' to be removed but found.",
         aliasesDev.contains(expectedAliasDev));
 
     Assert.assertEquals(aliases.size(), 1);
-    Assert.assertTrue("Expected alias 'knox.test.alias' not found ",
-        aliases.contains(expectedAlias));
+    Assert.assertTrue("Expected alias '" + expectedAlias + "' not found ",
+        aliases.contains(expectedAlias.toLowerCase(Locale.ROOT)));
 
     /* Test auto-generate password for alias */
     final String testAutoGeneratedpasswordAlias = "knox.test.alias.auto";


Mime
View raw message