sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-startupfilter] 17/21: SLING-6100 - avoid NPE in StartupFilterImpl
Date Wed, 18 Oct 2017 23:25:52 GMT
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-startupfilter.git

commit bb2972447e71de1de65904e3e545300f237e3886
Author: Bertrand Delacretaz <bdelacretaz@apache.org>
AuthorDate: Wed Oct 5 10:56:58 2016 +0000

    SLING-6100 - avoid NPE in StartupFilterImpl
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1763407 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/startupfilter/impl/StartupFilterImpl.java   |  2 +-
 .../startupfilter/impl/StartupFilterImplTest.java     | 19 ++++++++++++++++---
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/sling/startupfilter/impl/StartupFilterImpl.java b/src/main/java/org/apache/sling/startupfilter/impl/StartupFilterImpl.java
index 6f850ff..d0b367d 100644
--- a/src/main/java/org/apache/sling/startupfilter/impl/StartupFilterImpl.java
+++ b/src/main/java/org/apache/sling/startupfilter/impl/StartupFilterImpl.java
@@ -101,7 +101,7 @@ public class StartupFilterImpl implements StartupFilter, Filter {
         // Bypass for the managerRoot path
         if(request instanceof HttpServletRequest) {
             final String pathInfo = ((HttpServletRequest)request).getPathInfo();
-            if(managerRoot != null && managerRoot.length() > 0 && pathInfo.startsWith(managerRoot))
{
+            if(managerRoot != null && managerRoot.length() > 0 && pathInfo
!= null && pathInfo.startsWith(managerRoot)) {
                 log.debug("Bypassing filter for path {} which starts with {}", pathInfo,
managerRoot);
                 chain.doFilter(request, sr);
                 return;
diff --git a/src/test/java/org/apache/sling/startupfilter/impl/StartupFilterImplTest.java
b/src/test/java/org/apache/sling/startupfilter/impl/StartupFilterImplTest.java
index 46a2c5c..7745cad 100644
--- a/src/test/java/org/apache/sling/startupfilter/impl/StartupFilterImplTest.java
+++ b/src/test/java/org/apache/sling/startupfilter/impl/StartupFilterImplTest.java
@@ -133,6 +133,7 @@ public class StartupFilterImplTest {
     private AtomicInteger activeFilterCount;
     private ServiceRegistration serviceRegistration;
     private String requestPath;
+    private String pathInfo;
     private static final String CONSOLE_ROOT = "/test/system/console";
 
     @Before
@@ -202,7 +203,7 @@ public class StartupFilterImplTest {
             will(new ChangeInteger(activeFilterCount, false));
 
             allowing(request).getPathInfo();
-            will(returnValue(getRequestPath()));
+            will(returnValue(getPathInfo()));
 
             allowing(chain).doFilter(with(any(ServletRequest.class)), with(any(ServletResponse.class)));
         }});
@@ -214,6 +215,10 @@ public class StartupFilterImplTest {
         return requestPath;
     }
 
+    private String getPathInfo() {
+        return pathInfo;
+    }
+
     private void assertRequest(final int expectedStatus, final String expectedMessage) throws
Exception {
         lastReturnedStatus = -1;
 
@@ -237,14 +242,22 @@ public class StartupFilterImplTest {
 
     @Test
     public void testBypassRoot() throws Exception {
-        requestPath = CONSOLE_ROOT;
+        requestPath = pathInfo = CONSOLE_ROOT;
         setProvider(null);
         assertRequest(-1, "");
     }
 
     @Test
+    public void testNullPathInfo() throws Exception {
+        requestPath = pathInfo = CONSOLE_ROOT;
+        pathInfo = null;
+        setProvider(null);
+        assertRequest(503, "Startup in progress");
+    }
+
+    @Test
     public void testBypassSubpath() throws Exception {
-        requestPath = CONSOLE_ROOT + "/something";
+        requestPath = pathInfo = CONSOLE_ROOT + "/something";
         setProvider(null);
         assertRequest(-1, "");
     }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message