Search in sources :

Example 1 with UrlRewriteFilterContentDescriptorImpl

use of org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteFilterContentDescriptorImpl in project knox by apache.

the class JavaScriptFilterReaderTest method testSimpleMultipleLines.

@Test
public void testSimpleMultipleLines() throws IOException {
    String inputJs = "var url = '/webhdfs/v1' + abs_path + '?op=GET_BLOCK_LOCATIONS';\n" + "$.ajax({\"url\": url, \"crossDomain\": true}).done(function(data) {}).error(network_error_handler(url));\n";
    StringReader inputReader = new StringReader(inputJs);
    UrlRewriteFilterContentDescriptor config = new UrlRewriteFilterContentDescriptorImpl();
    config.addApply("/webhdfs/v1", "test-rule");
    JavaScriptFilterReader filterReader = new NoopJsFilterReader(inputReader, config);
    String outputJs = new String(IOUtils.toCharArray(filterReader));
    assertThat(outputJs, is(inputJs));
}
Also used : StringReader(java.io.StringReader) UrlRewriteFilterContentDescriptorImpl(org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteFilterContentDescriptorImpl) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor) Test(org.junit.Test)

Example 2 with UrlRewriteFilterContentDescriptorImpl

use of org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteFilterContentDescriptorImpl in project knox by apache.

the class JavaScriptFilterReaderTest method testMatchedJsContent.

@Test
public void testMatchedJsContent() throws IOException {
    Map<String, Map<String, String>> rules = new HashMap<>();
    Map<String, String> map = new HashMap<>();
    map.put("(https?://[^/':,]+:[\\d]+)?/cluster/app", "https://knoxhost:8443/cluster/app");
    map.put("/webhdfs/v1", "https://knoxhost:8443/webhdfs/v1");
    rules.put("test-rule", map);
    String inputJs = "var url = '/webhdfs/v1' + abs_path + '?op=GET_BLOCK_LOCATIONS';\n" + "$.ajax({\"url\": url, \"crossDomain\": true}).done(function(data) {\n" + "  var url = http://testhost:8088/cluster/app/application_1436831599487_0001;\n" + "}).error(network_error_handler(url));\n";
    StringReader inputReader = new StringReader(inputJs);
    UrlRewriteFilterContentDescriptor config = new UrlRewriteFilterContentDescriptorImpl();
    config.addApply("(https?://[^/':,]+:[\\d]+)?/cluster/app", "test-rule");
    config.addApply("/webhdfs/v1", "test-rule");
    JavaScriptFilterReader filterReader = new MatchRuleJsFilterReader(inputReader, rules, config);
    String outputJs = new String(IOUtils.toCharArray(filterReader));
    String expectedOutputJs = "var url = 'https://knoxhost:8443/webhdfs/v1' + abs_path + '?op=GET_BLOCK_LOCATIONS';\n" + "$.ajax({\"url\": url, \"crossDomain\": true}).done(function(data) {\n" + "  var url = https://knoxhost:8443/cluster/app/application_1436831599487_0001;\n" + "}).error(network_error_handler(url));\n";
    assertThat(outputJs, is(expectedOutputJs));
}
Also used : HashMap(java.util.HashMap) StringReader(java.io.StringReader) Map(java.util.Map) HashMap(java.util.HashMap) UrlRewriteFilterContentDescriptorImpl(org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteFilterContentDescriptorImpl) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor) Test(org.junit.Test)

Example 3 with UrlRewriteFilterContentDescriptorImpl

use of org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteFilterContentDescriptorImpl in project knox by apache.

the class JavaScriptFilterReaderTest method testSimple.

@Test
public void testSimple() throws IOException {
    String inputJs = "function load_page() {}\n";
    StringReader inputReader = new StringReader(inputJs);
    UrlRewriteFilterContentDescriptor config = new UrlRewriteFilterContentDescriptorImpl();
    JavaScriptFilterReader filterReader = new NoopJsFilterReader(inputReader, config);
    String outputJs = new String(IOUtils.toCharArray(filterReader));
    assertThat(outputJs, is(inputJs));
}
Also used : StringReader(java.io.StringReader) UrlRewriteFilterContentDescriptorImpl(org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteFilterContentDescriptorImpl) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor) Test(org.junit.Test)

Example 4 with UrlRewriteFilterContentDescriptorImpl

use of org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteFilterContentDescriptorImpl in project knox by apache.

the class HtmlFilterReaderBaseTest method testMatchedJavaScriptText.

