YARN-2547. Cross Origin Filter throws UnsupportedOperationException upon destroy (Mit Desai via jeagles)
(cherry picked from commit 54e5794806
)
This commit is contained in:
parent
f21a5236e5
commit
546a708acc
|
@ -188,6 +188,9 @@ Release 2.6.0 - UNRELEASED
|
||||||
YARN-2229. Changed the integer field of ContainerId to be long type.
|
YARN-2229. Changed the integer field of ContainerId to be long type.
|
||||||
(Tsuyoshi OZAWA via jianhe)
|
(Tsuyoshi OZAWA via jianhe)
|
||||||
|
|
||||||
|
YARN-2547. Cross Origin Filter throws UnsupportedOperationException upon
|
||||||
|
destroy (Mit Desai via jeagles)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
|
@ -150,8 +150,8 @@ public class CrossOriginFilter implements Filter {
|
||||||
if (allowedMethodsConfig == null) {
|
if (allowedMethodsConfig == null) {
|
||||||
allowedMethodsConfig = ALLOWED_METHODS_DEFAULT;
|
allowedMethodsConfig = ALLOWED_METHODS_DEFAULT;
|
||||||
}
|
}
|
||||||
allowedMethods =
|
allowedMethods.addAll(
|
||||||
Arrays.asList(allowedMethodsConfig.trim().split("\\s*,\\s*"));
|
Arrays.asList(allowedMethodsConfig.trim().split("\\s*,\\s*")));
|
||||||
LOG.info("Allowed Methods: " + getAllowedMethodsHeader());
|
LOG.info("Allowed Methods: " + getAllowedMethodsHeader());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,8 +161,8 @@ public class CrossOriginFilter implements Filter {
|
||||||
if (allowedHeadersConfig == null) {
|
if (allowedHeadersConfig == null) {
|
||||||
allowedHeadersConfig = ALLOWED_HEADERS_DEFAULT;
|
allowedHeadersConfig = ALLOWED_HEADERS_DEFAULT;
|
||||||
}
|
}
|
||||||
allowedHeaders =
|
allowedHeaders.addAll(
|
||||||
Arrays.asList(allowedHeadersConfig.trim().split("\\s*,\\s*"));
|
Arrays.asList(allowedHeadersConfig.trim().split("\\s*,\\s*")));
|
||||||
LOG.info("Allowed Headers: " + getAllowedHeadersHeader());
|
LOG.info("Allowed Headers: " + getAllowedHeadersHeader());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,8 +172,8 @@ public class CrossOriginFilter implements Filter {
|
||||||
if (allowedOriginsConfig == null) {
|
if (allowedOriginsConfig == null) {
|
||||||
allowedOriginsConfig = ALLOWED_ORIGINS_DEFAULT;
|
allowedOriginsConfig = ALLOWED_ORIGINS_DEFAULT;
|
||||||
}
|
}
|
||||||
allowedOrigins =
|
allowedOrigins.addAll(
|
||||||
Arrays.asList(allowedOriginsConfig.trim().split("\\s*,\\s*"));
|
Arrays.asList(allowedOriginsConfig.trim().split("\\s*,\\s*")));
|
||||||
allowAllOrigins = allowedOrigins.contains("*");
|
allowAllOrigins = allowedOrigins.contains("*");
|
||||||
LOG.info("Allowed Origins: " + StringUtils.join(allowedOrigins, ','));
|
LOG.info("Allowed Origins: " + StringUtils.join(allowedOrigins, ','));
|
||||||
LOG.info("Allow All Origins: " + allowAllOrigins);
|
LOG.info("Allow All Origins: " + allowAllOrigins);
|
||||||
|
|
|
@ -217,6 +217,55 @@ public class TestCrossOriginFilter {
|
||||||
verify(mockChain).doFilter(mockReq, mockRes);
|
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 {
|
private static class FilterConfigTest implements FilterConfig {
|
||||||
|
|
||||||
final Map<String, String> map;
|
final Map<String, String> map;
|
||||||
|
|
Loading…
Reference in New Issue