CsrfTokenResponseHeaderFilter extends OncePerRequestFilter { @VisibleForTesting Map<String, List<String>> getCorsHeadersConfiguration() { Map<String, List<String>> corsConfiguration = new HashMap<>( 1 ); final List<String> exposedHeaders = Arrays.asList( RESPONSE_HEADER_NAME, RESPONSE_PARAM_NAME, RESPONSE_TOKEN_NAME ); corsConfiguration.put( CORS_EXPOSE_HEADERS_HEADER, exposedHeaders ); return corsConfiguration; }    }
@Test public void TestWhenCsrfTokenThenCorsResponseHeaders() throws Exception { MockFilterConfig cfg = new MockFilterConfig(); filter.init( cfg ); CsrfToken token = createToken(); when( this.mockRequest.getAttribute( REQUEST_ATTRIBUTE_NAME ) ).thenReturn( token ); Map<String, List<String>> configuration = Collections.emptyMap(); when( this.filter.getCorsHeadersConfiguration() ).thenReturn( configuration ); PowerMockito.mockStatic( WebUtil.class ); filter.doFilter( this.mockRequest, this.mockResponse, this.filterChain ); PowerMockito.verifyStatic( once() ); WebUtil.setCorsResponseHeaders( this.mockRequest, this.mockResponse, configuration ); }