Skip to content

Commit

Permalink
Update some s3 integ and protocol tests
Browse files Browse the repository at this point in the history
Update PutBucketLifecycleConfiguration test it now checks the Crc32
checksum header instead of Md5
  • Loading branch information
landonxjames committed Sep 26, 2024
1 parent 6182401 commit d0aedfe
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
4 changes: 1 addition & 3 deletions aws/sdk/aws-models-extra/s3-tests.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ apply PutBucketLifecycleConfiguration @httpRequestTests([
protocol: "aws.protocols#restXml",
uri: "/",
headers: {
// we can assert this, but when this test is promoted, it can't assert
// on the exact contents
"content-md5": "JP8DTuCSH6yDC8wNGg4+mA==",
"x-amz-checksum-crc32": "11+f3g==",
},
bodyMediaType: "application/xml",
body: """
Expand Down
2 changes: 1 addition & 1 deletion aws/sdk/integration-tests/s3/tests/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async fn multi_region_access_points() {
let auth_header = captured_request.headers().get("AUTHORIZATION").unwrap();
// Verifies that the sigv4a signing algorithm was used, that the signing scope doesn't include a region, and that the x-amz-region-set header was signed.
let expected_start =
"AWS4-ECDSA-P256-SHA256 Credential=ANOTREAL/20090213/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-region-set;x-amz-user-agent, Signature=";
"AWS4-ECDSA-P256-SHA256 Credential=ANOTREAL/20090213/s3/aws4_request, SignedHeaders=host;x-amz-checksum-mode;x-amz-content-sha256;x-amz-date;x-amz-region-set;x-amz-user-agent, Signature=";

assert!(
auth_header.starts_with(expected_start),
Expand Down
7 changes: 6 additions & 1 deletion aws/sdk/integration-tests/s3/tests/express.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ async fn presigning() {
][..],
&query_params
);
assert_eq!(presigned.headers().count(), 0);
// Presigned request has one header and that is the x-amz-checksum-mode
// header with default value ENABLED
assert_eq!(presigned.headers().count(), 1);
let headers = presigned.headers().collect::<Vec<(&str, &str)>>();
assert_eq!(headers.get(0).unwrap().0, "x-amz-checksum-mode");
assert_eq!(headers.get(0).unwrap().1, "ENABLED");
}

fn operation_request_with_checksum(
Expand Down
14 changes: 9 additions & 5 deletions aws/sdk/integration-tests/s3/tests/presigning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ async fn test_presigning() {
][..],
&query_params
);
assert_eq!(presigned.headers().count(), 0);
assert_eq!(presigned.headers().count(), 1);
let headers = presigned.headers().collect::<HashMap<_, _>>();
assert_eq!(headers.get("x-amz-checksum-mode").unwrap(), &"ENABLED");
}

#[tokio::test]
Expand Down Expand Up @@ -135,8 +137,8 @@ async fn test_presigning_with_payload_headers() {
"X-Amz-Date=20090213T233131Z",
"X-Amz-Expires=30",
"X-Amz-Security-Token=notarealsessiontoken",
"X-Amz-Signature=be1d41dc392f7019750e4f5e577234fb9059dd20d15f6a99734196becce55e52",
"X-Amz-SignedHeaders=content-length%3Bcontent-type%3Bhost",
"X-Amz-Signature=9403eb5961c8af066f2473f88cb9248b39fd61f8eedc33af14ec9c2d26c22974",
"X-Amz-SignedHeaders=content-length%3Bcontent-type%3Bhost%3Bx-amz-checksum-crc32%3Bx-amz-sdk-checksum-algorithm",
"x-id=PutObject"
][..],
&query_params
Expand All @@ -148,7 +150,9 @@ async fn test_presigning_with_payload_headers() {
Some(&"application/x-test")
);
assert_eq!(headers.get(CONTENT_LENGTH.as_str()), Some(&"12345"));
assert_eq!(headers.len(), 2);
assert_eq!(headers.get("x-amz-sdk-checksum-algorithm"), Some(&"CRC32"));
assert_eq!(headers.get("x-amz-checksum-crc32"), Some(&"AAAAAA=="));
assert_eq!(headers.len(), 4);
}

#[tokio::test]
Expand All @@ -164,7 +168,7 @@ async fn test_presigned_upload_part() {
})
.await;
pretty_assertions::assert_eq!(
"https://bucket.s3.us-east-1.amazonaws.com/key?x-id=UploadPart&partNumber=0&uploadId=upload-id&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ANOTREAL%2F20090213%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20090213T233131Z&X-Amz-Expires=30&X-Amz-SignedHeaders=content-length%3Bhost&X-Amz-Signature=a702867244f0bd1fb4d161e2a062520dcbefae3b9992d2e5366bcd61a60c6ddd&X-Amz-Security-Token=notarealsessiontoken",
"https://bucket.s3.us-east-1.amazonaws.com/key?x-id=UploadPart&partNumber=0&uploadId=upload-id&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ANOTREAL%2F20090213%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20090213T233131Z&X-Amz-Expires=30&X-Amz-SignedHeaders=content-length%3Bhost%3Bx-amz-checksum-crc32%3Bx-amz-sdk-checksum-algorithm&X-Amz-Signature=0b5835e056c463d6c0963326966f6cf42c75b7a218057836274d38288e055d36&X-Amz-Security-Token=notarealsessiontoken",
presigned.uri().to_string(),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ async fn test_stalled_stream_protection_defaults_for_upload() {
.credentials_provider(Credentials::for_tests())
.region(Region::new("us-east-1"))
.endpoint_url(format!("http://{server_addr}"))
// The Body used here is odd and fails the body.size_hint().exact() check in the streaming branch of
// the `RequestChecksumInterceptor`
.request_checksum_calculation(aws_sdk_s3::config::RequestChecksumCalculation::WhenRequired)
.build();
let client = Client::from_conf(conf);

Expand Down

0 comments on commit d0aedfe

Please sign in to comment.