diff --git a/android-test/build.gradle b/android-test/build.gradle index d521be679162..fb245ae02c6b 100644 --- a/android-test/build.gradle +++ b/android-test/build.gradle @@ -39,4 +39,6 @@ dependencies { androidTestImplementation project(':okhttp-tls') androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + androidTestImplementation 'com.squareup.moshi:moshi:1.8.0' + androidTestImplementation 'com.squareup.moshi:moshi-kotlin:1.8.0' } diff --git a/android-test/src/androidTest/java/okhttp/android/test/OkHttpTest.kt b/android-test/src/androidTest/java/okhttp/android/test/OkHttpTest.kt index 3aec4cab3763..30461171423d 100644 --- a/android-test/src/androidTest/java/okhttp/android/test/OkHttpTest.kt +++ b/android-test/src/androidTest/java/okhttp/android/test/OkHttpTest.kt @@ -17,6 +17,8 @@ package okhttp.android.test import android.os.Build import android.support.test.runner.AndroidJUnit4 +import com.squareup.moshi.Moshi +import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import okhttp3.Call import okhttp3.CertificatePinner import okhttp3.Connection @@ -26,6 +28,7 @@ import okhttp3.Protocol import okhttp3.RecordingEventListener import okhttp3.Request import okhttp3.TlsVersion +import okhttp3.internal.platform.Platform import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer import okhttp3.tls.internal.TlsUtil.localhost @@ -37,6 +40,7 @@ import org.junit.Assert.fail import org.junit.Assume.assumeNoException import org.junit.Assume.assumeTrue import org.junit.Before +import org.junit.Ignore import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -52,6 +56,10 @@ import javax.net.ssl.SSLSocket class OkHttpTest { private lateinit var client: OkHttpClient + private val moshi = Moshi.Builder() + .add(KotlinJsonAdapterFactory()) + .build() + @JvmField @Rule val server = MockWebServer() @@ -137,6 +145,44 @@ class OkHttpTest { } } + data class HowsMySslResults( + val unknown_cipher_suite_supported: Boolean, + val beast_vuln: Boolean, + val session_ticket_supported: Boolean, + val tls_compression_supported: Boolean, + val ephemeral_keys_supported: Boolean, + val rating: String, + val tls_version: String, + val able_to_detect_n_minus_one_splitting: Boolean, + val insecure_cipher_suites: Map>, + val given_cipher_suites: List? + ) + + @Test + @Ignore + fun testSSLFeatures() { + assumeNetwork() + + val request = Request.Builder().url("https://www.howsmyssl.com/a/check").build() + + val response = client.newCall(request).execute() + + val results = response.use { + moshi.adapter(HowsMySslResults::class.java).fromJson(response.body!!.string())!! + } + + Platform.get().log(Platform.WARN, "results $results", null) + + assertTrue(results.session_ticket_supported) + assertEquals("Probably Okay", results.rating) + // TODO map to expected versions automatically, test ignored for now. Run manually. + assertEquals("TLS 1.3", results.tls_version) + assertEquals(0, results.insecure_cipher_suites.size) + + assertEquals(TlsVersion.TLS_1_3, response.handshake?.tlsVersion) + assertEquals(Protocol.HTTP_2, response.protocol) + } + @Test fun testMockWebserverRequest() { enableTls()