knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From su...@apache.org
Subject knox git commit: KNOX-763 Added rewrite filter apply capability to text values in html content
Date Wed, 09 Nov 2016 22:08:38 GMT
Repository: knox
Updated Branches:
  refs/heads/master c51b0feb6 -> c7c58cdda


KNOX-763 Added rewrite filter apply capability to text values in html content


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

Branch: refs/heads/master
Commit: c7c58cddab5e7818d6f2a390cb354a9c16aaf8da
Parents: c51b0fe
Author: Sumit Gupta <sumit@apache.org>
Authored: Wed Nov 9 17:07:24 2016 -0500
Committer: Sumit Gupta <sumit@apache.org>
Committed: Wed Nov 9 17:07:24 2016 -0500

----------------------------------------------------------------------
 .../rewrite/impl/html/HtmlFilterReaderBase.java |  2 +-
 .../api/UrlRewriteServletFilterTest.java        | 51 ++++++++++++++++++++
 .../api/UrlRewriteServletFilterTest/rewrite.xml | 10 ++++
 3 files changed, 62 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/c7c58cdd/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBase.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBase.java
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBase.java
index a6222a8..f9d11cf 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBase.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBase.java
@@ -218,7 +218,7 @@ public abstract class HtmlFilterReaderBase extends Reader implements UrlRewriteF
           // embedded javascript content
           outputValue = UrlRewriteUtil.filterJavaScript( inputValue, config, this, REGEX_COMPILER
);
         } else {
-          outputValue = filterText( stack.peek().getQName(), inputValue, null );
+          outputValue = filterText( stack.peek().getQName(), inputValue, getRuleName(inputValue)
);
         }
       }
       if( outputValue == null ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/c7c58cdd/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
index 54fdfa3..1950bf3 100644
--- a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
+++ b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest.java
@@ -759,6 +759,57 @@ public class UrlRewriteServletFilterTest {
     assertThat( the( actual ), hasXPath( "/root/url/text()", equalTo( "http://mock-host:42/test-output-path-2"
) ) );
   }
 
+  @Test
+  public void testResponseHtmlBodyRewriteCSSImport() throws Exception {
+    Map<String,String> initParams = new HashMap<String,String>();
+    //initParams.put( "url, "" );
+    initParams.put( "response.body", "test-filter-5" );
+    //initParams.put( "response", "" );
+    setUp( initParams );
+
+    String responseHtml = "<!DOCTYPE html>\n" +
+                          "<html>\n" +
+                          "  <head>\n" +
+                          "    <meta charset=\"UTF-8\">\n" +
+                          "    <style type=\"text/css\">@import \"pretty.css\";</style>"
+
+                          "    <script src=\"script.js\"></script>\n" +
+                          "  </head>\n" +
+                          "  <body>\n" +
+                          "  </body>\n" +
+                          "</html>";
+    String rewrittenResponseHtml = "<!DOCTYPE html>\n" +
+                                   "<html>\n" +
+                                   "  <head>\n" +
+                                   "    <meta charset=\"UTF-8\">\n" +
+                                   "    <style type=\"text/css\">@import \"http://someotherhost/stylesheets/pretty.css\";</style>"
+
+                                   "    <script src=\"script.js\"></script>\n"
+
+                                   "  </head>\n" +
+                                   "  <body>\n" +
+                                   "  </body>\n" +
+                                   "</html>";
+
+    // Setup the server side request/response interaction.
+    interaction.expect()
+               .method( "GET" )
+               .requestUrl( "http://mock-host:42/test-output-path-1" );
+    interaction.respond()
+               .contentType( "application/html" )
+               .content( responseHtml, Charset.forName( "UTF-8" ) )
+               .status( 200 );
+    interactions.add( interaction );
+    request.setMethod( "GET" );
+    request.setURI( "/test-input-path" );
+    request.setHeader( "Host", "mock-host:42" );
+    request.setHeader( "Content-Type", "application/html" );
+
+    // Execute the request.
+    response = TestUtils.execute( server, request );
+
+    assertThat( response.getStatus(), is( 200 ) );
+    String content = response.getContent();
+    assertThat(content, is(rewrittenResponseHtml));
+  }
+
   private static class SetupFilter implements Filter {
     @Override
     public void init( FilterConfig filterConfig ) throws ServletException {

http://git-wip-us.apache.org/repos/asf/knox/blob/c7c58cdd/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest/rewrite.xml
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest/rewrite.xml
b/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest/rewrite.xml
index e3e9c63..72a7ecc 100644
--- a/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest/rewrite.xml
+++ b/gateway-provider-rewrite/src/test/resources/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteServletFilterTest/rewrite.xml
@@ -53,6 +53,10 @@
         <rewrite template="http://someotherhost/stylesheets/pretty.css"/>
     </rule>
 
+    <rule name="test-rule-html-import-attribute">
+        <rewrite template="@import &quot;http://someotherhost/stylesheets/pretty.css&quot;;"/>
+    </rule>
+
     <filter name="test-filter-1">
         <content type="application/json">
             <apply path="$.url" rule="test-rule-1"/>
@@ -91,5 +95,11 @@
         </content>
     </filter>
 
+    <filter name="test-filter-5">
+        <content type="*/html">
+            <apply path="(@import)+ .*css.*" rule="test-rule-html-import-attribute"/>
+        </content>
+    </filter>
+
 
 </rules>
\ No newline at end of file


Mime
View raw message