mirror of
https://github.com/square/okhttp.git
synced 2025-08-07 12:42:57 +03:00
Quick Android Test Fixes (#6428)
This commit is contained in:
@@ -284,6 +284,7 @@ open class PlatformRule @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
fun assumeJdkVersion(majorVersion: Int) {
|
||||
assumeNotAndroid()
|
||||
assumeTrue(PlatformVersion.majorVersion == majorVersion)
|
||||
}
|
||||
|
||||
|
@@ -17,6 +17,7 @@ dependencies {
|
||||
compileOnly deps.animalSniffer
|
||||
|
||||
testImplementation project(':okhttp-testing-support')
|
||||
testImplementation project(':mockwebserver-junit5')
|
||||
testImplementation deps.junit
|
||||
testImplementation deps.assertj
|
||||
}
|
||||
|
@@ -76,7 +76,7 @@ dependencies {
|
||||
testImplementation project(':okhttp-urlconnection')
|
||||
testImplementation project(':mockwebserver')
|
||||
testImplementation project(':mockwebserver-junit4')
|
||||
testRuntimeOnly project(':mockwebserver-junit5')
|
||||
testImplementation project(':mockwebserver-junit5')
|
||||
testImplementation project(':mockwebserver-deprecated')
|
||||
testImplementation project(':okhttp-logging-interceptor')
|
||||
testImplementation project(':okhttp-brotli')
|
||||
|
@@ -21,6 +21,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import okhttp3.UrlComponentEncodingTester.Component;
|
||||
import okhttp3.UrlComponentEncodingTester.Encoding;
|
||||
import okhttp3.testing.PlatformRule;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -33,6 +34,8 @@ import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public final class HttpUrlTest {
|
||||
public final PlatformRule platform = new PlatformRule();
|
||||
|
||||
@Parameterized.Parameters(name = "Use get = {0}")
|
||||
public static Collection<Object[]> parameters() {
|
||||
return asList(
|
||||
@@ -1511,6 +1514,9 @@ public final class HttpUrlTest {
|
||||
}
|
||||
|
||||
@Test public void fromJavaNetUrlUnsupportedScheme() throws Exception {
|
||||
// java.net.MalformedURLException: unknown protocol: mailto
|
||||
platform.assumeNotAndroid();
|
||||
|
||||
URL javaNetUrl = new URL("mailto:user@example.com");
|
||||
assertThat(HttpUrl.get(javaNetUrl)).isNull();
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ package okhttp3;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
import okhttp3.internal.platform.Platform;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
@@ -184,8 +185,13 @@ public class MediaTypeTest {
|
||||
|
||||
@Test public void testCharsetNameIsDoubleQuotedAndSingleQuoted() throws Exception {
|
||||
MediaType mediaType = parse("text/plain;charset=\"'utf-8'\"");
|
||||
if (Platform.Companion.isAndroid()) {
|
||||
// Charset.forName("'utf-8'") == UTF-8
|
||||
assertThat(mediaType.charset().name()).isEqualTo("UTF-8");
|
||||
} else {
|
||||
assertThat(mediaType.charset()).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void testCharsetNameIsDoubleQuotedSingleQuote() throws Exception {
|
||||
MediaType mediaType = parse("text/plain;charset=\"'\"");
|
||||
|
@@ -41,6 +41,7 @@ import okhttp3.Protocol;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Route;
|
||||
import okhttp3.internal.http.RecordingProxySelector;
|
||||
import okhttp3.internal.platform.Platform;
|
||||
import okhttp3.testing.PlatformRule;
|
||||
import okhttp3.testing.PlatformVersion;
|
||||
import okhttp3.tls.HandshakeCertificates;
|
||||
@@ -470,10 +471,13 @@ public final class RouteSelectorTest {
|
||||
@Test public void routeToString() throws Exception {
|
||||
Route route = new Route(httpAddress(), Proxy.NO_PROXY,
|
||||
InetSocketAddress.createUnresolved("host", 1234));
|
||||
assertThat(route.toString()).isEqualTo(
|
||||
PlatformVersion.INSTANCE.getMajorVersion() >= 14
|
||||
? "Route{host/<unresolved>:1234}"
|
||||
: "Route{host:1234}");
|
||||
String expected;
|
||||
if (Platform.Companion.isAndroid() || PlatformVersion.INSTANCE.getMajorVersion() < 14) {
|
||||
expected = "Route{host:1234}";
|
||||
} else {
|
||||
expected = "Route{host/<unresolved>:1234}";
|
||||
}
|
||||
assertThat(route.toString()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
private void assertRoute(Route route, Address address, Proxy proxy, InetAddress socketAddress,
|
||||
|
@@ -34,6 +34,7 @@ import javax.net.ssl.X509TrustManager;
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
import mockwebserver3.MockResponse;
|
||||
import mockwebserver3.MockWebServer;
|
||||
import mockwebserver3.junit5.internal.MockWebServerExtension;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.OkHttpClientTestRule;
|
||||
@@ -47,6 +48,7 @@ import okhttp3.tls.HandshakeCertificates;
|
||||
import okhttp3.tls.HeldCertificate;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
@@ -56,6 +58,7 @@ import static okhttp3.tls.internal.TlsUtil.newTrustManager;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
@ExtendWith(MockWebServerExtension.class)
|
||||
public final class ClientAuthTest {
|
||||
@RegisterExtension public final PlatformRule platform = new PlatformRule();
|
||||
@RegisterExtension public final OkHttpClientTestRule clientTestRule = new OkHttpClientTestRule();
|
||||
|
@@ -30,6 +30,7 @@ import javax.security.auth.x500.X500Principal;
|
||||
import okhttp3.FakeSSLSession;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.internal.Util;
|
||||
import okhttp3.internal.platform.Platform;
|
||||
import okhttp3.testing.PlatformRule;
|
||||
import okhttp3.tls.HeldCertificate;
|
||||
import okhttp3.tls.internal.TlsUtil;
|
||||
@@ -189,7 +190,7 @@ public final class HostnameVerifierTest {
|
||||
+ "-----END CERTIFICATE-----\n");
|
||||
|
||||
X509Certificate peerCertificate = ((X509Certificate) session.getPeerCertificates()[0]);
|
||||
if (platform.isConscrypt()) {
|
||||
if (Platform.Companion.isAndroid() || platform.isConscrypt()) {
|
||||
assertThat(certificateSANs(peerCertificate)).containsExactly("bar.com");
|
||||
} else {
|
||||
assertThat(certificateSANs(peerCertificate)).containsExactly("bar.com", "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.co.jp");
|
||||
@@ -382,7 +383,7 @@ public final class HostnameVerifierTest {
|
||||
+ "-----END CERTIFICATE-----\n");
|
||||
|
||||
X509Certificate peerCertificate = ((X509Certificate) session.getPeerCertificates()[0]);
|
||||
if (platform.isConscrypt()) {
|
||||
if (Platform.Companion.isAndroid() || platform.isConscrypt()) {
|
||||
assertThat(certificateSANs(peerCertificate)).containsExactly("*.bar.com");
|
||||
} else {
|
||||
assertThat(certificateSANs(peerCertificate)).containsExactly("*.bar.com", "*.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.co.jp");
|
||||
@@ -660,7 +661,11 @@ public final class HostnameVerifierTest {
|
||||
+ "-----END CERTIFICATE-----\n");
|
||||
|
||||
X509Certificate peerCertificate = ((X509Certificate) session.getPeerCertificates()[0]);
|
||||
if (Platform.Companion.isAndroid()) {
|
||||
assertThat(certificateSANs(peerCertificate)).containsExactly();
|
||||
} else {
|
||||
assertThat(certificateSANs(peerCertificate)).containsExactly("<EFBFBD><EFBFBD><EFBFBD>.com", "<EFBFBD><EFBFBD><EFBFBD>.com");
|
||||
}
|
||||
|
||||
assertThat(verifier.verify("tel.com", session)).isFalse();
|
||||
assertThat(verifier.verify("k.com", session)).isFalse();
|
||||
|
Reference in New Issue
Block a user