You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by lm...@apache.org on 2018/03/02 04:46:59 UTC

knox git commit: KNOX-1199 - Ambari View API for Tez View needs Double Quotes Encoded on Dispatch

Repository: knox
Updated Branches:
  refs/heads/master ec915ded8 -> 5b3843a89


KNOX-1199 - Ambari View API for Tez View needs Double Quotes Encoded on Dispatch

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

Branch: refs/heads/master
Commit: 5b3843a89d70c4f8e9b13227480bee1b4a90568b
Parents: ec915de
Author: Larry McCay <lm...@hortonworks.com>
Authored: Thu Mar 1 23:46:32 2018 -0500
Committer: Larry McCay <lm...@hortonworks.com>
Committed: Thu Mar 1 23:46:32 2018 -0500

----------------------------------------------------------------------
 .../dispatch/AbstractGatewayDispatch.java       |  5 ++
 .../PassAllHeadersNoEncodingDispatchTest.java   | 74 ++++++++++++++++++++
 2 files changed, 79 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/5b3843a8/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java
index aad7d4c..0377142 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java
@@ -147,6 +147,11 @@ public abstract class AbstractGatewayDispatch implements Dispatch {
       str.replace(pipe, pipe+1, "%7C");
       pipe = str.indexOf("|", pipe+1);
     }
+    int dq = str.indexOf("\"");
+    while (dq > -1) {
+      str.replace(dq, dq+1, "%22");
+      dq = str.indexOf("\"", dq+1);
+    }
   }
 
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/5b3843a8/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/PassAllHeadersNoEncodingDispatchTest.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/PassAllHeadersNoEncodingDispatchTest.java b/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/PassAllHeadersNoEncodingDispatchTest.java
new file mode 100644
index 0000000..d840ba4
--- /dev/null
+++ b/gateway-spi/src/test/java/org/apache/knox/gateway/dispatch/PassAllHeadersNoEncodingDispatchTest.java
@@ -0,0 +1,74 @@
+package org.apache.knox.gateway.dispatch;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.net.URI;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.knox.test.TestUtils;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+public class PassAllHeadersNoEncodingDispatchTest {
+  @Test( timeout = TestUtils.MEDIUM_TIMEOUT )
+  public void testGetDispatchUrl() throws Exception {
+    HttpServletRequest request;
+    Dispatch dispatch;
+    String path;
+    String query;
+    URI uri;
+
+    dispatch = new PassAllHeadersNoEncodingDispatch();
+
+    path = "http://test-host:42/test-path";
+    request = EasyMock.createNiceMock( HttpServletRequest.class );
+    EasyMock.expect( request.getRequestURI() ).andReturn( path ).anyTimes();
+    EasyMock.expect( request.getRequestURL() ).andReturn( new StringBuffer( path ) ).anyTimes();
+    EasyMock.expect( request.getQueryString() ).andReturn( null ).anyTimes();
+    EasyMock.replay( request );
+    uri = dispatch.getDispatchUrl( request );
+    assertThat( uri.toASCIIString(), is( "http://test-host:42/test-path" ) );
+
+    path = "http://test-host:42/test,path";
+    request = EasyMock.createNiceMock( HttpServletRequest.class );
+    EasyMock.expect( request.getRequestURI() ).andReturn( path ).anyTimes();
+    EasyMock.expect( request.getRequestURL() ).andReturn( new StringBuffer( path ) ).anyTimes();
+    EasyMock.expect( request.getQueryString() ).andReturn( null ).anyTimes();
+    EasyMock.replay( request );
+    uri = dispatch.getDispatchUrl( request );
+    assertThat( uri.toASCIIString(), is( "http://test-host:42/test,path" ) );
+
+    // encoding in the patch remains
+    path = "http://test-host:42/test%2Cpath";
+    request = EasyMock.createNiceMock( HttpServletRequest.class );
+    EasyMock.expect( request.getRequestURI() ).andReturn( path ).anyTimes();
+    EasyMock.expect( request.getRequestURL() ).andReturn( new StringBuffer( path ) ).anyTimes();
+    EasyMock.expect( request.getQueryString() ).andReturn( null ).anyTimes();
+    EasyMock.replay( request );
+    uri = dispatch.getDispatchUrl( request );
+    assertThat( uri.toASCIIString(), is( "http://test-host:42/test%2Cpath" ) );
+
+    // encoding in query string is removed
+    path = "http://test-host:42/test%2Cpath";
+    query = "test%26name=test%3Dvalue";
+    request = EasyMock.createNiceMock( HttpServletRequest.class );
+    EasyMock.expect( request.getRequestURI() ).andReturn( path ).anyTimes();
+    EasyMock.expect( request.getRequestURL() ).andReturn( new StringBuffer( path ) ).anyTimes();
+    EasyMock.expect( request.getQueryString() ).andReturn( query ).anyTimes();
+    EasyMock.replay( request );
+    uri = dispatch.getDispatchUrl( request );
+    assertThat( uri.toASCIIString(), is( "http://test-host:42/test%2Cpath?test&name=test=value" ) );
+
+    // double quotes removed
+    path = "https://test-host:42/api/v1/views/TEZ/versions/0.7.0.2.6.2.0-205/instances/TEZ_CLUSTER_INSTANCE/resources/atsproxy/ws/v1/timeline/TEZ_DAG_ID";
+    query = "limit=9007199254740991&primaryFilter=applicationId:%22application_1518808140659_0007%22&_=1519053586839";
+    request = EasyMock.createNiceMock( HttpServletRequest.class );
+    EasyMock.expect( request.getRequestURI() ).andReturn( path ).anyTimes();
+    EasyMock.expect( request.getRequestURL() ).andReturn( new StringBuffer( path ) ).anyTimes();
+    EasyMock.expect( request.getQueryString() ).andReturn( query ).anyTimes();
+    EasyMock.replay( request );
+    uri = dispatch.getDispatchUrl( request );
+    assertThat( uri.toASCIIString(), is( "https://test-host:42/api/v1/views/TEZ/versions/0.7.0.2.6.2.0-205/instances/TEZ_CLUSTER_INSTANCE/resources/atsproxy/ws/v1/timeline/TEZ_DAG_ID?limit=9007199254740991&primaryFilter=applicationId:%22application_1518808140659_0007%22&_=1519053586839" ) );
+  }
+}