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-394: Request and response URLs must be parsed as literals not templates. Part 2.
Date Tue, 03 Nov 2015 14:43:35 GMT
Repository: knox
Updated Branches:
  refs/heads/master 33bb1ce57 -> 34b1cd03d


KNOX-394: Request and response URLs must be parsed as literals not templates. Part 2.


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

Branch: refs/heads/master
Commit: 34b1cd03d57c742bfe182c54a4fef21103a15fb6
Parents: 33bb1ce
Author: Kevin Minder <kevin.minder@hortonworks.com>
Authored: Tue Nov 3 09:43:31 2015 -0500
Committer: Kevin Minder <kevin.minder@hortonworks.com>
Committed: Tue Nov 3 09:43:31 2015 -0500

----------------------------------------------------------------------
 CHANGES                                         |  1 +
 .../gateway/OozieServiceDefinitionTest.java     | 50 ++++++++++++++++++++
 .../oozie-request-with-complex-var.xml          | 14 ++++++
 3 files changed, 65 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/34b1cd03/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 65ddf39..c0c5d42 100644
--- a/CHANGES
+++ b/CHANGES
@@ -29,6 +29,7 @@ Release Notes - Apache Knox - Version 0.7.0
     * [KNOX-603] - Coverity: Potential resource leak in BaseKeystoreService.createKeystore
     * [KNOX-614] - Incorrect URI template expansion with {**} query params #fragments
     * [KNOX-616] - XmlUrlRewriteStreamFilter unscapes escaped special characters
+    * [KNOX-394] - Request and response URLs must be parsed as literals not templates
 
 ------------------------------------------------------------------------------
 Release Notes - Apache Knox - Version 0.6.0

http://git-wip-us.apache.org/repos/asf/knox/blob/34b1cd03/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
index 96d8fbd..6b09c2a 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
@@ -96,6 +96,56 @@ public class OozieServiceDefinitionTest {
   }
 
   @Test
+  public void testOozieRewriteRulesForLiteralComplexTemplateValuesBugKnox394() throws Exception
{
+
+    // This is a unique part of this test.
+    String testResource = "oozie-request-with-complex-var.xml";
+
+    // Mock out the service url registry which is required for several url rewrite functions
to work.
+    ServiceRegistry registry = EasyMock.createNiceMock( ServiceRegistry.class );
+    EasyMock.expect( registry.lookupServiceURL( "test-cluster", "NAMENODE" ) ).andReturn(
"test-scheme://test-host:42" ).anyTimes();
+
+    // Mock out the gateway services registry which is required for several url rewrite functions
to work.
+    GatewayServices services = EasyMock.createNiceMock( GatewayServices.class );
+    EasyMock.expect( services.getService( GatewayServices.SERVICE_REGISTRY_SERVICE ) ).andReturn(
registry ).anyTimes();
+
+    UrlRewriteProcessor rewriteProcessor = new UrlRewriteProcessor();
+
+    ServletContext servletContext = EasyMock.createNiceMock( ServletContext.class );
+    EasyMock.expect( servletContext.getAttribute( UrlRewriteServletContextListener.PROCESSOR_ATTRIBUTE_NAME
) ).andReturn( rewriteProcessor ).anyTimes();
+    EasyMock.expect( servletContext.getAttribute( GatewayServices.GATEWAY_SERVICES_ATTRIBUTE
) ).andReturn( services ).anyTimes();
+    EasyMock.expect( servletContext.getAttribute( GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE
) ).andReturn( "test-cluster" ).anyTimes();
+
+    HttpServletRequest servletRequest = EasyMock.createNiceMock( HttpServletRequest.class
);
+    EasyMock.expect( servletRequest.getInputStream() ).andReturn( new MockServletInputStream(
TestUtils.getResourceStream( OozieServiceDefinitionTest.class, testResource ) ) ).anyTimes();
+    EasyMock.expect( servletRequest.getContentType() ).andReturn( "text/xml" ).anyTimes();
+
+    FilterConfig filterConfig = EasyMock.createNiceMock( FilterConfig.class );
+    EasyMock.expect( filterConfig.getServletContext() ).andReturn( servletContext ).anyTimes();
+    EasyMock.expect( filterConfig.getInitParameter( UrlRewriteServletFilter.REQUEST_BODY_FILTER_PARAM
) ).andReturn( "OOZIE/oozie/configuration" ).anyTimes();
+
+    EasyMock.replay( registry, services, servletContext, servletRequest, filterConfig );
+
+    UrlRewriteEnvironment rewriteEnvironment = new UrlRewriteServletEnvironment( servletContext
);
+
+    Reader rulesReader = TestUtils.getResourceReader( "services/oozie/4.0.0/rewrite.xml",
"UTF-8" );
+    UrlRewriteRulesDescriptor rewriteRules = UrlRewriteRulesDescriptorFactory.load( "xml",
rulesReader );
+    rulesReader.close();
+
+    rewriteProcessor.initialize( rewriteEnvironment, rewriteRules );
+
+    UrlRewriteRequest rewriteRequest = new UrlRewriteRequest( filterConfig, servletRequest
);
+
+    InputStream stream = rewriteRequest.getInputStream();
+
+    Document document = TestUtils.parseXml( stream );
+
+    assertThat( document,
+        hasXPath( "/configuration/property[name='oozie.wf.application.path']/value",
+            equalTo( "${nameNode}/user/${user.name}/${examplesRoot}/apps/hive" ) ) );
+  }
+
+  @Test
   public void testOozieRewriteRulesForValuesRelativeToServiceRegistry() throws Exception
{
 
     // This is a unique part of this test.

http://git-wip-us.apache.org/repos/asf/knox/blob/34b1cd03/gateway-test/src/test/resources/org/apache/hadoop/gateway/OozieServiceDefinitionTest/oozie-request-with-complex-var.xml
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/resources/org/apache/hadoop/gateway/OozieServiceDefinitionTest/oozie-request-with-complex-var.xml
b/gateway-test/src/test/resources/org/apache/hadoop/gateway/OozieServiceDefinitionTest/oozie-request-with-complex-var.xml
new file mode 100644
index 0000000..ad1cff5
--- /dev/null
+++ b/gateway-test/src/test/resources/org/apache/hadoop/gateway/OozieServiceDefinitionTest/oozie-request-with-complex-var.xml
@@ -0,0 +1,14 @@
+<configuration><property><name>oozie.use.system.libpath</name><value>true</value></property>
+    <property><name>examplesRoot</name><value>examples-path</value></property>
+    <property><name>cluster_name</name><value>hdp</value></property>
+    <property><name>knox_truth</name><value>true</value></property>
+    <property><name>oozie_port</name><value>11000</value>
+    </property><property><name>oozie_host</name><value>hostname</value></property>
+    <property><name>jobTracker</name><value>hostname</value></property>
+    <property><name>oozie.wf.application.path</name><value>${nameNode}/user/${user.name}/${examplesRoot}/apps/hive</value></property>
+    <property><name>knox_gateway_port</name><value>8443</value></property>
+    <property><name>knox_gateway_path</name><value>gateway</value></property>
+    <property><name>user.name</name><value>svbigred</value></property>
+    <property><name>ENV</name><value>dev</value></property>
+    <property><name>nameNode</name><value>hdfs://hostname:8020</value></property>
+</configuration>
\ No newline at end of file


Mime
View raw message