KNOX-1385 - Inconsistent WebSSOResourceTest whitelist tests
diff --git a/gateway-service-knoxsso/src/test/java/org/apache/knox/gateway/service/knoxsso/WebSSOResourceTest.java b/gateway-service-knoxsso/src/test/java/org/apache/knox/gateway/service/knoxsso/WebSSOResourceTest.java
index 28643e5..3e8acd4 100644
--- a/gateway-service-knoxsso/src/test/java/org/apache/knox/gateway/service/knoxsso/WebSSOResourceTest.java
+++ b/gateway-service-knoxsso/src/test/java/org/apache/knox/gateway/service/knoxsso/WebSSOResourceTest.java
@@ -579,77 +579,6 @@
}
@Test
- public void testDefaultWhitelistLocalhostByAddress() throws Exception {
- doTestDefaultLocalhostWhitelist("127.0.0.1");
- }
-
- @Test
- public void testDefaultWhitelistLocalhostByName() throws Exception {
- doTestDefaultLocalhostWhitelist("localhost");
- }
-
- private void doTestDefaultLocalhostWhitelist(String localhostId) throws Exception {
- String whitelistValue = doTestDefaultWhitelist(localhostId);
- assertTrue(whitelistValue.contains("localhost"));
- }
-
- private String doTestDefaultWhitelist(String hostname) throws Exception {
- final String testServiceRole = "TEST";
-
- GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class);
- EasyMock.expect(config.getDispatchWhitelistServices()).andReturn(Collections.singletonList(testServiceRole)).anyTimes();
- EasyMock.expect(config.getDispatchWhitelist()).andReturn(null).anyTimes();
- EasyMock.replay(config);
-
- ServletContext context = EasyMock.createNiceMock(ServletContext.class);
- EasyMock.expect(context.getInitParameter("knoxsso.cookie.name")).andReturn(null);
- EasyMock.expect(context.getInitParameter("knoxsso.cookie.secure.only")).andReturn(null);
- EasyMock.expect(context.getInitParameter("knoxsso.cookie.max.age")).andReturn(null);
- EasyMock.expect(context.getInitParameter("knoxsso.cookie.domain.suffix")).andReturn(null);
- EasyMock.expect(context.getInitParameter("knoxsso.redirect.whitelist.regex")).andReturn(null);
- EasyMock.expect(context.getInitParameter("knoxsso.token.audiences")).andReturn(null);
- EasyMock.expect(context.getInitParameter("knoxsso.token.ttl")).andReturn("60000");
- EasyMock.expect(context.getInitParameter("knoxsso.enable.session")).andReturn(null);
- EasyMock.expect(context.getAttribute("org.apache.knox.gateway.config")).andReturn(config).anyTimes();
-
- HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
- EasyMock.expect(request.getParameter("originalUrl")).andReturn("http://localhost:9080/service");
- EasyMock.expect(request.getParameterMap()).andReturn(Collections.<String,String[]>emptyMap());
- EasyMock.expect(request.getServletContext()).andReturn(context).anyTimes();
- EasyMock.expect(request.getAttribute("targetServiceRole")).andReturn(testServiceRole).anyTimes();
- EasyMock.expect(request.getServerName()).andReturn(hostname).anyTimes();
-
- Principal principal = EasyMock.createNiceMock(Principal.class);
- EasyMock.expect(principal.getName()).andReturn("alice").anyTimes();
- EasyMock.expect(request.getUserPrincipal()).andReturn(principal).anyTimes();
-
- GatewayServices services = EasyMock.createNiceMock(GatewayServices.class);
- EasyMock.expect(context.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE)).andReturn(services);
-
- JWTokenAuthority authority = new TestJWTokenAuthority(publicKey, privateKey);
- EasyMock.expect(services.getService(GatewayServices.TOKEN_SERVICE)).andReturn(authority);
-
- HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
- ServletOutputStream outputStream = EasyMock.createNiceMock(ServletOutputStream.class);
- CookieResponseWrapper responseWrapper = new CookieResponseWrapper(response, outputStream);
-
- EasyMock.replay(principal, services, context, request);
-
- WebSSOResource webSSOResponse = new WebSSOResource();
- webSSOResponse.request = request;
- webSSOResponse.response = responseWrapper;
- webSSOResponse.context = context;
- webSSOResponse.init();
-
- Field whitelistField = webSSOResponse.getClass().getDeclaredField("whitelist");
- whitelistField.setAccessible(true);
- String whitelistValue = (String) whitelistField.get(webSSOResponse);
- assertNotNull(whitelistValue);
-
- return whitelistValue;
- }
-
- @Test
public void testWhitelistValidationWithEncodedOriginalURL() throws Exception {
GatewayConfig config = EasyMock.createNiceMock(GatewayConfig.class);
EasyMock.expect(config.getDispatchWhitelistServices()).andReturn(Collections.emptyList()).anyTimes();