|
@@ -243,6 +243,31 @@ public class TestHostRestrictingAuthorizationFilter {
|
|
filter.destroy();
|
|
filter.destroy();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Test acceptable behavior to malformed requests
|
|
|
|
+ * Case: the request URI does not start with "/webhdfs/v1"
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testInvalidURI() throws Exception {
|
|
|
|
+ HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
|
|
|
|
+ Mockito.when(request.getMethod()).thenReturn("GET");
|
|
|
|
+ Mockito.when(request.getRequestURI()).thenReturn("/InvalidURI");
|
|
|
|
+ HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
|
|
|
|
+
|
|
|
|
+ Filter filter = new HostRestrictingAuthorizationFilter();
|
|
|
|
+ HashMap<String, String> configs = new HashMap<String, String>() {};
|
|
|
|
+ configs.put(AuthenticationFilter.AUTH_TYPE, "simple");
|
|
|
|
+ FilterConfig fc = new DummyFilterConfig(configs);
|
|
|
|
+
|
|
|
|
+ filter.init(fc);
|
|
|
|
+ filter.doFilter(request, response,
|
|
|
|
+ (servletRequest, servletResponse) -> {});
|
|
|
|
+ Mockito.verify(response, Mockito.times(1))
|
|
|
|
+ .sendError(Mockito.eq(HttpServletResponse.SC_NOT_FOUND),
|
|
|
|
+ Mockito.anyString());
|
|
|
|
+ filter.destroy();
|
|
|
|
+ }
|
|
|
|
+
|
|
private static class DummyFilterConfig implements FilterConfig {
|
|
private static class DummyFilterConfig implements FilterConfig {
|
|
final Map<String, String> map;
|
|
final Map<String, String> map;
|
|
|
|
|