CrossOriginFilter implements Filter { static String encodeHeader(final String header) { if (header == null) { return null; } return header.split("\n|\r")[0].trim(); }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest req, ServletResponse res,
      FilterChain chain); @Override void destroy(); static final String ALLOWED_ORIGINS; static final String ALLOWED_ORIGINS_DEFAULT; static final String ALLOWED_METHODS; static final String ALLOWED_METHODS_DEFAULT; static final String ALLOWED_HEADERS; static final String ALLOWED_HEADERS_DEFAULT; static final String MAX_AGE; static final String MAX_AGE_DEFAULT; }
@Test public void testEncodeHeaders() { String validOrigin = "http: String encodedValidOrigin = CrossOriginFilter.encodeHeader(validOrigin); Assert.assertEquals("Valid origin encoding should match exactly", validOrigin, encodedValidOrigin); String httpResponseSplitOrigin = validOrigin + " \nSecondHeader: value"; String encodedResponseSplitOrigin = CrossOriginFilter.encodeHeader(httpResponseSplitOrigin); Assert.assertEquals("Http response split origin should be protected against", validOrigin, encodedResponseSplitOrigin); String validOriginList = "http: String encodedValidOriginList = CrossOriginFilter .encodeHeader(validOriginList); Assert.assertEquals("Valid origin list encoding should match exactly", validOriginList, encodedValidOriginList); }
@Test public void testEncodeHeaders() { String validOrigin = "http: String encodedValidOrigin = CrossOriginFilter.encodeHeader(validOrigin); Assert.assertEquals("Valid origin encoding should match exactly", validOrigin, encodedValidOrigin); String httpResponseSplitOrigin = validOrigin + " \nSecondHeader: value"; String encodedResponseSplitOrigin = CrossOriginFilter.encodeHeader(httpResponseSplitOrigin); Assert.assertEquals("Http response split origin should be protected against", validOrigin, encodedResponseSplitOrigin); String validOriginList = "http: String encodedValidOriginList = CrossOriginFilter.encodeHeader(validOriginList); Assert.assertEquals("Valid origin list encoding should match exactly", validOriginList, encodedValidOriginList); }