hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1666010 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/auth/AuthScope.java test/java/org/apache/http/auth/TestAuthScope.java test/java/org/apache/http/impl/client/TestBasicCredentialsProvider.java
Date Wed, 11 Mar 2015 20:54:11 GMT
Author: olegk
Date: Wed Mar 11 20:54:11 2015
New Revision: 1666010

URL: http://svn.apache.org/r1666010
Log:
HTTPCLIENT-1628: Auth cache can fail when domain name contains uppercase characters
Contributed by Dennis Ju <dejuknow at gmail.com>

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthScope.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestAuthScope.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCredentialsProvider.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthScope.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthScope.java?rev=1666010&r1=1666009&r2=1666010&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthScope.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthScope.java
Wed Mar 11 20:54:11 2015
@@ -129,7 +129,7 @@ public class AuthScope {
             final String realm,
             final String schemeName) {
         Args.notNull(origin, "Host");
-        this.host = origin.getHostName();
+        this.host = origin.getHostName().toLowerCase(Locale.ROOT);
         this.port = origin.getPort() < 0 ? ANY_PORT : origin.getPort();
         this.realm = realm == null ? ANY_REALM : realm;
         this.scheme = schemeName == null ? ANY_SCHEME : schemeName.toUpperCase(Locale.ROOT);

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestAuthScope.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestAuthScope.java?rev=1666010&r1=1666009&r2=1666010&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestAuthScope.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/auth/TestAuthScope.java
Wed Mar 11 20:54:11 2015
@@ -88,6 +88,23 @@ public class TestAuthScope {
     }
 
     @Test
+    public void testMixedCaseHostname() {
+        final AuthScope authscope = new AuthScope("SomeHost", 80);
+        Assert.assertEquals(null, authscope.getScheme());
+        Assert.assertEquals("somehost", authscope.getHost());
+        Assert.assertEquals(80, authscope.getPort());
+        Assert.assertEquals(null, authscope.getRealm());
+        Assert.assertEquals("<any realm>@somehost:80", authscope.toString());
+    }
+
+    public void testByOriginMixedCaseHostname() throws Exception {
+        final HttpHost host = new HttpHost("SomeHost", 8080, "http");
+        final AuthScope authscope = new AuthScope(host);
+        Assert.assertEquals("somehost", authscope.getHost());
+        Assert.assertEquals(host, authscope.getOrigin());
+    }
+
+    @Test
     public void testBasicsOptionalHost() {
         final AuthScope authscope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT,
AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);
         Assert.assertEquals(null, authscope.getScheme());

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCredentialsProvider.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCredentialsProvider.java?rev=1666010&r1=1666009&r2=1666010&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCredentialsProvider.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestBasicCredentialsProvider.java
Wed Mar 11 20:54:11 2015
@@ -26,6 +26,7 @@
  */
 package org.apache.http.impl.client;
 
+import org.apache.http.HttpHost;
 import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.Credentials;
 import org.apache.http.auth.UsernamePasswordCredentials;
@@ -125,6 +126,16 @@ public class TestBasicCredentialsProvide
     }
 
     @Test
+    public void testMixedCaseHostname() throws Exception {
+        final HttpHost httpHost = new HttpHost("hOsT", 80);
+        final BasicCredentialsProvider state = new BasicCredentialsProvider();
+        final Credentials expected = new UsernamePasswordCredentials("name", "pass");
+        state.setCredentials(new AuthScope(httpHost), expected);
+        final Credentials got = state.getCredentials(DEFSCOPE);
+        Assert.assertEquals(expected, got);
+    }
+
+    @Test
     public void testCredentialsMatching() {
         final Credentials creds1 = new UsernamePasswordCredentials("name1", "pass1");
         final Credentials creds2 = new UsernamePasswordCredentials("name2", "pass2");



Mime
View raw message