Skip to content

Commit

Permalink
Fix a bug where we aren't checking the URL (#3211)
Browse files Browse the repository at this point in the history
## Motivation and Context
In #3059 there was an accidental deletion of a test
## Description
Re-introduce checking the URL in protocol tests

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
  • Loading branch information
rcoh authored Nov 16, 2023
1 parent 5d9a817 commit 84b8db3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class DefaultProtocolTestGenerator(
checkHeaders(this, "http_request.headers()", httpRequestTestCase.headers)
checkForbidHeaders(this, "http_request.headers()", httpRequestTestCase.forbidHeaders)
checkRequiredHeaders(this, "http_request.headers()", httpRequestTestCase.requireHeaders)

if (protocolSupport.requestBodySerialization) {
// "If no request body is defined, then no assertions are made about the body of the message."
httpRequestTestCase.body.orNull()?.also { body ->
Expand All @@ -248,6 +249,22 @@ class DefaultProtocolTestGenerator(
if (!httpRequestTestCase.vendorParams.isEmpty) {
logger.warning("Test case provided vendorParams but these were ignored")
}

rustTemplate(
"""
let uri: #{Uri} = http_request.uri().parse().expect("invalid URI sent");
#{AssertEq}(http_request.method(), ${method.dq()}, "method was incorrect");
#{AssertEq}(uri.path(), ${uri.dq()}, "path was incorrect");
""",
*codegenScope,
)

resolvedHost.orNull()?.also { host ->
rustTemplate(
"""#{AssertEq}(uri.host().expect("host should be set"), ${host.dq()});""",
*codegenScope,
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,23 @@ class ProtocolTestGeneratorTest {
err.message shouldContain "required query param missing"
}

@Test
fun `test invalid path`() {
val err = assertThrows<CommandError> {
testService(
"""
.uri("/incorrect-path?required&Hi=Hello%20there")
.header("X-Greeting", "Hi")
.method("POST")
""",
)
}

// Verify the test actually ran
err.message shouldContain "say_hello_request ... FAILED"
err.message shouldContain "path was incorrect"
}

@Test
fun `invalid header`() {
val err = assertThrows<CommandError> {
Expand Down

0 comments on commit 84b8db3

Please sign in to comment.