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

Fix requests mock for custom S3 endpoints #7445

Merged

Conversation

dhirving
Copy link
Contributor

@dhirving dhirving commented Mar 8, 2024

Prior to the commit that introduced mock_aws (a7f3b36), it was possible to use the requests mock to access S3 presigned URLs that had a custom endpoint.

This commit restores that behavior by applying the hostname-remapping logic from BotocoreStubber to CustomRegistry.

Prior to the commit that introduced mock_aws (a7f3b36), it was possible to use the requests mock to access S3 presigned URLs that had a custom endpoint.

This commit restores that behavior by applying the
hostname-remapping logic from BotocoreStubber to CustomRegistry.
Copy link

codecov bot commented Mar 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.80%. Comparing base (9aef694) to head (7f3f773).
Report is 99 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7445      +/-   ##
==========================================
- Coverage   95.88%   95.80%   -0.08%     
==========================================
  Files         843      854      +11     
  Lines       82578    83971    +1393     
==========================================
+ Hits        79178    80451    +1273     
- Misses       3400     3520     +120     
Flag Coverage Δ
servertests 32.22% <20.68%> (-0.30%) ⬇️
unittests 95.77% <100.00%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bblommers bblommers added the moto-core PR's that touch the core functionality. This will trigger additional tests. label Mar 8, 2024
url_with_standard_aws_domain = urlunparse(
get_equivalent_url_in_aws_domain(request.url)
)
request_with_standard_aws_domain = request.copy()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copying and preparing the URL is only necessary in some cases, but it currently happens for every incoming HTTP request. The possible performance downsides of that worry me a little.

Can we make the copy+prepare conditional, and only execute that part if the standardized URL is different from the original?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's a good call. There's no guarantee that URLs will roundtrip unchanged through urlparse/urlunparse, so I put the modification check a little further up. That will also save some string copying.

Avoid an unnecessary copy and modification of the request object in cases where no URL remapping occurred.
Copy link
Collaborator

@bblommers bblommers left a comment

Choose a reason for hiding this comment

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

Awesome - thank you for fixing this @dhirving!

@bblommers bblommers added this to the 5.0.4 milestone Mar 12, 2024
@bblommers bblommers merged commit ed3f77f into getmoto:master Mar 12, 2024
40 checks passed
Copy link
Contributor

This is now part of moto >= 5.0.4.dev10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
moto-core PR's that touch the core functionality. This will trigger additional tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants