Skip to content

Commit

Permalink
Update s3 module_util validate_bucket_name to accept 3 character buck…
Browse files Browse the repository at this point in the history
…et name (ansible-collections#802)

Update s3 module_util validate_bucket_name to accept 3 character bucket name

SUMMARY
According to the S3 docs (https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html), the minimum bucket name is 3 characters. The current validate_bucket_name function fails for any bucket name less than 4 characters. This PR updates the check and adds unit test cases for minimum length.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
s3
ADDITIONAL INFORMATION
To reproduce, attempt to perform an action on a bucket with a 3 character name.

Reviewed-by: Alina Buzachis <None>
Reviewed-by: Gonéri Le Bouder <[email protected]>
  • Loading branch information
jbellanti authored May 10, 2022
1 parent 30c6d5d commit 93b8370
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- module.utils.s3 - Update validate_bucket_name minimum length to 3 (https://github.com/ansible-collections/amazon.aws/pull/802).
4 changes: 2 additions & 2 deletions plugins/module_utils/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def calculate_etag_content(module, content, etag, s3, bucket, obj, version=None)

def validate_bucket_name(module, name):
# See: https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html
if len(name) < 4:
module.fail_json(msg='the S3 bucket name is too short')
if len(name) < 3:
module.fail_json(msg='the length of an S3 bucket must be at least 3 characters')
if len(name) > 63:
module.fail_json(msg='the length of an S3 bucket cannot exceed 63 characters')

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/module_utils/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def test_validate_bucket_name():
assert not module.fail_json.called
assert s3.validate_bucket_name(module, "my.example.s3.bucket") is True
assert not module.fail_json.called
assert s3.validate_bucket_name(module, "doc") is True
assert not module.fail_json.called

module.fail_json.reset_mock()
s3.validate_bucket_name(module, "doc_example_bucket")
Expand All @@ -38,3 +40,5 @@ def test_validate_bucket_name():
module.fail_json.reset_mock()
s3.validate_bucket_name(module, "doc-example-bucket-")
assert module.fail_json.called
s3.validate_bucket_name(module, "my")
assert module.fail_json.called

0 comments on commit 93b8370

Please sign in to comment.