knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lmc...@apache.org
Subject knox git commit: KNOX-582 Query Parameter rewrite does not honor empty string value (jeffreyr via lmccay)
Date Tue, 11 Aug 2015 14:12:46 GMT
Repository: knox
Updated Branches:
  refs/heads/master dc86bde75 -> 928b4a27a


KNOX-582 Query Parameter rewrite does not honor empty string value (jeffreyr via lmccay)

Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/928b4a27
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/928b4a27
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/928b4a27

Branch: refs/heads/master
Commit: 928b4a27a15246fa7901418fe43ee0649adf0c14
Parents: dc86bde
Author: Larry McCay <lmccay@hortonworks.com>
Authored: Tue Aug 11 10:11:37 2015 -0400
Committer: Larry McCay <lmccay@hortonworks.com>
Committed: Tue Aug 11 10:11:37 2015 -0400

----------------------------------------------------------------------
 .../hadoop/gateway/util/urltemplate/Parser.java |  2 +-
 .../gateway/util/urltemplate/ParserTest.java    |  6 ++++
 .../gateway/util/urltemplate/RewriterTest.java  | 37 +++++++++++++++++++-
 3 files changed, 43 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/928b4a27/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Parser.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Parser.java
b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Parser.java
index 63a2428..99f4806 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Parser.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Parser.java
@@ -315,7 +315,7 @@ public class Parser {
     // Otherwise the token has no value.
     } else {
       paramName = Segment.ANONYMOUS_PARAM;
-      actualPattern = null;
+      actualPattern = s;
       effectivePattern = actualPattern;
     }
     Token token = new Token( paramName, actualPattern, effectivePattern );

http://git-wip-us.apache.org/repos/asf/knox/blob/928b4a27/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/ParserTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/ParserTest.java
b/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/ParserTest.java
index a36ddae..eeabba9 100644
--- a/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/ParserTest.java
+++ b/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/ParserTest.java
@@ -1253,6 +1253,12 @@ public class ParserTest {
     assertThat( output.getParameterName(), is( "" ) );
     assertThat( output.getOriginalPattern(), is( "$" ) );
     assertThat( output.getEffectivePattern(), is( "$" ) );
+
+    input = "";
+    output = Parser.parseTemplateToken( input, Segment.GLOB_PATTERN );
+    assertThat( output.getParameterName(), is( "" ) );
+    assertThat( output.getOriginalPattern(), is( "" ) );
+    assertThat( output.getEffectivePattern(), is( "" ) );
   }
 
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/928b4a27/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/RewriterTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/RewriterTest.java
b/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/RewriterTest.java
index 8d031c2..285b025 100644
--- a/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/RewriterTest.java
+++ b/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/RewriterTest.java
@@ -33,10 +33,16 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.io.UnsupportedEncodingException;
 
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
 
 @Category( { UnitTests.class, FastTests.class } )
 public class RewriterTest {
@@ -326,7 +332,36 @@ public class RewriterTest {
 
     assertThat( actualOutput, is( expectOutput ) );
   }
-  
+
+  @Test
+  public void testRewriteHonorsEmptyParameters() throws Exception {
+    Template inputTemplate, outputTemplate;
+    URI actualInput, actualOutput;
+
+    inputTemplate = Parser.parse( "*://*:*/**/oozie/{**}?{**}");
+    outputTemplate = Parser.parse( "http://localhost:11000/oozie/{**}?{**}");
+
+    actualInput = new URI("https://localhost:8443/gateway/oozieui/oozie/v2/jobs?_dc=1438899557070&filter=&timezone=GMT");
+    actualOutput = Rewriter.rewrite( actualInput, inputTemplate, outputTemplate, null, null
);
+
+    Map<String, String> actualInputParameters = this.getParameters( actualInput.toURL());
+    Map<String, String> actualOutputParameters  = this.getParameters( actualOutput.toURL());
+    assertTrue( actualInputParameters.equals(actualOutputParameters));
+
+  }
+
+  private Map<String, String> getParameters(URL url) throws UnsupportedEncodingException
{
+    final Map<String, String> parameter_pairs = new LinkedHashMap<String, String>();
+    final String[] pairs = url.getQuery().split("&");
+    for (String pair : pairs) {
+       final int idx = pair.indexOf("=");
+       final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), "UTF-8")
: pair;
+       final String value = idx > 0 && pair.length() > idx + 1 ? URLDecoder.decode(pair.substring(idx
+ 1), "UTF-8") : "";
+       parameter_pairs.put(key, value);
+    }
+    return parameter_pairs;
+    }
+
   private class TestResolver implements Params {
 
     private FilterConfig config;


Mime
View raw message