Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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