Skip to content

Commit b534927

Browse files
committed
Drop support for http body dot bytes response checksums
1 parent d498e30 commit b534927

File tree

2 files changed

+59
-14
lines changed

2 files changed

+59
-14
lines changed

tests/codegen/checksums/src/commonTest/kotlin/aws/sdk/kotlin/tests/codegen/checksums/ChecksumConfigTest.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import aws.smithy.kotlin.runtime.http.HttpStatusCode
1919
import aws.smithy.kotlin.runtime.http.interceptors.ChecksumMismatchException
2020
import aws.smithy.kotlin.runtime.http.response.HttpResponse
2121
import aws.smithy.kotlin.runtime.httptest.TestEngine
22+
import aws.smithy.kotlin.runtime.io.SdkSource
23+
import aws.smithy.kotlin.runtime.io.source
2224
import aws.smithy.kotlin.runtime.time.Instant
2325
import kotlinx.coroutines.runBlocking
2426
import kotlin.test.Test
@@ -270,6 +272,8 @@ class UserProvidedChecksumHeader {
270272
* Tests the `aws.protocols#httpChecksum` trait's `requestValidationModeMember`.
271273
*/
272274
class ResponseChecksumValidation {
275+
private val responseBody = "Hello world"
276+
273277
@Test
274278
fun responseChecksumValidationWhenSupported(): Unit = runBlocking {
275279
assertFailsWith<ChecksumMismatchException> {
@@ -282,7 +286,11 @@ class ResponseChecksumValidation {
282286
Headers {
283287
append("x-amz-checksum-crc32", "I will trigger `ChecksumMismatchException` if read!")
284288
},
285-
"World!".toHttpBody(),
289+
object : HttpBody.SourceContent() {
290+
override val isOneShot: Boolean = false
291+
override val contentLength: Long? = responseBody.length.toLong()
292+
override fun readFrom(): SdkSource = responseBody.toByteArray().source()
293+
},
286294
)
287295
val now = Instant.now()
288296
HttpCall(request, resp, now, now)
@@ -340,7 +348,11 @@ class ResponseChecksumValidation {
340348
Headers {
341349
append("x-amz-checksum-crc32", "I will trigger `ChecksumMismatchException` if read!")
342350
},
343-
"World!".toHttpBody(),
351+
object : HttpBody.SourceContent() {
352+
override val isOneShot: Boolean = false
353+
override val contentLength: Long? = responseBody.length.toLong()
354+
override fun readFrom(): SdkSource = responseBody.toByteArray().source()
355+
},
344356
)
345357
val now = Instant.now()
346358
HttpCall(request, resp, now, now)

tests/codegen/checksums/src/commonTest/kotlin/aws/sdk/kotlin/tests/codegen/checksums/ChecksumResponseTest.kt

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ package aws.sdk.kotlin.tests.codegen.checksums
88
import aws.sdk.kotlin.runtime.auth.credentials.StaticCredentialsProvider
99
import aws.sdk.kotlin.test.checksums.*
1010
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
11-
import aws.smithy.kotlin.runtime.http.Headers
12-
import aws.smithy.kotlin.runtime.http.HttpCall
13-
import aws.smithy.kotlin.runtime.http.HttpStatusCode
11+
import aws.smithy.kotlin.runtime.http.*
1412
import aws.smithy.kotlin.runtime.http.interceptors.ChecksumMismatchException
1513
import aws.smithy.kotlin.runtime.http.response.HttpResponse
16-
import aws.smithy.kotlin.runtime.http.toHttpBody
1714
import aws.smithy.kotlin.runtime.httptest.TestEngine
15+
import aws.smithy.kotlin.runtime.io.SdkSource
16+
import aws.smithy.kotlin.runtime.io.source
1817
import aws.smithy.kotlin.runtime.time.Instant
1918
import kotlinx.coroutines.runBlocking
2019
import kotlin.test.Test
2120
import kotlin.test.assertFailsWith
2221

22+
private val responseBody = "Hello world"
23+
2324
class SuccessfulChecksumResponseTest {
2425
@Test
2526
fun crc32(): Unit = runBlocking {
@@ -31,7 +32,11 @@ class SuccessfulChecksumResponseTest {
3132
Headers {
3233
append("x-amz-checksum-crc32", "i9aeUg==")
3334
},
34-
"Hello world".toHttpBody(),
35+
object : HttpBody.SourceContent() {
36+
override val isOneShot: Boolean = false
37+
override val contentLength: Long? = responseBody.length.toLong()
38+
override fun readFrom(): SdkSource = responseBody.toByteArray().source()
39+
},
3540
)
3641
val now = Instant.now()
3742
HttpCall(request, resp, now, now)
@@ -58,7 +63,11 @@ class SuccessfulChecksumResponseTest {
5863
Headers {
5964
append("x-amz-checksum-crc32c", "crUfeA==")
6065
},
61-
"Hello world".toHttpBody(),
66+
object : HttpBody.SourceContent() {
67+
override val isOneShot: Boolean = false
68+
override val contentLength: Long? = responseBody.length.toLong()
69+
override fun readFrom(): SdkSource = responseBody.toByteArray().source()
70+
},
6271
)
6372
val now = Instant.now()
6473
HttpCall(request, resp, now, now)
@@ -85,7 +94,11 @@ class SuccessfulChecksumResponseTest {
8594
Headers {
8695
append("x-amz-checksum-sha1", "e1AsOh9IyGCa4hLN+2Od7jlnP14=")
8796
},
88-
"Hello world".toHttpBody(),
97+
object : HttpBody.SourceContent() {
98+
override val isOneShot: Boolean = false
99+
override val contentLength: Long? = responseBody.length.toLong()
100+
override fun readFrom(): SdkSource = responseBody.toByteArray().source()
101+
},
89102
)
90103
val now = Instant.now()
91104
HttpCall(request, resp, now, now)
@@ -112,7 +125,11 @@ class SuccessfulChecksumResponseTest {
112125
Headers {
113126
append("x-amz-checksum-sha256", "ZOyIygCyaOW6GjVnihtTFtIS9PNmskdyMlNKiuyjfzw=")
114127
},
115-
"Hello world".toHttpBody(),
128+
object : HttpBody.SourceContent() {
129+
override val isOneShot: Boolean = false
130+
override val contentLength: Long? = responseBody.length.toLong()
131+
override fun readFrom(): SdkSource = responseBody.toByteArray().source()
132+
},
116133
)
117134
val now = Instant.now()
118135
HttpCall(request, resp, now, now)
@@ -142,7 +159,11 @@ class FailedChecksumResponseTest {
142159
Headers {
143160
append("x-amz-checksum-crc32", "bm90LWEtY2hlY2tzdW0=")
144161
},
145-
"Hello world".toHttpBody(),
162+
object : HttpBody.SourceContent() {
163+
override val isOneShot: Boolean = false
164+
override val contentLength: Long? = responseBody.length.toLong()
165+
override fun readFrom(): SdkSource = responseBody.toByteArray().source()
166+
},
146167
)
147168
val now = Instant.now()
148169
HttpCall(request, resp, now, now)
@@ -171,7 +192,11 @@ class FailedChecksumResponseTest {
171192
Headers {
172193
append("x-amz-checksum-crc32c", "bm90LWEtY2hlY2tzdW0=")
173194
},
174-
"Hello world".toHttpBody(),
195+
object : HttpBody.SourceContent() {
196+
override val isOneShot: Boolean = false
197+
override val contentLength: Long? = responseBody.length.toLong()
198+
override fun readFrom(): SdkSource = responseBody.toByteArray().source()
199+
},
175200
)
176201
val now = Instant.now()
177202
HttpCall(request, resp, now, now)
@@ -200,7 +225,11 @@ class FailedChecksumResponseTest {
200225
Headers {
201226
append("x-amz-checksum-sha1", "bm90LWEtY2hlY2tzdW0=")
202227
},
203-
"Hello world".toHttpBody(),
228+
object : HttpBody.SourceContent() {
229+
override val isOneShot: Boolean = false
230+
override val contentLength: Long? = responseBody.length.toLong()
231+
override fun readFrom(): SdkSource = responseBody.toByteArray().source()
232+
},
204233
)
205234
val now = Instant.now()
206235
HttpCall(request, resp, now, now)
@@ -229,7 +258,11 @@ class FailedChecksumResponseTest {
229258
Headers {
230259
append("x-amz-checksum-sha256", "bm90LWEtY2hlY2tzdW0=")
231260
},
232-
"Hello world".toHttpBody(),
261+
object : HttpBody.SourceContent() {
262+
override val isOneShot: Boolean = false
263+
override val contentLength: Long? = responseBody.length.toLong()
264+
override fun readFrom(): SdkSource = responseBody.toByteArray().source()
265+
},
233266
)
234267
val now = Instant.now()
235268
HttpCall(request, resp, now, now)

0 commit comments

Comments
 (0)