mirror of https://github.com/apache/nifi.git
NIFI-7993 - Upgraded Jetty dependency and fixed a minor issue with Jetty security filter tests.
Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com> This closes #4658.
This commit is contained in:
parent
c79ad1502e
commit
8a4079cd78
|
@ -18,6 +18,7 @@ package org.apache.nifi.web.security.headers;
|
||||||
|
|
||||||
import org.apache.nifi.web.security.headers.ContentSecurityPolicyFilter;
|
import org.apache.nifi.web.security.headers.ContentSecurityPolicyFilter;
|
||||||
import org.eclipse.jetty.servlet.FilterHolder;
|
import org.eclipse.jetty.servlet.FilterHolder;
|
||||||
|
import org.eclipse.jetty.servlet.ServletHandler;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
|
@ -35,7 +36,7 @@ public class HTTPHeaderFiltersTest {
|
||||||
public void testCSPHeaderApplied() throws ServletException, IOException, Exception {
|
public void testCSPHeaderApplied() throws ServletException, IOException, Exception {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
FilterHolder originFilter = new FilterHolder(new ContentSecurityPolicyFilter());
|
FilterHolder cspFilter = new FilterHolder(new ContentSecurityPolicyFilter());
|
||||||
|
|
||||||
// Set up request
|
// Set up request
|
||||||
HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class);
|
HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class);
|
||||||
|
@ -43,9 +44,10 @@ public class HTTPHeaderFiltersTest {
|
||||||
FilterChain mockFilterChain = Mockito.mock(FilterChain.class);
|
FilterChain mockFilterChain = Mockito.mock(FilterChain.class);
|
||||||
|
|
||||||
// Action
|
// Action
|
||||||
originFilter.start();
|
cspFilter.setServletHandler(new ServletHandler());
|
||||||
originFilter.initialize();
|
cspFilter.start();
|
||||||
originFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain);
|
cspFilter.initialize();
|
||||||
|
cspFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain);
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
assertEquals("frame-ancestors 'self'", mockResponse.getHeader("Content-Security-Policy"));
|
assertEquals("frame-ancestors 'self'", mockResponse.getHeader("Content-Security-Policy"));
|
||||||
|
@ -55,7 +57,7 @@ public class HTTPHeaderFiltersTest {
|
||||||
public void testCSPHeaderAppliedOnlyOnce() throws ServletException, IOException, Exception {
|
public void testCSPHeaderAppliedOnlyOnce() throws ServletException, IOException, Exception {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
FilterHolder originFilter = new FilterHolder(new ContentSecurityPolicyFilter());
|
FilterHolder cspFilter = new FilterHolder(new ContentSecurityPolicyFilter());
|
||||||
|
|
||||||
// Set up request
|
// Set up request
|
||||||
HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class);
|
HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class);
|
||||||
|
@ -63,10 +65,11 @@ public class HTTPHeaderFiltersTest {
|
||||||
FilterChain mockFilterChain = Mockito.mock(FilterChain.class);
|
FilterChain mockFilterChain = Mockito.mock(FilterChain.class);
|
||||||
|
|
||||||
// Action
|
// Action
|
||||||
originFilter.start();
|
cspFilter.setServletHandler(new ServletHandler());
|
||||||
originFilter.initialize();
|
cspFilter.start();
|
||||||
originFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain);
|
cspFilter.initialize();
|
||||||
originFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain);
|
cspFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain);
|
||||||
|
cspFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain);
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
assertEquals("frame-ancestors 'self'", mockResponse.getHeader("Content-Security-Policy"));
|
assertEquals("frame-ancestors 'self'", mockResponse.getHeader("Content-Security-Policy"));
|
||||||
|
@ -85,6 +88,7 @@ public class HTTPHeaderFiltersTest {
|
||||||
FilterChain mockFilterChain = Mockito.mock(FilterChain.class);
|
FilterChain mockFilterChain = Mockito.mock(FilterChain.class);
|
||||||
|
|
||||||
// Action
|
// Action
|
||||||
|
xfoFilter.setServletHandler(new ServletHandler());
|
||||||
xfoFilter.start();
|
xfoFilter.start();
|
||||||
xfoFilter.initialize();
|
xfoFilter.initialize();
|
||||||
xfoFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain);
|
xfoFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain);
|
||||||
|
@ -105,6 +109,7 @@ public class HTTPHeaderFiltersTest {
|
||||||
FilterChain mockFilterChain = Mockito.mock(FilterChain.class);
|
FilterChain mockFilterChain = Mockito.mock(FilterChain.class);
|
||||||
|
|
||||||
// Action
|
// Action
|
||||||
|
hstsFilter.setServletHandler(new ServletHandler());
|
||||||
hstsFilter.start();
|
hstsFilter.start();
|
||||||
hstsFilter.initialize();
|
hstsFilter.initialize();
|
||||||
hstsFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain);
|
hstsFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain);
|
||||||
|
@ -125,6 +130,7 @@ public class HTTPHeaderFiltersTest {
|
||||||
FilterChain mockFilterChain = Mockito.mock(FilterChain.class);
|
FilterChain mockFilterChain = Mockito.mock(FilterChain.class);
|
||||||
|
|
||||||
// Action
|
// Action
|
||||||
|
xssFilter.setServletHandler(new ServletHandler());
|
||||||
xssFilter.start();
|
xssFilter.start();
|
||||||
xssFilter.initialize();
|
xssFilter.initialize();
|
||||||
xssFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain);
|
xssFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain);
|
||||||
|
@ -136,16 +142,17 @@ public class HTTPHeaderFiltersTest {
|
||||||
@Test
|
@Test
|
||||||
public void testXContentTypeOptionsHeaderApplied() throws Exception {
|
public void testXContentTypeOptionsHeaderApplied() throws Exception {
|
||||||
// Arrange
|
// Arrange
|
||||||
FilterHolder xssFilter = new FilterHolder(new XContentTypeOptionsFilter());
|
FilterHolder xContentTypeFilter = new FilterHolder(new XContentTypeOptionsFilter());
|
||||||
|
|
||||||
HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class);
|
HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class);
|
||||||
MockHttpServletResponse mockResponse = new MockHttpServletResponse();
|
MockHttpServletResponse mockResponse = new MockHttpServletResponse();
|
||||||
FilterChain mockFilterChain = Mockito.mock(FilterChain.class);
|
FilterChain mockFilterChain = Mockito.mock(FilterChain.class);
|
||||||
|
|
||||||
// Action
|
// Action
|
||||||
xssFilter.start();
|
xContentTypeFilter.setServletHandler(new ServletHandler());
|
||||||
xssFilter.initialize();
|
xContentTypeFilter.start();
|
||||||
xssFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain);
|
xContentTypeFilter.initialize();
|
||||||
|
xContentTypeFilter.getFilter().doFilter(mockRequest, mockResponse, mockFilterChain);
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
assertEquals("nosniff", mockResponse.getHeader("X-Content-Type-Options"));
|
assertEquals("nosniff", mockResponse.getHeader("X-Content-Type-Options"));
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -90,7 +90,7 @@
|
||||||
<inceptionYear>2014</inceptionYear>
|
<inceptionYear>2014</inceptionYear>
|
||||||
<org.slf4j.version>1.7.30</org.slf4j.version>
|
<org.slf4j.version>1.7.30</org.slf4j.version>
|
||||||
<ranger.version>2.1.0</ranger.version>
|
<ranger.version>2.1.0</ranger.version>
|
||||||
<jetty.version>9.4.26.v20200117</jetty.version>
|
<jetty.version>9.4.34.v20201102</jetty.version>
|
||||||
<jackson.version>2.9.10</jackson.version>
|
<jackson.version>2.9.10</jackson.version>
|
||||||
<jackson-databind.version>2.9.10.5</jackson-databind.version>
|
<jackson-databind.version>2.9.10.5</jackson-databind.version>
|
||||||
<nifi.registry.version>0.8.0</nifi.registry.version>
|
<nifi.registry.version>0.8.0</nifi.registry.version>
|
||||||
|
|
Loading…
Reference in New Issue