DomainValidateFilter implements Filter { @VisibleForTesting protected String removePortIfNeeded(String host) { return host.split("\\s*:\\s*")[0]; } 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 removePortIfNeeded() { String target = "10.2.1.1:8080"; Assert.assertEquals("10.2.1.1", filter.removePortIfNeeded(target)); target = "10.2.1.1"; Assert.assertEquals("10.2.1.1", filter.removePortIfNeeded(target)); target = "domain.name:8080"; Assert.assertEquals("domain.name", filter.removePortIfNeeded(target)); target = "domain.name"; Assert.assertEquals("domain.name", filter.removePortIfNeeded(target)); }