Repository: knox
Updated Branches:
  refs/heads/master 62a75e0e0 -> ce9aa2441


KNOX-754 encoding response headers


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

Branch: refs/heads/master
Commit: ce9aa244163a8db709722eb786f4fb45ec59e7fd
Parents: 62a75e0
Author: Sumit Gupta <su...@apache.org>
Authored: Wed Oct 12 09:05:00 2016 -0400
Committer: Sumit Gupta <su...@apache.org>
Committed: Wed Oct 12 09:05:00 2016 -0400

----------------------------------------------------------------------
 .../filter/rewrite/impl/UrlRewriteResponse.java |  2 +-
 .../hadoop/gateway/GatewayBasicFuncTest.java    | 44 +++++++++++++++++---
 2 files changed, 40 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/ce9aa244/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
----------------------------------------------------------------------
diff --git 
a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
 
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
index 5e4aae3..2c9c70d 100644
--- 
a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
+++ 
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/UrlRewriteResponse.java
@@ -117,7 +117,7 @@ public class UrlRewriteResponse extends 
GatewayResponseWrapper implements Params
       Template input = Parser.parseLiteral( value );
       Template output = rewriter.rewrite( this, input, 
UrlRewriter.Direction.OUT, rule );
       if( output != null ) {
-        value = output.getPattern();
+        value = output.toEncodedString();
       }
     } catch( URISyntaxException e ) {
       LOG.failedToParseValueForUrlRewrite( value );

http://git-wip-us.apache.org/repos/asf/knox/blob/ce9aa244/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
----------------------------------------------------------------------
diff --git 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
 
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
index 2df67dd..dc6e80e 100644
--- 
a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
+++ 
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
@@ -67,11 +67,7 @@ import org.slf4j.LoggerFactory;
 import static com.jayway.restassured.RestAssured.given;
 import static org.apache.hadoop.test.TestUtils.LOG_ENTER;
 import static org.apache.hadoop.test.TestUtils.LOG_EXIT;
-import static org.hamcrest.CoreMatchers.anyOf;
-import static org.hamcrest.CoreMatchers.either;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.CoreMatchers.*;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.greaterThan;
@@ -343,6 +339,44 @@ public class GatewayBasicFuncTest {
   }
 
   @Test( timeout = TestUtils.MEDIUM_TIMEOUT )
+  public void testBasicOutboundEncodedHeaderUseCase() throws IOException {
+    LOG_ENTER();
+    String root = "/tmp/GatewayBasicFuncTest/testBasicOutboundHeaderUseCase";
+    String username = "hdfs";
+    String password = "hdfs-password";
+    InetSocketAddress gatewayAddress = driver.gateway.getAddresses()[0];
+    String gatewayHostName = gatewayAddress.getHostName();
+    String gatewayAddrName = 
InetAddress.getByName(gatewayHostName).getHostAddress();
+
+    driver.getMock( "WEBHDFS" )
+        .expect()
+        .method( "PUT" )
+        .pathInfo( "/v1" + root + "/dir/fileレポー" )
+        .header( "Host", driver.getRealAddr( "WEBHDFS" ) )
+        .queryParam( "op", "CREATE" )
+        .queryParam( "user.name", username )
+        .respond()
+        .status( HttpStatus.SC_TEMPORARY_REDIRECT )
+        .header("Location", driver.getRealUrl("DATANODE") + "/v1" + root + 
"/dir/file%E3%83%AC%E3%83%9D%E3%83%BC?op=CREATE&user.name=hdfs");
+    Response response = given()
+        //.log().all()
+        .auth().preemptive().basic( username, password )
+        .header("X-XSRF-Header", "jksdhfkhdsf")
+        .queryParam( "op", "CREATE" )
+        .expect()
+        //.log().ifError()
+        .statusCode( HttpStatus.SC_TEMPORARY_REDIRECT )
+        .when().put( driver.getUrl("WEBHDFS") + "/v1" + root + 
"/dir/file%E3%83%AC%E3%83%9D%E3%83%BC" );
+    String location = response.getHeader( "Location" );
+    //System.out.println( location );
+    log.debug( "Redirect location: " + response.getHeader( "Location" ) );
+    if( driver.isUseGateway() ) {
+      MatcherAssert.assertThat( location, 
containsString("/dir/file%E3%83%AC%E3%83%9D%E3%83%BC") );
+    }
+    LOG_EXIT();
+  }
+
+  @Test( timeout = TestUtils.MEDIUM_TIMEOUT )
   public void testHdfsTildeUseCase() throws IOException {
     LOG_ENTER();
     String root = "/tmp/GatewayBasicFuncTest/testHdfsTildeUseCase";

Reply via email to