-
Notifications
You must be signed in to change notification settings - Fork 195
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
Add "invalid xml body root" check exemption for S3's GetObjectAttributes
#1665
Changes from 14 commits
1962f47
bb6728a
aa3a2be
c1df769
12b3de0
2129d40
2215c14
63cc880
0738972
bb7d739
469e367
2dfbd30
41627e3
5c49248
9481d48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
use aws_http::user_agent::AwsUserAgent; | ||
use aws_sdk_s3::{ | ||
middleware::DefaultMiddleware, model::ObjectAttributes, operation::GetObjectAttributes, | ||
Credentials, Region, | ||
}; | ||
use aws_smithy_client::{test_connection::TestConnection, Client as CoreClient}; | ||
use aws_smithy_http::body::SdkBody; | ||
use std::time::{Duration, UNIX_EPOCH}; | ||
|
||
pub type Client<C> = CoreClient<C, DefaultMiddleware>; | ||
|
||
const RESPONSE_BODY_XML: &[u8] = b"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<GetObjectAttributesResponse xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Checksum><ChecksumSHA1>e1AsOh9IyGCa4hLN+2Od7jlnP14=</ChecksumSHA1></Checksum></GetObjectAttributesResponse>"; | ||
|
||
#[tokio::test] | ||
async fn ignore_invalid_xml_body_root() { | ||
tracing_subscriber::fmt::init(); | ||
|
||
let conn = TestConnection::new(vec![ | ||
(http::Request::builder() | ||
.header("x-amz-object-attributes", "Checksum") | ||
.header("x-amz-user-agent", "aws-sdk-rust/0.123.test api/test-service/0.123 os/windows/XPSP3 lang/rust/1.50.0") | ||
.header("x-amz-date", "20210618T170728Z") | ||
.header("authorization", "AWS4-HMAC-SHA256 Credential=ANOTREAL/20210618/us-east-1/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-object-attributes;x-amz-security-token;x-amz-user-agent, Signature=0e6ec749db5a0af07890a83f553319eda95be0e498d058c64880471a474c5378") | ||
.header("x-amz-content-sha256", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") | ||
.header("x-amz-security-token", "notarealsessiontoken") | ||
.uri(http::Uri::from_static("https://s3.us-east-1.amazonaws.com/some-test-bucket/test.txt?attributes")) | ||
.body(SdkBody::empty()) | ||
.unwrap(), | ||
http::Response::builder() | ||
.header( | ||
"x-amz-id-2", | ||
"rbipIUyF3YKPIcqpz6hrP9x9mzYMSqkHzDEp6TEN/STcKvylDIE/LLN6x9t6EKJRrgctNsdNHWk=", | ||
) | ||
.header("x-amz-request-id", "K8036R3D4NZNMMVC") | ||
.header("date", "Tue, 23 Aug 2022 18:17:23 GMT") | ||
.header("last-modified", "Tue, 21 Jun 2022 16:30:01 GMT") | ||
.header("server", "AmazonS3") | ||
.header("content-length", "224") | ||
.status(200) | ||
.body(RESPONSE_BODY_XML) | ||
.unwrap()) | ||
]); | ||
let creds = Credentials::new( | ||
"ANOTREAL", | ||
"notrealrnrELgWzOk3IfjzDKtFBhDby", | ||
Some("notarealsessiontoken".to_string()), | ||
None, | ||
"test", | ||
); | ||
let conf = aws_sdk_s3::Config::builder() | ||
.credentials_provider(creds) | ||
.region(Region::new("us-east-1")) | ||
.build(); | ||
let client = Client::new(conn.clone()); | ||
|
||
let mut op = GetObjectAttributes::builder() | ||
.bucket("some-test-bucket") | ||
.key("test.txt") | ||
.object_attributes(ObjectAttributes::Checksum) | ||
.build() | ||
.unwrap() | ||
.make_operation(&conf) | ||
.await | ||
.unwrap(); | ||
op.properties_mut() | ||
.insert(UNIX_EPOCH + Duration::from_secs(1624036048)); | ||
op.properties_mut().insert(AwsUserAgent::for_tests()); | ||
|
||
let res = client.call(op).await.unwrap(); | ||
|
||
conn.assert_requests_match(&[]); | ||
|
||
println!("res: {:#?}", res) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,10 @@ | |
package software.amazon.smithy.rust.codegen.smithy.protocols | ||
|
||
import software.amazon.smithy.aws.traits.protocols.RestXmlTrait | ||
import software.amazon.smithy.model.node.Node | ||
import software.amazon.smithy.model.shapes.OperationShape | ||
import software.amazon.smithy.model.shapes.ShapeId | ||
import software.amazon.smithy.model.traits.AnnotationTrait | ||
import software.amazon.smithy.model.traits.TimestampFormatTrait | ||
import software.amazon.smithy.rust.codegen.rustlang.CargoDependency | ||
import software.amazon.smithy.rust.codegen.rustlang.RustModule | ||
|
@@ -110,3 +113,12 @@ open class RestXml(private val coreCodegenContext: CoreCodegenContext) : Protoco | |
|
||
override fun serverRouterRuntimeConstructor() = "new_rest_xml_router" | ||
} | ||
|
||
/** | ||
* Indicates that a service is expected to send XML where the root element name does not match the modeled member name. | ||
*/ | ||
class AllowInvalidXmlRoot : AnnotationTrait(ID, Node.objectNode()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I was cross checking the S3 documentation with the S3 model to try and find other operations that may be broken (which unfortunately turned out to be a pointless endeavor—they're both wrong), I noticed that some S3 operations use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've broken this work out into a separate issue: #1668 |
||
companion object { | ||
val ID: ShapeId = ShapeId.from("smithy.api.internal#allowInvalidXmlRoot") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a brief stroll through botocore to see if there were any other obvious operations that have the wrong shape, and we may want to check
s3#GetBucketLocation
,s3#ListObjects
,s3#ListObjectVersions
, andec2#GetConsoleOutput
(this last one is using the ec2Query protocol, which still has XML responses). Not saying these ones meet the criteria, but that I see special code in botocore parsing these XML responses in botocore. If it's easy to check these, then we should, but probably not worth spending a ton of time on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've broken this work out into a separate issue: #1668