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

Allow expected content-type to ignore parameters #3576

Closed
wants to merge 7 commits into from
Closed
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
10 changes: 9 additions & 1 deletion CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
# author = "rcoh"

[[smithy-rs]]
message = """
`Content-Type` header validation now ignores parameter portion of media types.
"""
references = ["smithy-rs#3471","smithy-rs#3576"]
meta = { "breaking" = false, "tada" = false, "bug" = true, target = "server" }
authors = ["djedward"]

[[aws-sdk-rust]]
message = "Upgraded MSRV to Rust 1.75"
references = ["smithy-rs#3553"]
Expand All @@ -33,4 +41,4 @@ author = "avandesa"
message = "Change some credentials related info log messages to debug."
references = ["smithy-rs#3546"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "orf"
author = "orf"
50 changes: 50 additions & 0 deletions codegen-core/common-test-models/aws-json1-0-extras.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
$version: "2.0"

namespace aws.protocoltests.json10

use aws.api#service
use aws.protocols#awsJson1_0
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests

@service(sdkId: "JSON RPC 10")
@awsJson1_0
@title("Sample Json 1.0 Protocol Service")
service JsonRpc10Extras {
version: "2024-04-15",
operations: [
ContentTypeParameters
]
}

@httpRequestTests([
{
id: "AwsJson10ContentTypeParameters",
documentation: "A server should ignore parameters added to the content type",
protocol: awsJson1_0,
method: "POST",
headers: {
"Content-Type": "application/x-amz-json-1.0; charset=utf-8",
"X-Amz-Target": "JsonRpc10Extras.ContentTypeParameters",
},
uri: "/",
body: "{\"value\":5}",
bodyMediaType: "application/json",
params: {
value: 5,
},
appliesTo: "server"
}
])
operation ContentTypeParameters {
input: ContentTypeParametersInput,
output: ContentTypeParametersOutput
}

@input
structure ContentTypeParametersInput {
value: Integer,
}

@output
structure ContentTypeParametersOutput {}
55 changes: 55 additions & 0 deletions codegen-core/common-test-models/aws-json1-1-extras.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
$version: "2.0"

namespace aws.protocoltests.json

use aws.api#service
use aws.protocols#awsJson1_1
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests

@service(
sdkId: "Json Protocol",
arnNamespace: "jsonprotocol",
cloudFormationName: "JsonProtocol",
cloudTrailEventSource: "jsonprotocol.amazonaws.com",
)
@awsJson1_1
@title("Sample Json 1.1 Protocol Service")
service JsonProtocolExtras {
version: "2024-04-15",
operations: [
ContentTypeParameters
]
}

@httpRequestTests([
{
id: "AwsJson11ContentTypeParameters",
documentation: "A server should ignore parameters added to the content type",
protocol: awsJson1_1,
method: "POST",
headers: {
"Content-Type": "application/x-amz-json-1.1; charset=utf-8",
"X-Amz-Target": "JsonProtocolExtras.ContentTypeParameters",
},
uri: "/",
body: "{\"value\":5}",
bodyMediaType: "application/json",
params: {
value: 5,
},
appliesTo: "server"
}
])
operation ContentTypeParameters {
input: ContentTypeParametersInput,
output: ContentTypeParametersOutput
}

@input
structure ContentTypeParametersInput {
value: Integer,
}

@output
structure ContentTypeParametersOutput {}
30 changes: 30 additions & 0 deletions codegen-core/common-test-models/rest-json-extras.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ service RestJsonExtras {
CaseInsensitiveErrorOperation,
EmptyStructWithContentOnWireOp,
QueryPrecedence,
ContentTypeParameters,
],
errors: [ExtraError]
}
Expand Down Expand Up @@ -349,3 +350,32 @@ structure EmptyStructWithContentOnWireOpOutput {
operation EmptyStructWithContentOnWireOp {
output: EmptyStructWithContentOnWireOpOutput,
}

@http(uri: "/content-type-parameters", method: "POST")
@httpRequestTests([
{
id: "RestJsonContentTypeParameters",
documentation: "A server should ignore parameters added to the content type",
uri: "/content-type-parameters",
method: "POST",
protocol: "aws.protocols#restJson1",
body: "{\"value\":5}",
headers: { "Content-Type": "application/json; charset=utf-8" },
params: {
value: 5,
},
appliesTo: "server",
},
])
operation ContentTypeParameters {
input: ContentTypeParametersInput,
output: ContentTypeParametersOutput,
}

@input
structure ContentTypeParametersInput {
value: Integer,
}

@output
structure ContentTypeParametersOutput {}
51 changes: 51 additions & 0 deletions codegen-core/common-test-models/rest-xml-extras.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
$version: "2.0"

namespace aws.protocoltests.restxml

use aws.api#service
use aws.protocols#restXml
use smithy.test#httpRequestTests
use smithy.test#httpResponseTests

/// A REST XML service that sends XML requests and responses.
@service(sdkId: "Rest Xml Protocol")
@restXml
@title("Sample Rest Xml Protocol Service")
service RestXmlExtras {
version: "2024-04-15",
operations: [
ContentTypeParameters
]
}

@httpRequestTests([
{
id: "RestXmlContentTypeParameters",
documentation: "A server should ignore parameters added to the content type",
protocol: restXml,
method: "PUT",
headers: {
"Content-Type": "application/xml; charset=utf-8"
},
uri: "/ContentTypeParameters",
body: "<ContentTypeParametersInput><value>5</value></ContentTypeParametersInput>",
bodyMediaType: "application/xml",
params: {
value: 5,
},
appliesTo: "server"
}
])
@http(uri: "/ContentTypeParameters", method: "PUT")
operation ContentTypeParameters {
input: ContentTypeParametersInput,
output: ContentTypeParametersOutput
}

@input
structure ContentTypeParametersInput {
value: Integer,
}

@output
structure ContentTypeParametersOutput {}
15 changes: 15 additions & 0 deletions codegen-server-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ val allCodegenTests = "../codegen-core/common-test-models".let { commonModels ->
"pokemon-service-awsjson-server-sdk",
imports = listOf("$commonModels/pokemon-awsjson.smithy", "$commonModels/pokemon-common.smithy"),
),
CodegenTest(
"aws.protocoltests.json10#JsonRpc10Extras",
"aws_json10_extras",
imports = listOf("$commonModels/aws-json1-0-extras.smithy"),
),
CodegenTest(
"aws.protocoltests.json#JsonProtocolExtras",
"aws_json11_extras",
imports = listOf("$commonModels/aws-json1-1-extras.smithy"),
),
CodegenTest(
"aws.protocoltests.restxml#RestXmlExtras",
"rest_xml_extras",
imports = listOf("$commonModels/rest-xml-extras.smithy"),
),
)
}

