fix S3 v3 VirtualHost removing trailing slash #9604
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Following #9603, I've ran the OpenDAL integration test with
OPENDAL_S3_ENABLE_VIRTUAL_HOST_STYLE=on
to see if there would be any difference, and 2 tests failed. After investigation, it was because callingListObjectsV2
would return the keys without the trailing slash, making the test assertions fail. After investigating the difference between the calls, I could see the parsed request was different between the 2 modes:Virtual-Host before the fix:
PUT opendal-testing.s3.localhost.localstack.cloud:4566/CI/16b716e8-4cd2-4f6e-9d82-ee338b5e48b1/580cc505-82cf-424e-8448-ca4bf9dfd1ac/
-> PutObjectRequest({'ACL': None, 'Bucket': 'opendal-testing', ..., 'Key': 'CI/16b716e8-4cd2-4f6e-9d82-ee338b5e48b1/580cc505-82cf-424e-8448-ca4bf9dfd1ac', 'Metadata': {}...)
Path style:
PUT s3.localhost.localstack.cloud:4566/opendal-testing/CI/cc66a8ac-a924-42b2-950a-b5a9b6bca060/23a5e248-3249-436f-881f-cc1b8dcbffbe/
-> PutObjectRequest({'ACL': None, 'Bucket': 'opendal-testing', ..., 'Key': 'CI/cc66a8ac-a924-42b2-950a-b5a9b6bca060/23a5e248-3249-436f-881f-cc1b8dcbffbe/', 'Metadata': {}...)
As we can see, the Virtual Host mangled the trailing slash, thus creating an object with the wrong key. This was due to a previous assertion in the VirtualHostRewriter which was written to actually mangle it. I've changed it to be closer to our previous proxy, and simply prefix the path with the bucket.
Those test suites are really building confidence in our new S3 implementation, most of them are passing on the first try and some real edge cases are popping up. I'll continue to scour the internet to find S3 test suites to test LocalStack against. Maybe another Apache project which will use LocalStack 😄
Just for info, here are the 2 previously failing tests:
Changes
localstack.aws.protocol.parser.S3RequestParser._parse_shape
) to also test for virtual host mode.