DomainValidateFilter implements Filter { @VisibleForTesting protected String removeProtocolIfNeeded(String urlStr) { if(urlStr.startsWith(HTTP_PROTOCOL_PREFIX)) { return urlStr.replace(HTTP_PROTOCOL_PREFIX, ""); } return urlStr; } DomainValidateFilter(BooleanSupplier shouldCheckConfig, Supplier<String> expectedDomainName); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain); @Override void destroy(); static final String STOP_CHECK_URI; static final String START_CHECK_URI; static final String HTTP_REQUEST_HEADER_HOST; static final int BAD_REQUEST_CODE; static final String BAD_REQUEST_MESSAGE_TEMPLATE; }
@Test public void removeProtocolIfNeeded() { String target = "http: Assert.assertEquals("10.2.1.1:8080", filter.removeProtocolIfNeeded(target)); }