HTTPCLIENT-1628: Auth cache can fail when domain name contains uppercase characters
Contributed by Dennis Ju <dejuknow at gmail.com> git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1666010 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f1e0f669f1
commit
d85679d2a1
|
@ -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);
|
||||
|
|
|
@ -87,6 +87,23 @@ public class TestAuthScope {
|
|||
Assert.assertEquals("<any realm>@somehost:8080", authscope.toString());
|
||||
}
|
||||
|
||||
@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);
|
||||
|
|
|
@ -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;
|
||||
|
@ -124,6 +125,16 @@ public class TestBasicCredentialsProvider {
|
|||
Assert.assertNotSame(cred, got);
|
||||
}
|
||||
|
||||
@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");
|
||||
|
|
Loading…
Reference in New Issue