knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pzamp...@apache.org
Subject [1/4] knox git commit: KNOX-1385 - More inconsistent whitelist tests
Date Thu, 19 Jul 2018 19:14:03 GMT
Repository: knox
Updated Branches:
  refs/heads/master f92733c28 -> 529854861


KNOX-1385 - More inconsistent whitelist tests


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

Branch: refs/heads/master
Commit: ed24bcdb704f7be0b34424f87ceb5fdceca952dc
Parents: f92733c
Author: Phil Zampino <pzampino@apache.org>
Authored: Wed Jul 11 13:22:16 2018 -0400
Committer: Phil Zampino <pzampino@apache.org>
Committed: Wed Jul 11 13:22:16 2018 -0400

----------------------------------------------------------------------
 .../gateway/dispatch/GatewayDispatchFilterTest.java   | 10 ++++++++--
 .../apache/knox/gateway/util/WhitelistUtilsTest.java  | 14 ++++++++++----
 2 files changed, 18 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/ed24bcdb/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilterTest.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilterTest.java
b/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilterTest.java
index 02f6fa1..db08788 100644
--- a/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilterTest.java
+++ b/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilterTest.java
@@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.lang.reflect.Method;
+import java.net.InetAddress;
 import java.net.URLEncoder;
 import java.util.Arrays;
 import java.util.Collections;
@@ -136,7 +137,7 @@ public class GatewayDispatchFilterTest {
                                    null,
                                    serviceRole,
                                    "http://localhost:9999",
-                                   true);
+                                   shouldExpectLocalhost());
   }
 
   /**
@@ -151,7 +152,7 @@ public class GatewayDispatchFilterTest {
                                    null,
                                    serviceRole,
                                    URLEncoder.encode("http://localhost:9999", "UTF-8"),
-                                   true);
+                                   shouldExpectLocalhost());
   }
 
 
@@ -229,6 +230,11 @@ public class GatewayDispatchFilterTest {
   }
 
 
+  private static boolean shouldExpectLocalhost() throws Exception {
+    return InetAddress.getLocalHost().getCanonicalHostName().equalsIgnoreCase("localhost");
+  }
+
+
   private void doTestServiceDispatchWhitelist(List<String> whitelistedServices,
                                               String       whitelist,
                                               String       serviceRole,

http://git-wip-us.apache.org/repos/asf/knox/blob/ed24bcdb/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 7fce2cc..ddf62f2 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
@@ -24,11 +24,13 @@ import javax.annotation.RegEx;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import java.lang.reflect.Method;
+import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
@@ -63,12 +65,12 @@ public class WhitelistUtilsTest {
     // Check localhost by name
     String whitelist = doTestGetDispatchWhitelist(config, serviceRole);
     assertNotNull(whitelist);
-    assertTrue(whitelist.contains("localhost"));
+    assertEquals(shouldExpectLocalhost(), whitelist.contains("localhost"));
 
     // Check localhost by loopback address
     whitelist = doTestGetDispatchWhitelist(config, "127.0.0.1", serviceRole);
     assertNotNull(whitelist);
-    assertTrue(whitelist.contains("localhost"));
+    assertEquals(shouldExpectLocalhost(), whitelist.contains("localhost"));
   }
 
   @Test
@@ -141,8 +143,12 @@ public class WhitelistUtilsTest {
         doTestGetDispatchWhitelist(createMockGatewayConfig(Collections.singletonList(serviceRole),
WHITELIST),
                                    serviceRole);
     assertNotNull(whitelist);
-    assertTrue("Expected the derived localhost whitelist.",
-               RegExUtils.checkWhitelist(whitelist, "http://localhost:9099/"));
+    assertEquals(shouldExpectLocalhost(),
+                 RegExUtils.checkWhitelist(whitelist, "http://localhost:9099/"));
+  }
+
+  private static boolean shouldExpectLocalhost() throws Exception {
+    return InetAddress.getLocalHost().getCanonicalHostName().equalsIgnoreCase("localhost");
   }
 
   private String doTestGetDispatchWhitelist(GatewayConfig config, String serviceRole) {


Mime
View raw message