### Question:
SecurityFilter implements Filter { @Override public void doFilter(ServletRequest serReq, ServletResponse serResp, FilterChain filtCh) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) serReq; String reqUrl = req.getRequestURL().toString(); LOG.debug("Filtering {} for security purposes", reqUrl); if (serReq.getLocalPort() != config.getTwoWayAuthPort()) { if (isRequestAllowed(reqUrl)) { filtCh.doFilter(serReq, serResp); } else { LOG.warn("This request is not allowed on this port: " + reqUrl); } } else { LOG.debug("Request can continue on secure port {}", serReq.getLocalPort()); filtCh.doFilter(serReq, serResp); } }  @Override void destroy(); @Override void doFilter(ServletRequest serReq, ServletResponse serResp,
		FilterChain filtCh); @Override void init(FilterConfig arg0); static void init(Configuration instance);  }### Answer:
@Test public void mustFilterNonHttpsRequests() throws Exception { SecurityFilter filter = new SecurityFilter(); MockHttpServletRequest request = this.getDefaultRequest(); request.setRequestURI("/certs/"); request.setScheme("http"); MockHttpServletResponse response = new MockHttpServletResponse(); request.setLocalPort(8440); MockFilterChain chain = new MockFilterChain(); filter.doFilter(request, response, chain); assertNull(chain.getRequest()); assertNull(chain.getResponse()); }
@Test public void mustAllowSecurePortRequests() throws Exception { SecurityFilter filter = new SecurityFilter(); MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = this.getDefaultRequest(); request.setServerPort(8441); request.setLocalPort(8441); request.setRequestURI("/certs/"); MockFilterChain chain = new MockFilterChain(); filter.doFilter(request, response, chain); assertEquals(request, chain.getRequest()); assertEquals(response, chain.getResponse()); }
@Test public void mustAllowCertCreationRequests() throws Exception { SecurityFilter filter = new SecurityFilter(); MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = this.getDefaultRequest(); request.setRequestURI("/certs/www.andromeda-01.com"); request.setMethod("POST"); MockFilterChain chain = new MockFilterChain(); filter.doFilter(request, response, chain); assertEquals(request, chain.getRequest()); assertEquals(response, chain.getResponse()); }
@Test public void mustAllowCertCaGetRequests() throws Exception { SecurityFilter filter = new SecurityFilter(); MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = this.getDefaultRequest(); request.setRequestURI("/cert/ca/"); MockFilterChain chain = new MockFilterChain(); filter.doFilter(request, response, chain); assertEquals(request, chain.getRequest()); assertEquals(response, chain.getResponse()); }