HTTPCLIENT-1997: Return the last domain segment instead of normalized domain name from PublicSuffixMatcher#getDomainRoot in case there is no match

This commit is contained in:
jeromedemangel 2019-06-26 14:45:31 +02:00 committed by Oleg Kalnichevski
parent 9e6287c88b
commit 19a87e0c77
3 changed files with 16 additions and 2 deletions

View File

@ -171,7 +171,7 @@ public final class PublicSuffixMatcher {
result = segment; result = segment;
segment = nextSegment; segment = nextSegment;
} }
return normalized; return result;
} }
/** /**

View File

@ -69,7 +69,9 @@ public class TestPublicSuffixMatcher {
Assert.assertEquals("blah.blah.tokyo.jp", matcher.getDomainRoot("blah.blah.tokyo.jp")); 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("blah.ac.jp", matcher.getDomainRoot("blah.blah.ac.jp"));
Assert.assertEquals("garbage", matcher.getDomainRoot("garbage")); 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 @Test

View File

@ -275,6 +275,18 @@ public class TestDefaultHostnameVerifier {
Assert.assertTrue(DefaultHostnameVerifier.matchIdentityStrict("mail.a.b.c.com", "m*.a.b.c.com")); 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 @Test // Check compressed IPv6 hostname matching
public void testHTTPCLIENT_1316() throws Exception{ public void testHTTPCLIENT_1316() throws Exception{
final String host1 = "2001:0db8:aaaa:bbbb:cccc:0:0:0001"; final String host1 = "2001:0db8:aaaa:bbbb:cccc:0:0:0001";