YARN-2547. Cross Origin Filter throws UnsupportedOperationException upon destroy (Mit Desai via jeagles)

This commit is contained in:
Jonathan Eagles 2014-09-12 15:35:17 -05:00
parent 3122daa802
commit 54e5794806
3 changed files with 58 additions and 6 deletions

View File

@ -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

View File

@ -150,8 +150,8 @@ private void initializeAllowedMethods(FilterConfig filterConfig) {
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 @@ private void initializeAllowedHeaders(FilterConfig filterConfig) {
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 @@ private void initializeAllowedOrigins(FilterConfig filterConfig) {
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);

View File

@ -217,6 +217,55 @@ public void testCrossOriginFilter() throws ServletException, IOException {
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;