Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix S3 v3 VirtualHost removing trailing slash #9604

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

Merged
merged 2 commits into from
Nov 13, 2023
Merged

Conversation

bentsku
Copy link
Contributor

@bentsku bentsku commented Nov 11, 2023

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 calling ListObjectsV2 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

  • Updated an existing test verifying this behavior for the regular path style (we already have a special case for this in the parser, see localstack.aws.protocol.parser.S3RequestParser._parse_shape) to also test for virtual host mode.
  • Modified the VirtualHostRewriter to not mangle the trailing slash
  • Also spotted a different issue in the V2 legacy provider, where the v-host proxy was not proxying the request with the raw path, so the test would fail.

@bentsku bentsku added aws:s3 Amazon Simple Storage Service area: asf semver: patch Non-breaking changes which can be included in patch releases labels Nov 11, 2023
@bentsku bentsku self-assigned this Nov 11, 2023
Copy link

github-actions bot commented Nov 11, 2023

LocalStack Community integration with Pro

       2 files  ±0         2 suites  ±0   1h 27m 27s ⏱️ + 5m 13s
2 307 tests +1  2 010 ✔️ +1  297 💤 ±0  0 ±0 
2 308 runs  +1  2 010 ✔️ +1  298 💤 ±0  0 ±0 

Results for commit b2437e1. ± Comparison against base commit 76483ac.

This pull request removes 1 and adds 2 tests. Note that renamed tests count towards both.
tests.aws.services.s3.test_s3.TestS3 ‑ test_url_encoded_key
tests.aws.services.s3.test_s3.TestS3 ‑ test_url_encoded_key[False]
tests.aws.services.s3.test_s3.TestS3 ‑ test_url_encoded_key[True]

♻️ This comment has been updated with latest results.

Copy link
Member

@alexrashed alexrashed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and clean change! Thanks for jumping on this, and providing the additional snapshot validated test! 🚀 💯

@bentsku bentsku force-pushed the run-s3-opendal-tests branch from 8ced809 to b2437e1 Compare November 11, 2023 22:29
@coveralls
Copy link

Coverage Status

coverage: 84.015% (-0.004%) from 84.019%
when pulling b2437e1 on run-s3-opendal-tests
into 76483ac on master.

@bentsku bentsku added this to the 3.0 milestone Nov 12, 2023
@bentsku bentsku merged commit 78999d0 into master Nov 13, 2023
@bentsku bentsku deleted the run-s3-opendal-tests branch November 13, 2023 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: asf aws:s3 Amazon Simple Storage Service semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants