### Question:
CloudflareAccessService { public void processLogoutRequest(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { if(isRequestFilteringDisabled()) { log.debug("Plugin filters are disabled or no configured yet, bypassing logout redirect"); chain.doFilter(request, response); return; } if(isAtlassianFlowEnabled(request)) { log.debug("Atlassian flow is enabled, bypassing"); chain.doFilter(request, response); return; } if(new CloudflareToken(request).isNotPresent()) { log.debug("No token present, bypassing logout redirect"); chain.doFilter(request, response); return; } clearSession(request); AuthenticationContext authContext = getAuthContext(); log.debug("Redirecting user to cloudflare logout at " + authContext.getLogoutUrl()); response.sendRedirect(authContext.getLogoutUrl()); } @Autowired  CloudflareAccessService(@ComponentImport PluginAccessor pluginAcessor,
									CloudflarePluginDetails pluginDetails,
									ConfigurationService configurationService,
									AtlassianUserService userService,
									SuccessfulAuthenticationRequestHandler successHandler,
									FailedAuthenticationRequestHandler failureHandler,
									Environment env,
									PluginStateService pluginStateService); void processAuthRequest(HttpServletRequest request, HttpServletResponse response, FilterChain chain); void processLogoutRequest(HttpServletRequest request, HttpServletResponse response, FilterChain chain);  }### Answer:
@Test public void testLogout() throws IOException, ServletException { HttpServletRequest httpRequest = mock(HttpServletRequest.class); HttpServletResponse httpResponse = mock(HttpServletResponse.class); FilterChain chain = mock(FilterChain.class); HttpSession httpSession = mock(HttpSession.class); when(httpRequest.getHeader(CloudflareToken.CF_ACCESS_JWT_HEADER)).thenReturn(authContext.getValidToken()); when(httpRequest.getCookies()).thenReturn(new Cookie[] { newCookie("seraph.whatever", "test", 999999), newCookie("JSESSIONID", "test", 999999), }); when(httpRequest.getSession()).thenReturn(httpSession); when(httpRequest.getSession(false)).thenReturn(httpSession); when(httpRequest.getServerName()).thenReturn("example.com"); CloudflareAccessService cloudflareAccessService = newCloudflareAccessServiceInstance(); cloudflareAccessService.processLogoutRequest(httpRequest, httpResponse, chain); verify(httpResponse, times(1)).sendRedirect(authContext.getLogoutUrl()); verify(httpSession, times(1)).invalidate(); }
@Test public void testLogoutWithoutToken() throws IOException, ServletException { HttpServletRequest httpRequest = mock(HttpServletRequest.class); HttpServletResponse httpResponse = mock(HttpServletResponse.class); FilterChain chain = mock(FilterChain.class); HttpSession httpSession = mock(HttpSession.class); when(httpRequest.getCookies()).thenReturn(new Cookie[] { newCookie("seraph.whatever", "test", 999999), newCookie("JSESSIONID", "test", 999999), }); when(httpRequest.getSession()).thenReturn(httpSession); when(httpRequest.getSession(false)).thenReturn(httpSession); when(httpRequest.getServerName()).thenReturn("example.com"); CloudflareAccessService cloudflareAccessService = newCloudflareAccessServiceInstance(); cloudflareAccessService.processLogoutRequest(httpRequest, httpResponse, chain); verify(httpResponse, times(0)).sendRedirect(authContext.getLogoutUrl()); verify(httpSession, times(0)).invalidate(); verify(chain, times(1)).doFilter(httpRequest, httpResponse); }