Skip to content

Commit e9bf8e5

Browse files
committed
RequestChecksum required client config tests
1 parent 472fae9 commit e9bf8e5

File tree

2 files changed

+107
-31
lines changed

2 files changed

+107
-31
lines changed

tests/codegen/checksums/src/commonTest/kotlin/ClientConfigTests.kt

Lines changed: 83 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,101 @@ import kotlin.test.Test
1010
import kotlin.test.assertFalse
1111
import kotlin.test.assertTrue
1212
import aws.smithy.kotlin.runtime.httptest.TestEngine
13+
import org.junit.jupiter.api.Nested
14+
import kotlin.test.Ignore
1315

1416
class ClientConfigTests {
15-
@Test
16-
fun requestChecksumCalculationWhenSupported(): Unit = runBlocking {
17-
val testInterceptor = TestInterceptor()
17+
@Nested
18+
inner class RequestChecksumNotRequired {
19+
@Test
20+
@Ignore // todo: un-ignore
21+
fun requestChecksumCalculationWhenSupported(): Unit = runBlocking {
22+
val testInterceptor = TestInterceptor()
1823

19-
ClientConfigTestClient {
20-
requestChecksumCalculation = RequestChecksumCalculation.WHEN_SUPPORTED
21-
interceptors = mutableListOf(testInterceptor)
22-
httpClient = TestEngine()
23-
credentialsProvider = StaticCredentialsProvider(
24-
Credentials("accessKeyID", "secretAccessKey"),
25-
)
26-
region = "us-east-1"
27-
}.use { client ->
28-
client.checksumsNotRequiredOperation {
29-
body = "Hello World!"
24+
ClientConfigTestClient {
25+
requestChecksumCalculation = RequestChecksumCalculation.WHEN_SUPPORTED
26+
interceptors = mutableListOf(testInterceptor)
27+
httpClient = TestEngine()
28+
credentialsProvider = StaticCredentialsProvider(
29+
Credentials("accessKeyID", "secretAccessKey"),
30+
)
31+
region = "us-east-1"
32+
}.use { client ->
33+
client.checksumsNotRequiredOperation {
34+
body = "Hello World!"
35+
}
3036
}
37+
38+
assertTrue(testInterceptor.containsChecksum)
3139
}
3240

33-
assertTrue(testInterceptor.containsChecksum)
41+
@Test
42+
fun requestChecksumCalculationWhenRequired(): Unit = runBlocking {
43+
val testInterceptor = TestInterceptor()
44+
45+
ClientConfigTestClient {
46+
requestChecksumCalculation = RequestChecksumCalculation.WHEN_REQUIRED
47+
interceptors = mutableListOf(testInterceptor)
48+
httpClient = TestEngine()
49+
credentialsProvider = StaticCredentialsProvider(
50+
Credentials("accessKeyID", "secretAccessKey"),
51+
)
52+
region = "us-east-1"
53+
}.use { client ->
54+
client.checksumsNotRequiredOperation {
55+
body = "Hello World!"
56+
}
57+
}
58+
59+
assertFalse(testInterceptor.containsChecksum)
60+
}
3461
}
3562

36-
@Test
37-
fun requestChecksumCalculationWhenRequired(): Unit = runBlocking {
38-
val testInterceptor = TestInterceptor()
63+
@Nested
64+
inner class RequestChecksumRequired {
65+
@Test
66+
@Ignore // todo: un-ignore
67+
fun requestChecksumCalculationWhenSupported(): Unit = runBlocking {
68+
val testInterceptor = TestInterceptor()
3969

40-
ClientConfigTestClient {
41-
requestChecksumCalculation = RequestChecksumCalculation.WHEN_REQUIRED
42-
interceptors = mutableListOf(testInterceptor)
43-
httpClient = TestEngine()
44-
credentialsProvider = StaticCredentialsProvider(
45-
Credentials("accessKeyID", "secretAccessKey"),
46-
)
47-
region = "us-east-1"
48-
}.use { client ->
49-
client.checksumsNotRequiredOperation {
50-
body = "Hello World!"
70+
ClientConfigTestClient {
71+
requestChecksumCalculation = RequestChecksumCalculation.WHEN_SUPPORTED
72+
interceptors = mutableListOf(testInterceptor)
73+
httpClient = TestEngine()
74+
credentialsProvider = StaticCredentialsProvider(
75+
Credentials("accessKeyID", "secretAccessKey"),
76+
)
77+
region = "us-east-1"
78+
}.use { client ->
79+
client.checksumsRequiredOperation {
80+
body = "Hello World!"
81+
}
5182
}
83+
84+
assertTrue(testInterceptor.containsChecksum)
5285
}
5386

54-
assertFalse(testInterceptor.containsChecksum)
87+
@Test
88+
@Ignore // todo: un-ignore
89+
fun requestChecksumCalculationWhenRequired(): Unit = runBlocking {
90+
val testInterceptor = TestInterceptor()
91+
92+
ClientConfigTestClient {
93+
requestChecksumCalculation = RequestChecksumCalculation.WHEN_REQUIRED
94+
interceptors = mutableListOf(testInterceptor)
95+
httpClient = TestEngine()
96+
credentialsProvider = StaticCredentialsProvider(
97+
Credentials("accessKeyID", "secretAccessKey"),
98+
)
99+
region = "us-east-1"
100+
}.use { client ->
101+
client.checksumsRequiredOperation {
102+
body = "Hello World!"
103+
}
104+
}
105+
106+
assertTrue(testInterceptor.containsChecksum)
107+
}
55108
}
56109
}
57110

tests/codegen/checksums/src/commonTest/resources/client-config.smithy

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use smithy.rules#endpointRuleSet
2020
})
2121
service ClientConfigTestService {
2222
version: "2023-01-01",
23-
operations: [ChecksumsNotRequiredOperation]
23+
operations: [ChecksumsNotRequiredOperation, ChecksumsRequiredOperation]
2424
}
2525

2626
@httpChecksum(
@@ -33,6 +33,16 @@ operation ChecksumsNotRequiredOperation {
3333
output: SomeOutput
3434
}
3535

36+
@httpChecksum(
37+
requestChecksumRequired: true,
38+
requestAlgorithmMember: "checksumAlgorithm",
39+
)
40+
@http(method: "POST", uri: "/test-checksums-2", code: 200)
41+
operation ChecksumsRequiredOperation {
42+
input: AnotherInput,
43+
output: AnotherOutput
44+
}
45+
3646
@input
3747
structure SomeInput {
3848
@httpHeader("x-amz-request-algorithm")
@@ -46,6 +56,19 @@ structure SomeInput {
4656
@output
4757
structure SomeOutput {}
4858

59+
@input
60+
structure AnotherInput {
61+
@httpHeader("x-amz-request-algorithm")
62+
checksumAlgorithm: ChecksumAlgorithm
63+
64+
@httpPayload
65+
@required
66+
body: String
67+
}
68+
69+
@output
70+
structure AnotherOutput {}
71+
4972
enum ChecksumAlgorithm {
5073
CRC32
5174
CRC32C

0 commit comments

Comments
 (0)