You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2019/06/27 15:33:31 UTC

[httpcomponents-client] branch master updated: HTTPCLIENT-1997: Return the last domain segment instead of normalized domain name from PublicSuffixMatcher#getDomainRoot in case there is no match

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/master by this push:
     new 19a87e0  HTTPCLIENT-1997: Return the last domain segment instead of normalized domain name from PublicSuffixMatcher#getDomainRoot in case there is no match
19a87e0 is described below

commit 19a87e0c772558231e571f99e0a05c0f32ff18eb
Author: jeromedemangel <je...@gmail.com>
AuthorDate: Wed Jun 26 14:45:31 2019 +0200

    HTTPCLIENT-1997: Return the last domain segment instead of normalized domain name from PublicSuffixMatcher#getDomainRoot in case there is no match
---
 .../org/apache/hc/client5/http/psl/PublicSuffixMatcher.java  |  2 +-
 .../apache/hc/client5/http/psl/TestPublicSuffixMatcher.java  |  4 +++-
 .../hc/client5/http/ssl/TestDefaultHostnameVerifier.java     | 12 ++++++++++++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixMatcher.java b/httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixMatcher.java
index 4ddaf00..29c50dc 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixMatcher.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixMatcher.java
@@ -171,7 +171,7 @@ public final class PublicSuffixMatcher {
             result = segment;
             segment = nextSegment;
         }
-        return normalized;
+        return result;
     }
 
     /**
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/psl/TestPublicSuffixMatcher.java b/httpclient5/src/test/java/org/apache/hc/client5/http/psl/TestPublicSuffixMatcher.java
index bf6a2e6..071d4cc 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/psl/TestPublicSuffixMatcher.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/psl/TestPublicSuffixMatcher.java
@@ -69,7 +69,9 @@ public class TestPublicSuffixMatcher {
         Assert.assertEquals("blah.blah.tokyo.jp", matcher.getDomainRoot("blah.blah.tokyo.jp"));
         Assert.assertEquals("blah.ac.jp", matcher.getDomainRoot("blah.blah.ac.jp"));
         Assert.assertEquals("garbage", matcher.getDomainRoot("garbage"));
-        Assert.assertEquals("garbage.garbage", matcher.getDomainRoot("garbage.garbage"));
+        Assert.assertEquals("garbage", matcher.getDomainRoot("garbage.garbage"));
+        Assert.assertEquals("garbage", matcher.getDomainRoot("*.garbage.garbage"));
+        Assert.assertEquals("garbage", matcher.getDomainRoot("*.garbage.garbage.garbage"));
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestDefaultHostnameVerifier.java b/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestDefaultHostnameVerifier.java
index 732451f..bd961d3 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestDefaultHostnameVerifier.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestDefaultHostnameVerifier.java
@@ -275,6 +275,18 @@ public class TestDefaultHostnameVerifier {
         Assert.assertTrue(DefaultHostnameVerifier.matchIdentityStrict("mail.a.b.c.com", "m*.a.b.c.com"));
     }
 
+    @Test
+    public void testHTTPCLIENT_1997() {
+        Assert.assertTrue(DefaultHostnameVerifier.matchIdentity(
+                "service.apps.dev.b.cloud.a", "*.apps.dev.b.cloud.a"));
+        Assert.assertTrue(DefaultHostnameVerifier.matchIdentityStrict(
+                "service.apps.dev.b.cloud.a", "*.apps.dev.b.cloud.a"));
+        Assert.assertTrue(DefaultHostnameVerifier.matchIdentity(
+                "service.apps.dev.b.cloud.a", "*.apps.dev.b.cloud.a", publicSuffixMatcher));
+        Assert.assertTrue(DefaultHostnameVerifier.matchIdentityStrict(
+                "service.apps.dev.b.cloud.a", "*.apps.dev.b.cloud.a", publicSuffixMatcher));
+    }
+
     @Test // Check compressed IPv6 hostname matching
     public void testHTTPCLIENT_1316() throws Exception{
         final String host1 = "2001:0db8:aaaa:bbbb:cccc:0:0:0001";