hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1143212 - in /hadoop/common/trunk/common: CHANGES.txt src/java/org/apache/hadoop/http/HttpServer.java src/test/core/org/apache/hadoop/http/TestHtmlQuoting.java src/test/core/org/apache/hadoop/http/TestHttpServer.java
Date Tue, 05 Jul 2011 22:09:54 GMT
Author: todd
Date: Tue Jul  5 22:09:54 2011
New Revision: 1143212

URL: http://svn.apache.org/viewvc?rev=1143212&view=rev
Log:
HADOOP-7440. HttpServer.getParameterValues throws NPE for missing parameters. Contributed
by Uma Maheswara Rao G and Todd Lipcon.

Modified:
    hadoop/common/trunk/common/CHANGES.txt
    hadoop/common/trunk/common/src/java/org/apache/hadoop/http/HttpServer.java
    hadoop/common/trunk/common/src/test/core/org/apache/hadoop/http/TestHtmlQuoting.java
    hadoop/common/trunk/common/src/test/core/org/apache/hadoop/http/TestHttpServer.java

Modified: hadoop/common/trunk/common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/CHANGES.txt?rev=1143212&r1=1143211&r2=1143212&view=diff
==============================================================================
--- hadoop/common/trunk/common/CHANGES.txt (original)
+++ hadoop/common/trunk/common/CHANGES.txt Tue Jul  5 22:09:54 2011
@@ -346,6 +346,9 @@ Trunk (unreleased changes)
     HADOOP-7090. Fix resource leaks in s3.INode, BloomMapFile, WritableUtils
     and CBZip2OutputStream.  (Uma Maheswara Rao G via szetszwo)
 
+    HADOOP-7440. HttpServer.getParameterValues throws NPE for missing
+    parameters. (Uma Maheswara Rao G and todd via todd)
+
 Release 0.22.0 - Unreleased
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/trunk/common/src/java/org/apache/hadoop/http/HttpServer.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/src/java/org/apache/hadoop/http/HttpServer.java?rev=1143212&r1=1143211&r2=1143212&view=diff
==============================================================================
--- hadoop/common/trunk/common/src/java/org/apache/hadoop/http/HttpServer.java (original)
+++ hadoop/common/trunk/common/src/java/org/apache/hadoop/http/HttpServer.java Tue Jul  5
22:09:54 2011
@@ -800,6 +800,9 @@ public class HttpServer implements Filte
       public String[] getParameterValues(String name) {
         String unquoteName = HtmlQuoting.unquoteHtmlChars(name);
         String[] unquoteValue = rawRequest.getParameterValues(unquoteName);
+        if (unquoteValue == null) {
+          return null;
+        }
         String[] result = new String[unquoteValue.length];
         for(int i=0; i < result.length; ++i) {
           result[i] = HtmlQuoting.quoteHtmlChars(unquoteValue[i]);

Modified: hadoop/common/trunk/common/src/test/core/org/apache/hadoop/http/TestHtmlQuoting.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/src/test/core/org/apache/hadoop/http/TestHtmlQuoting.java?rev=1143212&r1=1143211&r2=1143212&view=diff
==============================================================================
--- hadoop/common/trunk/common/src/test/core/org/apache/hadoop/http/TestHtmlQuoting.java (original)
+++ hadoop/common/trunk/common/src/test/core/org/apache/hadoop/http/TestHtmlQuoting.java Tue
Jul  5 22:09:54 2011
@@ -17,11 +17,12 @@
  */
 package org.apache.hadoop.http;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
+
+import javax.servlet.http.HttpServletRequest;
 
 import org.junit.Test;
+import org.mockito.Mockito;
 
 public class TestHtmlQuoting {
 
@@ -62,4 +63,28 @@ public class TestHtmlQuoting {
     }
     runRoundTrip(buffer.toString());
   }
+  
+
+  @Test
+  public void testRequestQuoting() throws Exception {
+    HttpServletRequest mockReq = Mockito.mock(HttpServletRequest.class);
+    HttpServer.QuotingInputFilter.RequestQuoter quoter =
+      new HttpServer.QuotingInputFilter.RequestQuoter(mockReq);
+    
+    Mockito.doReturn("a<b").when(mockReq).getParameter("x");
+    assertEquals("Test simple param quoting",
+        "a&lt;b", quoter.getParameter("x"));
+    
+    Mockito.doReturn(null).when(mockReq).getParameter("x");
+    assertEquals("Test that missing parameters dont cause NPE",
+        null, quoter.getParameter("x"));
+
+    Mockito.doReturn(new String[]{"a<b", "b"}).when(mockReq).getParameterValues("x");
+    assertArrayEquals("Test escaping of an array",
+        new String[]{"a&lt;b", "b"}, quoter.getParameterValues("x"));
+
+    Mockito.doReturn(null).when(mockReq).getParameterValues("x");
+    assertArrayEquals("Test that missing parameters dont cause NPE for array",
+        null, quoter.getParameterValues("x"));
+  }
 }

Modified: hadoop/common/trunk/common/src/test/core/org/apache/hadoop/http/TestHttpServer.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/src/test/core/org/apache/hadoop/http/TestHttpServer.java?rev=1143212&r1=1143211&r2=1143212&view=diff
==============================================================================
--- hadoop/common/trunk/common/src/test/core/org/apache/hadoop/http/TestHttpServer.java (original)
+++ hadoop/common/trunk/common/src/test/core/org/apache/hadoop/http/TestHttpServer.java Tue
Jul  5 22:09:54 2011
@@ -45,16 +45,20 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletRequestWrapper;
 import javax.servlet.http.HttpServletResponse;
 
+import junit.framework.Assert;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeys;
+import org.apache.hadoop.http.HttpServer.QuotingInputFilter.RequestQuoter;
 import org.apache.hadoop.security.Groups;
 import org.apache.hadoop.security.ShellBasedUnixGroupsMapping;
 import org.apache.hadoop.security.authorize.AccessControlList;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.mockito.Mockito;
 
 public class TestHttpServer extends HttpServerFunctionalTest {
   private static HttpServer server;
@@ -379,4 +383,26 @@ public class TestHttpServer extends Http
     }
     myServer.stop();
   }
+  
+  @Test
+  public void testRequestQuoterWithNull() throws Exception {
+    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+    Mockito.doReturn(null).when(request).getParameterValues("dummy");
+    RequestQuoter requestQuoter = new RequestQuoter(request);
+    String[] parameterValues = requestQuoter.getParameterValues("dummy");
+    Assert.assertEquals("It should return null "
+        + "when there are no values for the parameter", null, parameterValues);
+  }
+
+  @Test
+  public void testRequestQuoterWithNotNull() throws Exception {
+    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+    String[] values = new String[] { "abc", "def" };
+    Mockito.doReturn(values).when(request).getParameterValues("dummy");
+    RequestQuoter requestQuoter = new RequestQuoter(request);
+    String[] parameterValues = requestQuoter.getParameterValues("dummy");
+    Assert.assertTrue("It should return Parameter Values", Arrays.equals(
+        values, parameterValues));
+  }
+
 }



Mime
View raw message