Unverified Commit 84b8db34 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Fix a bug where we aren't checking the URL (#3211)

## 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._
parent 5d9a8175
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -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 ->
@@ -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,
                )
            }
        }
    }

+17 −0
Original line number Diff line number Diff line
@@ -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> {