Repository: knox Updated Branches: refs/heads/v1.1.0 14204cc2a -> 6357869d5
KNOX-1385 - Inconsistent WebSSOResourceTest whitelist tests Project: http://git-wip-us.apache.org/repos/asf/knox/repo Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/6357869d Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/6357869d Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/6357869d Branch: refs/heads/v1.1.0 Commit: 6357869d5d55364a667fe709f798bd76ac2fe917 Parents: 14204cc Author: Phil Zampino <[email protected]> Authored: Wed Jul 11 12:22:52 2018 -0400 Committer: Phil Zampino <[email protected]> Committed: Wed Jul 11 12:22:52 2018 -0400 ---------------------------------------------------------------------- .../service/knoxsso/WebSSOResourceTest.java | 71 -------------------- 1 file changed, 71 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/knox/blob/6357869d/gateway-service-knoxsso/src/test/java/org/apache/knox/gateway/service/knoxsso/WebSSOResourceTest.java ---------------------------------------------------------------------- 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 @@ public class WebSSOResourceTest { } @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();
