Java Code Examples for org.eclipse.jetty.servlet.FilterHolder#initialize()
The following examples show how to use
org.eclipse.jetty.servlet.FilterHolder#initialize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HTTPHeaderFiltersTest.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testCSPHeaderApplied() throws ServletException, IOException, Exception { // Arrange FilterHolder originFilter = new FilterHolder(new ContentSecurityPolicyFilter()); // Set up request HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); MockHttpServletResponse mockResponse = new MockHttpServletResponse(); FilterChain mockFilterChain = Mockito.mock(FilterChain.class); // Action originFilter.start(); originFilter.initialize(); originFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain); // Verify assertEquals("frame-ancestors 'self'", mockResponse.getHeader("Content-Security-Policy")); }
Example 2
Source File: HTTPHeaderFiltersTest.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testCSPHeaderAppliedOnlyOnce() throws ServletException, IOException, Exception { // Arrange FilterHolder originFilter = new FilterHolder(new ContentSecurityPolicyFilter()); // Set up request HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); MockHttpServletResponse mockResponse = new MockHttpServletResponse(); FilterChain mockFilterChain = Mockito.mock(FilterChain.class); // Action originFilter.start(); originFilter.initialize(); originFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain); originFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain); // Verify assertEquals("frame-ancestors 'self'", mockResponse.getHeader("Content-Security-Policy")); }
Example 3
Source File: HTTPHeaderFiltersTest.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testXFrameOptionsHeaderApplied() throws ServletException, IOException, Exception { // Arrange FilterHolder xfoFilter = new FilterHolder(new XFrameOptionsFilter()); // Set up request HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); MockHttpServletResponse mockResponse = new MockHttpServletResponse(); FilterChain mockFilterChain = Mockito.mock(FilterChain.class); // Action xfoFilter.start(); xfoFilter.initialize(); xfoFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain); // Verify assertEquals("SAMEORIGIN", mockResponse.getHeader("X-Frame-Options")); }
Example 4
Source File: HTTPHeaderFiltersTest.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testHSTSHeaderApplied() throws ServletException, IOException, Exception { // Arrange FilterHolder hstsFilter = new FilterHolder(new StrictTransportSecurityFilter()); // Set up request HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); MockHttpServletResponse mockResponse = new MockHttpServletResponse(); FilterChain mockFilterChain = Mockito.mock(FilterChain.class); // Action hstsFilter.start(); hstsFilter.initialize(); hstsFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain); // Verify assertEquals("max-age=31540000", mockResponse.getHeader("Strict-Transport-Security")); }
Example 5
Source File: HTTPHeaderFiltersTest.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testXSSProtectionHeaderApplied() throws ServletException, IOException, Exception { // Arrange FilterHolder xssFilter = new FilterHolder(new XSSProtectionFilter()); // Set up request HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); MockHttpServletResponse mockResponse = new MockHttpServletResponse(); FilterChain mockFilterChain = Mockito.mock(FilterChain.class); // Action xssFilter.start(); xssFilter.initialize(); xssFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain); // Verify assertEquals("1; mode=block", mockResponse.getHeader("X-XSS-Protection")); }
Example 6
Source File: HTTPHeaderFiltersTest.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testXContentTypeOptionsHeaderApplied() throws Exception { // Arrange FilterHolder xssFilter = new FilterHolder(new XContentTypeOptionsFilter()); HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); MockHttpServletResponse mockResponse = new MockHttpServletResponse(); FilterChain mockFilterChain = Mockito.mock(FilterChain.class); // Action xssFilter.start(); xssFilter.initialize(); xssFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain); // Verify assertEquals("nosniff", mockResponse.getHeader("X-Content-Type-Options")); }