Expand Down
4 changes: 2 additions & 2 deletions rust-runtime/aws-smithy-http-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws-smithy-http-server"
version = "0.61.2"
version = "0.61.3"
authors = ["Smithy Rust Server <smithy-rs-server@amazon.com>"]
edition = "2021"
license = "Apache-2.0"
Expand Down Expand Up @@ -29,7 +29,7 @@ http = "0.2"
http-body = "0.4"
hyper = { version = "0.14.26", features = ["server", "http1", "http2", "tcp", "stream"] }
lambda_http = { version = "0.8.0", optional = true }
mime = "0.3.4"
mime = "0.3.17"
nom = "7"
once_cell = "1.13"
pin-project-lite = "0.2"
Expand Down
9 changes: 8 additions & 1 deletion rust-runtime/aws-smithy-http-server/src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn content_type_header_classifier(
.parse::<mime::Mime>()
// `expected_content_type` comes from the codegen.
.expect("BUG: MIME parsing failed, `expected_content_type` is not valid. Please file a bug report under https://github.com/smithy-lang/smithy-rs/issues");
if expected_content_type != found_mime {
if expected_content_type != found_mime.essence_str() {
return Err(MissingContentTypeReason::UnexpectedMimeType {
expected_mime: Some(expected_mime),
found_mime: Some(found_mime),
Expand Down Expand Up @@ -257,6 +257,13 @@ mod tests {
assert!(matches!(result.unwrap_err(), MissingContentTypeReason::ToStrError(_)));
}

#[test]
fn valid_content_type_header_classifier_http_params() {
let request = req_content_type("application/json; charset=utf-8");
let result = content_type_header_classifier_http(&request, EXPECTED_MIME_APPLICATION_JSON);
assert!(result.is_ok());
}

#[test]
fn valid_accept_header_classifier_multiple_values() {
let valid_request = req_accept("text/strings, application/json, invalid");
Expand Down
Loading