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

s3: clean up use of tenanted bucket names #585

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions s3tests_boto3/functional/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import botocore.session
from botocore.exceptions import ClientError
from botocore.exceptions import ParamValidationError
from botocore.handlers import validate_bucket_name
import isodate
import email.utils
import datetime
Expand Down Expand Up @@ -10574,21 +10575,8 @@ def test_bucketv2_policy_acl():
client.delete_bucket_policy(Bucket=bucket_name)
client.put_bucket_acl(Bucket=bucket_name, ACL='public-read')

def tenanted_bucket_name(tenant):
def change_bucket_name(params, **kwargs):
old_name = params['context']['signing']['bucket']
new_name = "{}:{}".format(tenant, old_name)
params['Bucket'] = new_name
params['context']['signing']['bucket'] = new_name

# the : needs to be url-encoded for urls
new_name_url = "{}%3A{}".format(tenant, old_name)
params['url'] = params['url'].replace(old_name, new_name_url)
params['url_path'] = params['url_path'].replace(old_name, new_name_url)

return change_bucket_name

@pytest.mark.bucket_policy
@pytest.mark.fails_on_aws
def test_bucket_policy_different_tenant():
bucket_name = get_new_bucket()
client = get_client()
Expand All @@ -10615,12 +10603,13 @@ def test_bucket_policy_different_tenant():

# use the tenanted client to list the global tenant's bucket
tenant_client = get_tenant_client()
tenant_client.meta.events.register('before-call.s3.ListObjects', tenanted_bucket_name(''))
response = tenant_client.list_objects(Bucket=bucket_name)
tenant_client.meta.events.unregister("before-parameter-build.s3", validate_bucket_name)
response = tenant_client.list_objects(Bucket=":{}".format(bucket_name))

assert len(response['Contents']) == 1

@pytest.mark.bucket_policy
@pytest.mark.fails_on_aws
def test_bucket_policy_tenanted_bucket():
tenant_client = get_tenant_client()
bucket_name = get_new_bucket(tenant_client)
Expand Down Expand Up @@ -10649,9 +10638,9 @@ def test_bucket_policy_tenanted_bucket():

# use the global tenant's client to list the tenanted bucket
client = get_client()
client.meta.events.register('before-call.s3.ListObjects', tenanted_bucket_name(tenant))
client.meta.events.unregister("before-parameter-build.s3", validate_bucket_name)

response = client.list_objects(Bucket=bucket_name)
response = client.list_objects(Bucket="{}:{}".format(tenant, bucket_name))
assert len(response['Contents']) == 1

@pytest.mark.bucket_policy
Expand Down