@Test
public void testMatchedJavaScriptText() throws IOException, ParserConfigurationException {
    Map<String, Map<String, String>> rules = new HashMap<>();
    Map<String, String> map = new HashMap<>();
    map.put("(https?://[^/':,]+:[\\d]+)?/cluster/app", "https://knoxhost:8443/cluster/app");
    rules.put("test-rule", map);
    String inputXml = "<root>\n" + "  <script type=\"text/javascript\">\n" + "    var appsTableData=[\n" + "      [\"<a href='/cluster/app/application_1436831599487_0008'>application_1436831599487_0008</a>\",\"hdfs\",\"Spark Pi\",\"SPARK\",\"<a href='http://testhost:8088/cluster/app/application_1436831599487_0008'>History</a>\"],\n" + "      [\"<a href='/cluster/app/application_1436831599487_0006'>application_1436831599487_0006</a>\",\"hdfs\",\"Spark Pi\",\"SPARK\",\"<a href='http://testhost:8088/cluster/app/application_1436831599487_0006'>History</a>\"],\n" + "      [\"<a href='/cluster/app/application_1436831599487_0007'>application_1436831599487_0007</a>\",\"hdfs\",\"Spark Pi\",\"SPARK\",\"<a href='http://testhost:8088/cluster/app/application_1436831599487_0007'>History</a>\"]\n" + "    ]\n" + "  </script>\n" + "</root>\n";
    StringReader inputReader = new StringReader(inputXml);
    UrlRewriteFilterContentDescriptor config = new UrlRewriteFilterContentDescriptorImpl();
    config.addApply("(https?://[^/':,]+:[\\d]+)?/cluster/app", "test-rule");
    HtmlFilterReaderBase filterReader = new MatchRuleXmlFilterReader(inputReader, rules, config);
    String outputXml = new String(IOUtils.toCharArray(filterReader));
    String expectedOutput = "<root>\n" + "  <script type=\"text/javascript\">\n" + "    var appsTableData=[\n" + "      [\"<a href='https://knoxhost:8443/cluster/app/application_1436831599487_0008'>application_1436831599487_0008</a>\",\"hdfs\",\"Spark Pi\",\"SPARK\",\"<a href='https://knoxhost:8443/cluster/app/application_1436831599487_0008'>History</a>\"],\n" + "      [\"<a href='https://knoxhost:8443/cluster/app/application_1436831599487_0006'>application_1436831599487_0006</a>\",\"hdfs\",\"Spark Pi\",\"SPARK\",\"<a href='https://knoxhost:8443/cluster/app/application_1436831599487_0006'>History</a>\"],\n" + "      [\"<a href='https://knoxhost:8443/cluster/app/application_1436831599487_0007'>application_1436831599487_0007</a>\",\"hdfs\",\"Spark Pi\",\"SPARK\",\"<a href='https://knoxhost:8443/cluster/app/application_1436831599487_0007'>History</a>\"]\n" + "    ]\n" + "  </script>\n" + "</root>\n";
    assertThat(outputXml, is(expectedOutput));
}
Also used : HashMap(java.util.HashMap) StringReader(java.io.StringReader) HashMap(java.util.HashMap) Map(java.util.Map) UrlRewriteFilterContentDescriptorImpl(org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteFilterContentDescriptorImpl) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor) Test(org.junit.Test)

Example 5 with UrlRewriteFilterContentDescriptorImpl

use of org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteFilterContentDescriptorImpl in project knox by apache.

the class HtmlFilterReaderBaseTest method testMRJobHistoryUIJavaScriptText.

@Test
public void testMRJobHistoryUIJavaScriptText() throws IOException, ParserConfigurationException {
    Map<String, Map<String, String>> rules = new HashMap<>();
    Map<String, String> map = new HashMap<>();
    map.put("https?://[^/':,]+:[\\d]+", "https://knoxhost:8443/gateway/nodemanagerui/node?host=knoxhost");
    rules.put("test-rule", map);
    String inputXml = "<root>\n" + "  <script type=\"text/javascript\">\n" + "    var appsTableData=[\n" + "      [\"<a href='http://testhost:8042'>/default-rack/node</a>\",\"<a href='http://testhost:8042'>testhost:8042</a>\"],\n" + "    ]\n" + "  </script>\n" + "</root>\n";
    StringReader inputReader = new StringReader(inputXml);
    UrlRewriteFilterContentDescriptor config = new UrlRewriteFilterContentDescriptorImpl();
    config.addApply("https?://[^/':,]+:[\\d]+", "test-rule");
    HtmlFilterReaderBase filterReader = new MatchRuleXmlFilterReader(inputReader, rules, config);
    String outputXml = new String(IOUtils.toCharArray(filterReader));
    String expectedOutput = "<root>\n" + "  <script type=\"text/javascript\">\n" + "    var appsTableData=[\n" + "      [\"<a href='https://knoxhost:8443/gateway/nodemanagerui/node?host=knoxhost'>/default-rack/node</a>\",\"<a href='https://knoxhost:8443/gateway/nodemanagerui/node?host=knoxhost'>testhost:8042</a>\"],\n" + "    ]\n" + "  </script>\n" + "</root>\n";
    assertThat(outputXml, is(expectedOutput));
}
Also used : HashMap(java.util.HashMap) StringReader(java.io.StringReader) HashMap(java.util.HashMap) Map(java.util.Map) UrlRewriteFilterContentDescriptorImpl(org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteFilterContentDescriptorImpl) UrlRewriteFilterContentDescriptor(org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor) Test(org.junit.Test)

Aggregations

StringReader (java.io.StringReader)5 UrlRewriteFilterContentDescriptor (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteFilterContentDescriptor)5 UrlRewriteFilterContentDescriptorImpl (org.apache.knox.gateway.filter.rewrite.impl.UrlRewriteFilterContentDescriptorImpl)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3