You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by pz...@apache.org on 2018/06/28 21:00:20 UTC

knox git commit: KNOX-1369 - Default dispatch whitelist sometimes includes port information

Repository: knox
Updated Branches:
  refs/heads/master e4033958a -> c7a0a9931


KNOX-1369 - Default dispatch whitelist sometimes includes port information


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/c7a0a993
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/c7a0a993
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/c7a0a993

Branch: refs/heads/master
Commit: c7a0a99316b4a79bf3939bab627b793e15628a41
Parents: e403395
Author: Phil Zampino <pz...@apache.org>
Authored: Thu Jun 28 16:25:50 2018 -0400
Committer: Phil Zampino <pz...@apache.org>
Committed: Thu Jun 28 16:25:50 2018 -0400

----------------------------------------------------------------------
 .../apache/knox/gateway/util/WhitelistUtils.java    |  5 +++++
 .../knox/gateway/util/WhitelistUtilsTest.java       | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/c7a0a993/gateway-spi/src/main/java/org/apache/knox/gateway/util/WhitelistUtils.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/util/WhitelistUtils.java b/gateway-spi/src/main/java/org/apache/knox/gateway/util/WhitelistUtils.java
index 42e6eb2..e1f32be 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/util/WhitelistUtils.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/util/WhitelistUtils.java
@@ -76,6 +76,11 @@ public class WhitelistUtils {
       int domainIndex = thisHost.indexOf('.');
       if (domainIndex > 0) {
         String domain = thisHost.substring(thisHost.indexOf('.'));
+        // Sometimes, the server name includes port details, which need to be stripped
+        int portIndex = domain.indexOf(":");
+        if (portIndex > 0) {
+          domain = domain.substring(0, portIndex);
+        }
         String domainPattern = ".+" + domain.replaceAll("\\.", "\\\\.");
         defaultWhitelist = String.format(DEFAULT_DISPATCH_WHITELIST_TEMPLATE, domainPattern);
       }

http://git-wip-us.apache.org/repos/asf/knox/blob/c7a0a993/gateway-spi/src/test/java/org/apache/knox/gateway/util/WhitelistUtilsTest.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/test/java/org/apache/knox/gateway/util/WhitelistUtilsTest.java b/gateway-spi/src/test/java/org/apache/knox/gateway/util/WhitelistUtilsTest.java
index 172979a..34a1c6c 100644
--- a/gateway-spi/src/test/java/org/apache/knox/gateway/util/WhitelistUtilsTest.java
+++ b/gateway-spi/src/test/java/org/apache/knox/gateway/util/WhitelistUtilsTest.java
@@ -25,6 +25,7 @@ import javax.servlet.http.HttpServletRequest;
 import java.util.Collections;
 import java.util.List;
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -64,6 +65,21 @@ public class WhitelistUtilsTest {
     assertTrue(whitelist.contains("localhost"));
   }
 
+  /**
+   * KNOX-1369
+   */
+  @Test
+  public void testDomainBasedDefaultForAffectedServiceRoleWhenServerNameIncludesPort() throws Exception {
+    final String serviceRole = "TEST";
+
+    GatewayConfig config = createMockGatewayConfig(Collections.singletonList(serviceRole), null);
+
+    // Check localhost by loopback address
+    String whitelist = doTestGetDispatchWhitelist(config, "host.test.com:1234", serviceRole);
+    assertNotNull(whitelist);
+    assertTrue(whitelist.contains(".+\\.test\\.com"));
+    assertFalse(whitelist.contains(":1234"));
+  }
 
   @Test
   public void testDefaultDomainWhitelist() throws Exception {