### Question:
FalconAuthenticationFilter extends org.apache.hadoop.security.authentication.server.AuthenticationFilter { @Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain filterChain) throws IOException, ServletException { FilterChain filterChainWrapper = new FilterChain() { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) servletRequest; if (httpRequest.getMethod().equals("OPTIONS")) { optionsServlet.service(request, response); } else { final String user = Servlets.getUserFromRequest(httpRequest); if (StringUtils.isEmpty(user)) { ((HttpServletResponse) response).sendError(Response.Status.BAD_REQUEST.getStatusCode(), "Param user.name can't be empty"); } else if (blackListedUsers.contains(user)) { ((HttpServletResponse) response).sendError(Response.Status.BAD_REQUEST.getStatusCode(), "User can't be a superuser:" + BLACK_LISTED_USERS_KEY); } else { try { NDC.push(user + ":" + httpRequest.getMethod() + "/" + httpRequest.getPathInfo()); String doAsUser = httpRequest.getParameter(DO_AS_PARAM); CurrentUser.authenticate(user); CurrentUser.proxyDoAsUser(doAsUser, HostnameFilter.get()); LOG.info("Request from authenticated user: {}, URL={}, doAs user: {}", user, Servlets.getRequestURI(httpRequest), doAsUser); filterChain.doFilter(servletRequest, servletResponse); } finally { NDC.pop(); } } } } }; super.doFilter(request, response, filterChainWrapper); }  @Override void init(FilterConfig filterConfig); @Override void doFilter(final ServletRequest request, final ServletResponse response,
                         final FilterChain filterChain); @Override void destroy();  }### Answer:
@Test public void testDoFilter() throws Exception { Filter filter = new FalconAuthenticationFilter(); synchronized (StartupProperties.get()) { filter.init(mockConfig); } CurrentUser.authenticate("nouser"); Assert.assertEquals(CurrentUser.getUser(), "nouser"); CurrentUser.authenticate("guest"); Mockito.when(mockRequest.getQueryString()).thenReturn("user.name=guest"); filter.doFilter(mockRequest, mockResponse, mockChain); Assert.assertEquals(CurrentUser.getUser(), "guest"); CurrentUser.authenticate("nouser"); Assert.assertEquals(CurrentUser.getUser(), "nouser"); CurrentUser.authenticate(FalconTestUtil.TEST_USER_2); Mockito.when(mockRequest.getRemoteUser()).thenReturn(FalconTestUtil.TEST_USER_2); filter.doFilter(mockRequest, mockResponse, mockChain); Assert.assertEquals(CurrentUser.getUser(), FalconTestUtil.TEST_USER_2); }