DashboardRedirectionFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; if (("GET".equals(req.getMethod()) || "HEAD".equals(req.getMethod())) && !EXCLUDES.matcher(req.getRequestURI()).matches()) { resp.sendRedirect("/dashboard/"); return; } chain.doFilter(request, response); }  @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void init(FilterConfig filterConfig); @Override void destroy();  }
@Test(dataProvider = "nonNamespacePathProvider") public void shouldRedirectIfGetRequestIsNotNamespaceWorkspaceName(String uri) throws Exception { when(request.getMethod()).thenReturn("GET"); when(request.getRequestURI()).thenReturn(uri); EnvironmentContext context = new EnvironmentContext(); context.setSubject(new SubjectImpl("id123", "name", "token123", false)); EnvironmentContext.setCurrent(context); filter.doFilter(request, response, chain); verify(response).sendRedirect(eq("/dashboard/")); }
@Test(dataProvider = "nonNamespacePathProvider") public void shouldRedirectIfHEADRequestIsNotNamespaceWorkspaceName(String uri) throws Exception { when(request.getMethod()).thenReturn("HEAD"); when(request.getRequestURI()).thenReturn(uri); EnvironmentContext context = new EnvironmentContext(); context.setSubject(new SubjectImpl("id123", "name", "token123", false)); EnvironmentContext.setCurrent(context); filter.doFilter(request, response, chain); verify(response).sendRedirect(eq("/dashboard/")); }
@Test public void shouldSkipRequestToAppResources() throws Exception { when(request.getMethod()).thenReturn("GET"); when(request.getRequestURI()).thenReturn("/_app/loader.html"); filter.doFilter(request, response, chain); verify(chain).doFilter(any(ServletRequest.class), any(ServletResponse.class)); }
@Test(dataProvider = "notGETNorHEADMethodProvider") public void shouldSkipNotGETNorHEADRequest(String method) throws Exception { when(request.getMethod()).thenReturn(method); when(request.getRequestURI()).thenReturn("/namespace/workspaceName"); filter.doFilter(request, response, chain); verify(chain).doFilter(any(ServletRequest.class), any(ServletResponse.class)); }