Skip to content

Commit

Permalink
Hows My Ssl test for Android (#5428)
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke authored Sep 9, 2019
1 parent 3464ef3 commit 2cdbbda
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions android-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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<String, List<String>>,
val given_cipher_suites: List<String>?
)

@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()
Expand Down

0 comments on commit 2cdbbda

Please sign in to comment.