Skip to content

Commit 4167a27

Browse files
authored
misc: make route 53 uri tests resilient to model version changes (#1540)
1 parent e6bcbce commit 4167a27

File tree

3 files changed

+174
-81
lines changed

3 files changed

+174
-81
lines changed

services/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ subprojects {
102102
}
103103
}
104104

105+
if (project.name == "route53") {
106+
dependencies {
107+
implementation(libraries.smithy.kotlin.http.test) // needed for URI E2E tests
108+
}
109+
}
110+
105111
// Run the tests with the classpath containing the compile dependencies (including 'main'),
106112
// runtime dependencies, and the outputs of this compilation:
107113
classpath = compileDependencyFiles + runtimeDependencyFiles + output.allOutputs
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
package aws.sdk.kotlin.services.route53
2+
3+
import aws.sdk.kotlin.runtime.auth.credentials.StaticCredentialsProvider
4+
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
5+
import aws.smithy.kotlin.runtime.client.ProtocolRequestInterceptorContext
6+
import aws.smithy.kotlin.runtime.http.interceptors.HttpInterceptor
7+
import aws.smithy.kotlin.runtime.http.request.HttpRequest
8+
import aws.smithy.kotlin.runtime.httptest.TestEngine
9+
import kotlinx.coroutines.test.runTest
10+
import kotlin.test.Test
11+
import kotlin.test.assertEquals
12+
import kotlin.test.fail
13+
14+
class Route53UriTest {
15+
/**
16+
* Validates that HostedZoneId isn't trimmed when not prefixed
17+
*/
18+
@Test
19+
fun listResourceRecordSetsNoTrim() = runTest {
20+
Route53Client {
21+
region = "us-east-1"
22+
httpClient = TestEngine()
23+
interceptors = mutableListOf(
24+
AssertUrlInterceptor(
25+
expectedUrl = "/0000-00-00/hostedzone/IDOFMYHOSTEDZONE/rrset",
26+
),
27+
)
28+
credentialsProvider = StaticCredentialsProvider(Credentials("AKID", "SECRETAK"))
29+
}.use { client ->
30+
client.listResourceRecordSets {
31+
hostedZoneId = "IDOFMYHOSTEDZONE"
32+
}
33+
}
34+
}
35+
36+
/**
37+
* Validates that HostedZoneId is trimmed
38+
*/
39+
@Test
40+
fun listResourceRecordSetsTrim() = runTest {
41+
Route53Client {
42+
region = "us-east-1"
43+
httpClient = TestEngine()
44+
interceptors = mutableListOf(
45+
AssertUrlInterceptor(
46+
expectedUrl = "/0000-00-00/hostedzone/IDOFMYHOSTEDZONE/rrset",
47+
),
48+
)
49+
credentialsProvider = StaticCredentialsProvider(Credentials("AKID", "SECRETAK"))
50+
}.use { client ->
51+
client.listResourceRecordSets {
52+
hostedZoneId = "hostedzone/IDOFMYHOSTEDZONE"
53+
}
54+
}
55+
}
56+
57+
/**
58+
* Validates that HostedZoneId is trimmed even with a leading slash
59+
*/
60+
@Test
61+
fun listResourceRecordSetsTrimLeadingSlash() = runTest {
62+
Route53Client {
63+
region = "us-east-1"
64+
httpClient = TestEngine()
65+
interceptors = mutableListOf(
66+
AssertUrlInterceptor(
67+
expectedUrl = "/0000-00-00/hostedzone/IDOFMYHOSTEDZONE/rrset",
68+
),
69+
)
70+
credentialsProvider = StaticCredentialsProvider(Credentials("AKID", "SECRETAK"))
71+
}.use { client ->
72+
client.listResourceRecordSets {
73+
hostedZoneId = "/hostedzone/IDOFMYHOSTEDZONE"
74+
}
75+
}
76+
}
77+
78+
/**
79+
* Validates that HostedZoneId isn't over-trimmed
80+
*/
81+
@Test
82+
fun listResourceRecordSetsTrimMultiSlash() = runTest {
83+
Route53Client {
84+
region = "us-east-1"
85+
httpClient = TestEngine()
86+
interceptors = mutableListOf(
87+
AssertUrlInterceptor(
88+
expectedUrl = "/0000-00-00/hostedzone/IDOFMY%2FHOSTEDZONE/rrset",
89+
),
90+
)
91+
credentialsProvider = StaticCredentialsProvider(Credentials("AKID", "SECRETAK"))
92+
}.use { client ->
93+
client.listResourceRecordSets {
94+
hostedZoneId = "/hostedzone/IDOFMY/HOSTEDZONE"
95+
}
96+
}
97+
}
98+
99+
/**
100+
* This test validates that change id is correctly trimmed
101+
*/
102+
@Test
103+
fun getChangeTrimChangeId() = runTest {
104+
Route53Client {
105+
region = "us-east-1"
106+
httpClient = TestEngine()
107+
interceptors = mutableListOf(
108+
AssertUrlInterceptor(
109+
expectedUrl = "/0000-00-00/change/SOMECHANGEID",
110+
),
111+
)
112+
credentialsProvider = StaticCredentialsProvider(Credentials("AKID", "SECRETAK"))
113+
}.use { client ->
114+
client.getChange {
115+
id = "/change/SOMECHANGEID"
116+
}
117+
}
118+
}
119+
120+
/**
121+
* This test validates that delegation set id is correctly trimmed
122+
*/
123+
@Test
124+
fun getReusableDelegationSetTrimDelegationSetId() = runTest {
125+
Route53Client {
126+
region = "us-east-1"
127+
httpClient = TestEngine()
128+
interceptors = mutableListOf(
129+
AssertUrlInterceptor(
130+
expectedUrl = "/0000-00-00/delegationset/DELEGATIONSETID",
131+
),
132+
)
133+
credentialsProvider = StaticCredentialsProvider(Credentials("AKID", "SECRETAK"))
134+
}.use { client ->
135+
client.getReusableDelegationSet {
136+
id = "/delegationset/DELEGATIONSETID"
137+
}
138+
}
139+
}
140+
141+
/**
142+
* Model version can change the URL used as it's included in the URL.
143+
* This interceptor removes the model version from the expected and actual URLs.
144+
* Then performs an equality assertion between the two.
145+
*
146+
* https://github.com/awslabs/aws-sdk-kotlin/issues/1370
147+
*/
148+
private class AssertUrlInterceptor(private val expectedUrl: String) : HttpInterceptor {
149+
override fun readBeforeTransmit(context: ProtocolRequestInterceptorContext<Any, HttpRequest>) {
150+
val actualUrl = context.protocolRequest.url.path.toString()
151+
152+
val parsedActualUrl = removeModelVersion(actualUrl)
153+
val parsedExpectedUrl = removeModelVersion(expectedUrl)
154+
155+
assertEquals(parsedExpectedUrl, parsedActualUrl)
156+
}
157+
158+
private fun removeModelVersion(url: String) =
159+
try {
160+
url.replaceFirst(
161+
Regex("^/\\d{4}-\\d{2}-\\d{2}/"),
162+
"//",
163+
)
164+
} catch (e: Exception) {
165+
fail("The URL '$url' is not in the expected format", e)
166+
}
167+
}
168+
}

services/route53/model/route53-tests.smithy

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)