knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject knox git commit: KNOX-614: Incorrect URI template expansion with {**} query params #fragments
Date Tue, 27 Oct 2015 17:16:33 GMT
Repository: knox
Updated Branches:
  refs/heads/master 9c65733f0 -> 999831779


KNOX-614: Incorrect URI template expansion with {**} query params #fragments


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

Branch: refs/heads/master
Commit: 999831779eeb2dbaffc2e655ac1727382dc93afa
Parents: 9c65733
Author: Kevin Minder <kevin.minder@hortonworks.com>
Authored: Tue Oct 27 13:15:47 2015 -0400
Committer: Kevin Minder <kevin.minder@hortonworks.com>
Committed: Tue Oct 27 13:16:25 2015 -0400

----------------------------------------------------------------------
 CHANGES                                         |  3 +-
 .../gateway/util/urltemplate/Expander.java      | 10 ++++--
 .../gateway/util/urltemplate/ExpanderTest.java  | 34 ++++++++++++++++++++
 3 files changed, 44 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/99983177/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 0a851ab..d6f0d99 100644
--- a/CHANGES
+++ b/CHANGES
@@ -16,7 +16,7 @@ Release Notes - Apache Knox - Version 0.7.0
     * [KNOX-564] - Topology deployment fails for no configured providers
     * [KNOX-590] - CLI sys-user-auth-test and user-auth-test have improved messages and work
for more Shiro configs
     * [KNOX-597] - Improve diagnostic logging of HTTP traffic
-    * [KNOX-596] - Add diagnostics to topology depoloyment
+    * [KNOX-596] - Add diagnostics to topology deployment
 
 ** Bug
     * [KNOX-554] - Fixed support for gateway.path change + added support for X-Forward-*
headers in admin topology API.
@@ -25,6 +25,7 @@ Release Notes - Apache Knox - Version 0.7.0
     * [KNOX-599] - Template with {**} in queries are expanded with =null for query params
without a value
     * [KNOX-601] - Knox test failures on windows
     * [KNOX-603] - Coverity: Potential resource leak in BaseKeystoreService.createKeystore
+    * [KNOX-614] - Incorrect URI template expansion with {**} query params #fragments
 
 ------------------------------------------------------------------------------
 Release Notes - Apache Knox - Version 0.6.0

http://git-wip-us.apache.org/repos/asf/knox/blob/99983177/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Expander.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Expander.java
b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Expander.java
index ad6dc82..443df8f 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Expander.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Expander.java
@@ -53,8 +53,14 @@ public class Expander {
     expandScheme( template, names, params, evaluator, builder );
     expandAuthority( template, names, params, evaluator, builder );
     expandPath( template, names, params, evaluator, builder );
-    expandQuery( template, names, params, evaluator, builder );
-    expandFragment( template, names, params, evaluator, builder );
+    if( template.hasFragment() ) {
+      StringBuilder fragment = new StringBuilder();
+      expandFragment( template, names, params, evaluator, fragment );
+      expandQuery( template, names, params, evaluator, builder );
+      builder.append( fragment );
+    } else {
+      expandQuery( template, names, params, evaluator, builder );
+    }
     return builder.toString();
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/99983177/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/ExpanderTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/ExpanderTest.java
b/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/ExpanderTest.java
index 2cf8134..816144c 100644
--- a/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/ExpanderTest.java
+++ b/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/ExpanderTest.java
@@ -28,7 +28,9 @@ import java.net.URISyntaxException;
 import java.util.Arrays;
 import java.util.List;
 
+import static junit.framework.TestCase.assertNotNull;
 import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.equalToIgnoringCase;
 import static org.junit.Assert.assertThat;
@@ -430,4 +432,36 @@ public class ExpanderTest {
 
   }
 
+  @Test
+  public void testRedirectHeaderRewriteKnoxBug614() throws Exception {
+    URI inputUri, outputUri;
+    Matcher<Void> matcher;
+    Matcher<Void>.Match match;
+    Template input, pattern, template;
+    Evaluator evaluator;
+
+    inputUri = new URI("https://internal-host:9443/context/?user.name=admin#/login");
+
+    input = Parser.parse( inputUri.toString() );
+    pattern = Parser.parse( "*://*:*/{contextRoot}/?{**}#{fragment}" );
+    template = Parser.parse( "{$gateway.url}/foo/{contextRoot}/?{**}#{fragment}" );
+
+    matcher = new Matcher<Void>();
+    matcher.add( pattern, null );
+    match = matcher.match( input );
+
+    evaluator = new Evaluator() {
+      @Override
+      public List<String> evaluate( String function, List<String> parameters
) {
+        return Arrays.asList( "https://gateway-host:9443/gateway/default" );
+      }
+    };
+
+    outputUri = Expander.expand( template, match.getParams(), evaluator );
+    assertNotNull(outputUri.toString());
+    assertThat(
+        outputUri.toString(),
+        is( "https://gateway-host:9443/gateway/default/foo/context/?user.name=admin#/login"
) );
+  }
+
 }


Mime
View raw message