Skip to content

Commit 50b528e

Browse files
committed
refactor test
1 parent 45ef58b commit 50b528e

File tree

1 file changed

+16
-20
lines changed
  • runtime/protocol/http-client-engines/test-suite/jvm/test/aws/smithy/kotlin/runtime/http/test

1 file changed

+16
-20
lines changed

runtime/protocol/http-client-engines/test-suite/jvm/test/aws/smithy/kotlin/runtime/http/test/ConnectionTest.kt

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package aws.smithy.kotlin.runtime.http.test
66

77
import aws.smithy.kotlin.runtime.content.decodeToString
88
import aws.smithy.kotlin.runtime.http.*
9+
import aws.smithy.kotlin.runtime.http.engine.TlsContext
910
import aws.smithy.kotlin.runtime.http.engine.crt.CrtHttpEngineConfig
1011
import aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpEngineConfig
1112
import aws.smithy.kotlin.runtime.http.request.HttpRequest
@@ -26,8 +27,8 @@ import kotlin.time.Duration.Companion.seconds
2627
class ConnectionTest : AbstractEngineTest() {
2728
private fun testTlsConfigs(
2829
testName: String,
29-
tlsVersion: TlsVersion,
3030
serverType: ServerType,
31+
tlsContext: TlsContext = TlsContext {},
3132
okHttpConfigBlock: OkHttpEngineConfig.Builder.() -> Unit = {},
3233
crtConfigBlock: CrtHttpEngineConfig.Builder.() -> Unit = {},
3334
) {
@@ -36,9 +37,7 @@ class ConnectionTest : AbstractEngineTest() {
3637
testSslConfig.useAsSystemProperties {
3738
testEngines(skipEngines = setOf("CrtHttpEngine")) {
3839
engineConfig {
39-
tlsContext {
40-
minVersion = tlsVersion
41-
}
40+
this.tlsContext = tlsContext
4241

4342
if (this is OkHttpEngineConfig.Builder) {
4443
okHttpConfigBlock()
@@ -81,28 +80,31 @@ class ConnectionTest : AbstractEngineTest() {
8180

8281
@Test
8382
fun testMinTls1_2_vs_Tls_1_1() {
84-
val e = assertFailsWith<HttpException> { testTlsConfigs("testMinTls1_2", TlsVersion.TLS_1_2, ServerType.TLS_1_1) }
83+
val e = assertFailsWith<HttpException> {
84+
testTlsConfigs("testMinTls1_2", ServerType.TLS_1_1, TlsContext { minVersion = TlsVersion.TLS_1_2 })
85+
}
8586
assertEquals(HttpErrorCode.TLS_NEGOTIATION_ERROR, e.errorCode)
8687
}
87-
8888
@Test
89-
fun testMinTls1_2() = testTlsConfigs("testMinTls1_2", TlsVersion.TLS_1_2, ServerType.TLS_1_2)
89+
fun testMinTls1_2() = testTlsConfigs("testMinTls1_2", ServerType.TLS_1_2, TlsContext { minVersion = TlsVersion.TLS_1_2 })
9090

9191
@Test
9292
fun testMinTls1_3_vs_Tls_1_2() {
93-
val e = assertFailsWith<HttpException> { testTlsConfigs("testMinTls1_3_vs_Tls_1_2", TlsVersion.TLS_1_3, ServerType.TLS_1_2) }
93+
val e = assertFailsWith<HttpException> {
94+
testTlsConfigs("testMinTls1_3_vs_Tls_1_2", ServerType.TLS_1_2, TlsContext { minVersion = TlsVersion.TLS_1_3 })
95+
}
9496
assertEquals(HttpErrorCode.TLS_NEGOTIATION_ERROR, e.errorCode)
9597
}
9698

9799
@Test
98-
fun testMinTls1_3() = testTlsConfigs("testMinTls1_3", TlsVersion.TLS_1_3, ServerType.TLS_1_3)
100+
fun testMinTls1_3() = testTlsConfigs("testMinTls1_3", ServerType.TLS_1_3, TlsContext { minVersion = TlsVersion.TLS_1_3 })
99101

100102
@Test
101103
fun testTrustManagerWithTls1_2() {
102104
testTlsConfigs(
103105
"testTrustManagerWithTls1_2",
104-
TlsVersion.TLS_1_2,
105106
ServerType.TLS_1_2,
107+
TlsContext { minVersion = TlsVersion.TLS_1_2 },
106108
okHttpConfigBlock = {
107109
trustManagerProvider = createTestTrustManagerProvider(testCert)
108110
},
@@ -113,8 +115,8 @@ class ConnectionTest : AbstractEngineTest() {
113115
fun testTrustManagerWithTls1_3() {
114116
testTlsConfigs(
115117
"testTrustManagerWithTls1_3",
116-
TlsVersion.TLS_1_3,
117118
ServerType.TLS_1_3,
119+
TlsContext { minVersion = TlsVersion.TLS_1_3 },
118120
okHttpConfigBlock = {
119121
trustManagerProvider = createTestTrustManagerProvider(testCert)
120122
},
@@ -128,8 +130,8 @@ class ConnectionTest : AbstractEngineTest() {
128130
fun testCipherSuitesWithTls1_2() {
129131
testTlsConfigs(
130132
"testCipherSuitesWithTls1_2",
131-
TlsVersion.TLS_1_2,
132133
ServerType.TLS_1_2,
134+
TlsContext { minVersion = TlsVersion.TLS_1_2 },
133135
okHttpConfigBlock = {
134136
cipherSuites = listOf("TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384")
135137
},
@@ -142,8 +144,8 @@ class ConnectionTest : AbstractEngineTest() {
142144
val e = assertFailsWith<HttpException> {
143145
testTlsConfigs(
144146
"testCipherSuitesWithTls1_3",
145-
TlsVersion.TLS_1_3,
146147
ServerType.TLS_1_3,
148+
TlsContext { minVersion = TlsVersion.TLS_1_3 },
147149
okHttpConfigBlock = {
148150
cipherSuites = listOf("TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384")
149151
},
@@ -154,8 +156,8 @@ class ConnectionTest : AbstractEngineTest() {
154156
// test cipher suites compatible with Tls1_3
155157
testTlsConfigs(
156158
"testCipherSuitesWithTls1_3",
157-
TlsVersion.TLS_1_3,
158159
ServerType.TLS_1_3,
160+
TlsContext { minVersion = TlsVersion.TLS_1_3 },
159161
okHttpConfigBlock = {
160162
cipherSuites = listOf("TLS_AES_256_GCM_SHA384", "TLS_AES_128_GCM_SHA256")
161163
},
@@ -166,7 +168,6 @@ class ConnectionTest : AbstractEngineTest() {
166168
fun testHostnameVerifier() {
167169
testTlsConfigs(
168170
"testHostnameVerifier",
169-
TlsVersion.TLS_1_2,
170171
ServerType.TLS_1_2,
171172
okHttpConfigBlock = {
172173
hostnameVerifier = HostnameVerifier { hostname, _ ->
@@ -180,7 +181,6 @@ class ConnectionTest : AbstractEngineTest() {
180181
fun testCertificatePinner() {
181182
testTlsConfigs(
182183
"testCertificatePinner",
183-
TlsVersion.TLS_1_2,
184184
ServerType.TLS_1_2,
185185
okHttpConfigBlock = {
186186
certificatePinner = createTestCertificatePinner(testCert, ServerType.TLS_1_2)
@@ -192,7 +192,6 @@ class ConnectionTest : AbstractEngineTest() {
192192
fun testCaRoot() {
193193
testTlsConfigs(
194194
"testCaRoot",
195-
TlsVersion.TLS_1_2,
196195
ServerType.TLS_1_2,
197196
crtConfigBlock = {
198197
caRoot = createTestPemCert(testCert)
@@ -207,7 +206,6 @@ class ConnectionTest : AbstractEngineTest() {
207206
tempFile.writeText(createTestPemCert(testCert))
208207
testTlsConfigs(
209208
"testCaFile",
210-
TlsVersion.TLS_1_2,
211209
ServerType.TLS_1_2,
212210
crtConfigBlock = {
213211
caFile = tempFile.absolutePath
@@ -227,7 +225,6 @@ class ConnectionTest : AbstractEngineTest() {
227225

228226
testTlsConfigs(
229227
"testCaDir",
230-
TlsVersion.TLS_1_2,
231228
ServerType.TLS_1_2,
232229
crtConfigBlock = {
233230
caDir = tempDir.absolutePath
@@ -242,7 +239,6 @@ class ConnectionTest : AbstractEngineTest() {
242239
fun testVerifyPeerFalse() {
243240
testTlsConfigs(
244241
"testVerifyPeers",
245-
TlsVersion.TLS_1_2,
246242
ServerType.TLS_1_2,
247243
crtConfigBlock = {
248244
caRoot = createInvalidTestPemCert()

0 commit comments

Comments
 (0)