Skip to content

Commit 70da920

Browse files
committed
Add unit and functional tests for account regional namespace bucket support in s3 mb
1 parent ee25970 commit 70da920

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

tests/functional/s3/test_mb_command.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,31 @@ def test_make_bucket_with_multiple_tags(self):
9090
}
9191
self.assert_params_for_cmd(command, expected_params)
9292

93+
def test_account_regional_namespace_bucket(self):
94+
bucket = 'amzn-s3-demo-bucket-111122223333-us-west-2-an'
95+
command = self.prefix + 's3://%s --region us-west-2' % bucket
96+
self.parsed_responses = [{'Location': 'us-west-2'}]
97+
expected_params = {
98+
'Bucket': bucket,
99+
'BucketNamespace': 'account-regional',
100+
'CreateBucketConfiguration': {'LocationConstraint': 'us-west-2'},
101+
}
102+
self.assert_params_for_cmd(command, expected_params)
103+
104+
def test_account_regional_namespace_bucket_us_east_1(self):
105+
bucket = 'my-bucket-111122223333-us-east-1-an'
106+
command = self.prefix + 's3://%s --region us-east-1' % bucket
107+
expected_params = {
108+
'Bucket': bucket,
109+
'BucketNamespace': 'account-regional',
110+
}
111+
self.assert_params_for_cmd(command, expected_params)
112+
113+
def test_regular_bucket_no_namespace(self):
114+
command = self.prefix + 's3://my-regular-bucket --region us-east-1'
115+
expected_params = {'Bucket': 'my-regular-bucket'}
116+
self.assert_params_for_cmd(command, expected_params)
117+
93118
def test_tags_with_three_arguments_fails(self):
94119
command = self.prefix + 's3://bucket --tags Key1 Value1 ExtraArg'
95120
self.assert_params_for_cmd(

tests/unit/customizations/s3/test_utils.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
ProvideLastModifiedTimeSubscriber, DirectoryCreatorSubscriber,
4141
DeleteSourceObjectSubscriber, DeleteSourceFileSubscriber,
4242
DeleteCopySourceObjectSubscriber, NonSeekableStream, CreateDirectoryError,
43-
S3PathResolver, CaseConflictCleanupSubscriber)
43+
S3PathResolver, CaseConflictCleanupSubscriber,
44+
is_account_regional_namespace_bucket)
4445
from awscli.customizations.s3.results import WarningResult
4546
from tests.unit.customizations.s3 import FakeTransferFuture
4647
from tests.unit.customizations.s3 import FakeTransferFutureMeta
@@ -360,6 +361,46 @@ def test_outpost_bucket_arn_with_slash_raises_exception(self):
360361
)
361362

362363

364+
class TestIsAccountRegionalNamespaceBucket(unittest.TestCase):
365+
def test_matches_standard_pattern(self):
366+
self.assertTrue(
367+
is_account_regional_namespace_bucket(
368+
'amzn-s3-demo-bucket-111122223333-us-west-2-an'
369+
)
370+
)
371+
372+
def test_matches_different_region(self):
373+
self.assertTrue(
374+
is_account_regional_namespace_bucket(
375+
'my-bucket-123456789012-eu-central-1-an'
376+
)
377+
)
378+
379+
def test_no_match_regular_bucket(self):
380+
self.assertFalse(
381+
is_account_regional_namespace_bucket('my-regular-bucket')
382+
)
383+
384+
def test_no_match_missing_an_suffix(self):
385+
self.assertFalse(
386+
is_account_regional_namespace_bucket(
387+
'bucket-111122223333-us-west-2'
388+
)
389+
)
390+
391+
def test_no_match_wrong_account_id_length(self):
392+
self.assertFalse(
393+
is_account_regional_namespace_bucket(
394+
'bucket-12345-us-west-2-an'
395+
)
396+
)
397+
398+
def test_no_match_express_directory_bucket(self):
399+
self.assertFalse(
400+
is_account_regional_namespace_bucket('bucket--usw2-az1--x-s3')
401+
)
402+
403+
363404
class TestCreateWarning(unittest.TestCase):
364405
def test_create_warning(self):
365406
path = '/foo/'

0 commit comments

Comments
 (0)