1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-24 04:02:07 +03:00

Fix a bug where authentication was incorrectly case sensitive.

This commit is contained in:
jwilson
2013-11-03 13:58:08 -05:00
parent 43a7c604c9
commit f2a6a6496f
2 changed files with 21 additions and 8 deletions

View File

@@ -39,7 +39,7 @@ public final class HttpAuthenticator {
@Override public Credential authenticate(
Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
for (Challenge challenge : challenges) {
if (!"Basic".equals(challenge.getScheme())) {
if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
continue;
}
@@ -56,7 +56,7 @@ public final class HttpAuthenticator {
@Override public Credential authenticateProxy(
Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
for (Challenge challenge : challenges) {
if (!"Basic".equals(challenge.getScheme())) {
if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
continue;
}
@@ -146,7 +146,7 @@ public final class HttpAuthenticator {
// It needs to be fixed to handle any scheme and any parameters
// http://code.google.com/p/android/issues/detail?id=11140
if (!value.regionMatches(pos, "realm=\"", 0, "realm=\"".length())) {
if (!value.regionMatches(true, pos, "realm=\"", 0, "realm=\"".length())) {
break; // Unexpected challenge parameter; give up!
}

View File

@@ -16,16 +16,16 @@
package com.squareup.okhttp.internal.http;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import com.squareup.okhttp.mockwebserver.RecordedRequest;
import com.squareup.okhttp.mockwebserver.SocketPolicy;
import com.squareup.okhttp.HttpResponseCache;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.internal.RecordingAuthenticator;
import com.squareup.okhttp.internal.RecordingHostnameVerifier;
import com.squareup.okhttp.internal.RecordingOkAuthenticator;
import com.squareup.okhttp.internal.SslContextBuilder;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import com.squareup.okhttp.mockwebserver.RecordedRequest;
import com.squareup.okhttp.mockwebserver.SocketPolicy;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
@@ -76,11 +76,11 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import static com.squareup.okhttp.OkAuthenticator.Credential;
import static com.squareup.okhttp.mockwebserver.SocketPolicy.DISCONNECT_AT_END;
import static com.squareup.okhttp.mockwebserver.SocketPolicy.DISCONNECT_AT_START;
import static com.squareup.okhttp.mockwebserver.SocketPolicy.SHUTDOWN_INPUT_AT_END;
import static com.squareup.okhttp.mockwebserver.SocketPolicy.SHUTDOWN_OUTPUT_AT_END;
import static com.squareup.okhttp.OkAuthenticator.Credential;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@@ -1480,6 +1480,19 @@ public final class URLConnectionTest {
}
}
/** https://github.com/square/okhttp/issues/342 */
@Test public void authenticateRealmUppercase() throws Exception {
server.enqueue(new MockResponse().setResponseCode(401)
.addHeader("wWw-aUtHeNtIcAtE: bAsIc rEaLm=\"pRoTeCtEd aReA\"")
.setBody("Please authenticate."));
server.enqueue(new MockResponse().setBody("Successful auth!"));
server.play();
Authenticator.setDefault(new RecordingAuthenticator());
HttpURLConnection connection = client.open(server.getUrl("/"));
assertEquals("Successful auth!", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
}
@Test public void redirectedWithChunkedEncoding() throws Exception {
testRedirected(TransferKind.CHUNKED, true);
}