Skip to content

Commit

Permalink
Address virtual host style addressing bugs for short subdomains provi…
Browse files Browse the repository at this point in the history
…ded in ``endpoint_url`` (#2941)

* Address virtual style addressing bugs for short subdomains provided in ``endpoint_url``

* changelog

* pr feedback
  • Loading branch information
dlm6693 authored May 12, 2023
1 parent 22a19ea commit d95d441
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-EndpointProvider-38157.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "EndpointProvider",
"description": "Fixed bug in virtual addressing for S3 Buckets `#2938 <https://github.com/boto/botocore/issues/2938>`__"
}
10 changes: 3 additions & 7 deletions botocore/endpoint_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,9 @@ def aws_is_virtual_hostable_s3_bucket(self, value, allow_subdomains):
):
return False

if allow_subdomains is True:
return all(
self.aws_is_virtual_hostable_s3_bucket(label, False)
for label in value.split(".")
)

return self.is_valid_host_label(value, allow_subdomains=False)
return self.is_valid_host_label(
value, allow_subdomains=allow_subdomains
)


# maintains backwards compatibility as `Library` was misspelled
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3487,6 +3487,24 @@ def _addressing_for_presigned_url_test_cases():
signature_version="s3",
expected_url="https://s3.us-west-1.amazonaws.com/foo.bar.biz/key",
)
# Bucket names that contain dots and subcomponents that are less than
# 3 characters should still use virtual host style addressing if
# configured by the customer and they provide their own ``endpoint_url``
# that is insecure. https://github.com/boto/botocore/issues/2938
yield dict(
bucket="foo.b.biz",
key="key",
s3_config={"addressing_style": "virtual"},
customer_provided_endpoint="http://s3.us-west-2.amazonaws.com",
expected_url="http://foo.b.biz.s3.us-west-2.amazonaws.com/key",
)
yield dict(
bucket="foo.b.biz",
key="key",
s3_config={"addressing_style": "virtual"},
customer_provided_endpoint="https://s3.us-west-2.amazonaws.com",
expected_url="https://s3.us-west-2.amazonaws.com/foo.b.biz/key",
)


@pytest.mark.parametrize(
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test_endpoint_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,23 @@ def test_endpoint_reevaluates_result(endpoint_provider, monkeypatch):
for region in regions:
endpoint_provider.resolve_endpoint(Region=region)
assert mock_evaluate.call_count == 2


@pytest.mark.parametrize(
"bucket, expected_value",
[
("mybucket", True),
("ab", False),
("a.b", True),
("my.great.bucket.aws.com", True),
("mY.GREAT.bucket.aws.com", False),
("192.168.1.1", False),
],
)
def test_aws_is_virtual_hostable_s3_bucket_allow_subdomains(
rule_lib, bucket, expected_value
):
assert (
rule_lib.aws_is_virtual_hostable_s3_bucket(bucket, True)
== expected_value
)

0 comments on commit d95d441

Please sign in to comment.