knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lmc...@apache.org
Subject knox git commit: KNOX-913 - Invalid login.jsp redirect for Ranger Admin UI
Date Tue, 25 Apr 2017 19:41:49 GMT
Repository: knox
Updated Branches:
  refs/heads/master cfa28c766 -> ee332f578


KNOX-913 - Invalid login.jsp redirect for Ranger Admin UI

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

Branch: refs/heads/master
Commit: ee332f57824ee1fc4cb2343f5824e31895a30fda
Parents: cfa28c7
Author: Larry McCay <lmccay@hortonworks.com>
Authored: Tue Apr 25 15:41:40 2017 -0400
Committer: Larry McCay <lmccay@hortonworks.com>
Committed: Tue Apr 25 15:41:40 2017 -0400

----------------------------------------------------------------------
 .../rewrite/api/UrlRewriteProcessorTest.java    | 44 ++++++++++++++++++++
 .../gateway/util/urltemplate/Matcher.java       | 26 +++++++++++-
 .../gateway/util/urltemplate/MatcherTest.java   | 30 +++++++++++++
 3 files changed, 99 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/ee332f57/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteProcessorTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteProcessorTest.java
b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteProcessorTest.java
index 5135ad9..e40a9a9 100644
--- a/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteProcessorTest.java
+++ b/gateway-provider-rewrite/src/test/java/org/apache/hadoop/gateway/filter/rewrite/api/UrlRewriteProcessorTest.java
@@ -328,6 +328,50 @@ public class UrlRewriteProcessorTest {
     assertEquals("true", reWrittenParams.get("indent"));
   }
 
+
+  @Test
+  public void testSolrRewriteDefaultPort() throws Exception {
+    URI inputUri, outputUri;
+    Matcher<Void> matcher;
+    Matcher<Void>.Match match;
+    Template input, pattern, template;
+
+    inputUri = new URI(
+                "https://hortonworks.sandbox.hdp.24.test/gateway/sandbox/solr/TestCollection/select?q=*.*&wt=json&indent=true");
+
+    input = Parser.parseLiteral(inputUri.toString());
+    pattern = Parser.parseTemplate("*://*:*/**/solr/{collection=**}/{query=**}?{**}");
+    template = Parser.parseTemplate("http://sandbox.hortonworks.com/solr/{collection=**}/{query=**}?{**}");
+
+    matcher = new Matcher<Void>();
+    matcher.add(pattern, null);
+    match = matcher.match(input);
+
+    outputUri = Expander.expand(template, match.getParams(), null);
+
+    final String reWrittenScheme = outputUri.getScheme();
+    assertEquals("http", reWrittenScheme);
+
+    final String reWrittenHost = outputUri.getHost();
+    assertEquals("sandbox.hortonworks.com", reWrittenHost);
+
+    final String reWrittenPath = outputUri.getPath();
+    assertEquals("/solr/TestCollection/select", reWrittenPath);
+
+    // Whole thing is (non-deterministicly ordered around the &s):
+    // "q=*.*&wt=json&indent=true"
+    final String reWrittenQuery = outputUri.getQuery();
+
+    // Check individual parameters are present, and have the right value.
+    final Map<String, String> reWrittenParams = mapUrlParameters(reWrittenQuery);
+    assertTrue(reWrittenParams.containsKey("q"));
+    assertEquals("*.*", reWrittenParams.get("q"));
+    assertTrue(reWrittenParams.containsKey("wt"));
+    assertEquals("json", reWrittenParams.get("wt"));
+    assertEquals("true", reWrittenParams.get("indent"));
+  }
+
+
   /**
    * Turn a string containing URL parameters, e.g.
    * 

http://git-wip-us.apache.org/repos/asf/knox/blob/ee332f57/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Matcher.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Matcher.java
b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Matcher.java
index 1ab30b4..f1268fe 100644
--- a/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Matcher.java
+++ b/gateway-util-urltemplate/src/main/java/org/apache/hadoop/gateway/util/urltemplate/Matcher.java
@@ -145,7 +145,11 @@ public class Matcher<V> {
     pickMatchingChildren( input.getUsername(), status );
     pickMatchingChildren( input.getPassword(), status );
     pickMatchingChildren( input.getHost(), status );
-    pickMatchingChildren( input.getPort(), status );
+    // port does not makes sense without host
+    if(input.getHost() != null) {
+      // port is optional, since default ports do not need to present in URL
+      pickMatchingOptionalSegment(input.getPort(), status);
+    }
     return status.hasCandidates();
   }
 
@@ -182,6 +186,26 @@ public class Matcher<V> {
     }
   }
 
+  /**
+   * optional segment, if it does not present (it is null) it is accepted
+   */
+  private void pickMatchingOptionalSegment( Segment segment, Status status ) {
+    for( MatchSegment parent : status.candidates ) {
+      if( parent.pathNode.children != null ) {
+        for( PathNode node : parent.pathNode.children.values() ) {
+          if( segment != null ) {
+            if( node.matches( segment ) ) {
+              status.matches.add( new MatchSegment( parent, node, node.segment, segment )
);
+            }
+          } else {
+            status.matches.add( new MatchSegment( parent, node, node.segment, segment ) );
+          }
+        }
+      }
+    }
+    status.swapMatchesToCandidates();
+  }
+
   private Match pickBestMatch( Template input, Status status ) {
     Match bestMatch = new Match( null, null );
     PathNode bestPath = null;

http://git-wip-us.apache.org/repos/asf/knox/blob/ee332f57/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/MatcherTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/MatcherTest.java
b/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/MatcherTest.java
index c568168..2e61f0c 100644
--- a/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/MatcherTest.java
+++ b/gateway-util-urltemplate/src/test/java/org/apache/hadoop/gateway/util/urltemplate/MatcherTest.java
@@ -308,6 +308,36 @@ public class MatcherTest {
   }
 
   @Test
+  public void testDefaultPortMatching() throws Exception {
+    Matcher<String> matcher = new Matcher<String>();
+    Template patternTemplate, inputTemplate;
+    Matcher<String>.Match match;
+
+    patternTemplate = Parser.parseTemplate( "*://*:*/{path=*}" );
+    matcher.add( patternTemplate, "test-match" );
+
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host" );
+    match = matcher.match( inputTemplate );
+    assertThat( match, nullValue() );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host/" );
+    match = matcher.match( inputTemplate );
+    assertThat( match, nullValue() );
+    inputTemplate = Parser.parseLiteral( "test-scheme://test-host/test-path" );
+    match = matcher.match( inputTemplate );
+    assertThat( match, notNullValue() );
+
+
+    inputTemplate = Parser.parseLiteral( "https://127.0.0.1/a1/a2/b/c1/c2/d" );
+    patternTemplate = Parser.parseTemplate( "*://*:*/{pathA=**}/b/{pathC=**}/d" );
+    matcher.add( patternTemplate, "webhdfs" );
+    match = matcher.match( inputTemplate );
+    assertThat( match, notNullValue() );
+    assertThat( match.getValue(), is( "webhdfs" ) );
+    assertThat( match.getParams().resolve( "pathA" ), hasItems( "a1", "a2" ) );
+    assertThat( match.getParams().resolve( "pathC" ), hasItems( "c1", "c2" ) );
+  }
+
+  @Test
   public void testTopLevelPathGlobMatch() throws Exception {
     Matcher<String> matcher;
     Template patternTemplate, inputTemplate;


Mime
View raw message