YARN-2547. Cross Origin Filter throws UnsupportedOperationException upon destroy (Mit Desai via jeagles)
This commit is contained in:
parent
3122daa802
commit
54e5794806
|
@ -214,6 +214,9 @@ Release 2.6.0 - UNRELEASED
|
|||
YARN-2229. Changed the integer field of ContainerId to be long type.
|
||||
(Tsuyoshi OZAWA via jianhe)
|
||||
|
||||
YARN-2547. Cross Origin Filter throws UnsupportedOperationException upon
|
||||
destroy (Mit Desai via jeagles)
|
||||
|
||||
OPTIMIZATIONS
|
||||
|
||||
BUG FIXES
|
||||
|
|
|
@ -150,8 +150,8 @@ public class CrossOriginFilter implements Filter {
|
|||
if (allowedMethodsConfig == null) {
|
||||
allowedMethodsConfig = ALLOWED_METHODS_DEFAULT;
|
||||
}
|
||||
allowedMethods =
|
||||
Arrays.asList(allowedMethodsConfig.trim().split("\\s*,\\s*"));
|
||||
allowedMethods.addAll(
|
||||
Arrays.asList(allowedMethodsConfig.trim().split("\\s*,\\s*")));
|
||||
LOG.info("Allowed Methods: " + getAllowedMethodsHeader());
|
||||
}
|
||||
|
||||
|
@ -161,8 +161,8 @@ public class CrossOriginFilter implements Filter {
|
|||
if (allowedHeadersConfig == null) {
|
||||
allowedHeadersConfig = ALLOWED_HEADERS_DEFAULT;
|
||||
}
|
||||
allowedHeaders =
|
||||
Arrays.asList(allowedHeadersConfig.trim().split("\\s*,\\s*"));
|
||||
allowedHeaders.addAll(
|
||||
Arrays.asList(allowedHeadersConfig.trim().split("\\s*,\\s*")));
|
||||
LOG.info("Allowed Headers: " + getAllowedHeadersHeader());
|
||||
}
|
||||
|
||||
|
@ -172,8 +172,8 @@ public class CrossOriginFilter implements Filter {
|
|||
if (allowedOriginsConfig == null) {
|
||||
allowedOriginsConfig = ALLOWED_ORIGINS_DEFAULT;
|
||||
}
|
||||
allowedOrigins =
|
||||
Arrays.asList(allowedOriginsConfig.trim().split("\\s*,\\s*"));
|
||||
allowedOrigins.addAll(
|
||||
Arrays.asList(allowedOriginsConfig.trim().split("\\s*,\\s*")));
|
||||
allowAllOrigins = allowedOrigins.contains("*");
|
||||
LOG.info("Allowed Origins: " + StringUtils.join(allowedOrigins, ','));
|
||||
LOG.info("Allow All Origins: " + allowAllOrigins);
|
||||
|
|
|
@ -217,6 +217,55 @@ public class TestCrossOriginFilter {
|
|||
verify(mockChain).doFilter(mockReq, mockRes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCrossOriginFilterAfterRestart() throws ServletException {
|
||||
|
||||
// Setup the configuration settings of the server
|
||||
Map<String, String> conf = new HashMap<String, String>();
|
||||
conf.put(CrossOriginFilter.ALLOWED_ORIGINS, "example.com");
|
||||
conf.put(CrossOriginFilter.ALLOWED_HEADERS, "X-Requested-With,Accept");
|
||||
conf.put(CrossOriginFilter.ALLOWED_METHODS, "GET,POST");
|
||||
FilterConfig filterConfig = new FilterConfigTest(conf);
|
||||
|
||||
// Object under test
|
||||
CrossOriginFilter filter = new CrossOriginFilter();
|
||||
filter.init(filterConfig);
|
||||
|
||||
//verify filter values
|
||||
Assert.assertTrue("Allowed headers do not match",
|
||||
filter.getAllowedHeadersHeader()
|
||||
.compareTo("X-Requested-With,Accept") == 0);
|
||||
Assert.assertTrue("Allowed methods do not match",
|
||||
filter.getAllowedMethodsHeader()
|
||||
.compareTo("GET,POST") == 0);
|
||||
Assert.assertTrue(filter.isOriginAllowed("example.com"));
|
||||
|
||||
//destroy filter values and clear conf
|
||||
filter.destroy();
|
||||
conf.clear();
|
||||
|
||||
// Setup the configuration settings of the server
|
||||
conf.put(CrossOriginFilter.ALLOWED_ORIGINS, "newexample.com");
|
||||
conf.put(CrossOriginFilter.ALLOWED_HEADERS, "Content-Type,Origin");
|
||||
conf.put(CrossOriginFilter.ALLOWED_METHODS, "GET,HEAD");
|
||||
filterConfig = new FilterConfigTest(conf);
|
||||
|
||||
//initialize filter
|
||||
filter.init(filterConfig);
|
||||
|
||||
//verify filter values
|
||||
Assert.assertTrue("Allowed headers do not match",
|
||||
filter.getAllowedHeadersHeader()
|
||||
.compareTo("Content-Type,Origin") == 0);
|
||||
Assert.assertTrue("Allowed methods do not match",
|
||||
filter.getAllowedMethodsHeader()
|
||||
.compareTo("GET,HEAD") == 0);
|
||||
Assert.assertTrue(filter.isOriginAllowed("newexample.com"));
|
||||
|
||||
//destroy filter values
|
||||
filter.destroy();
|
||||
}
|
||||
|
||||
private static class FilterConfigTest implements FilterConfig {
|
||||
|
||||
final Map<String, String> map;
|
||||
|
|
Loading…
Reference in New Issue