S3Control: create_access_point() now returns the correct Alias (#6945)
This commit is contained in:
parent
2b4d29eafd
commit
abe78a892e
2
.github/workflows/tests_real_aws.yml
vendored
2
.github/workflows/tests_real_aws.yml
vendored
@ -42,4 +42,4 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
MOTO_TEST_ALLOW_AWS_REQUEST: ${{ true }}
|
MOTO_TEST_ALLOW_AWS_REQUEST: ${{ true }}
|
||||||
run: |
|
run: |
|
||||||
pytest -sv tests/test_dynamodb/ tests/test_ec2/ tests/test_lakeformation/ tests/test_ses/ tests/test_s3 -m aws_verified
|
pytest -sv tests/test_dynamodb/ tests/test_ec2/ tests/test_lakeformation/ tests/test_ses/ tests/test_s3* -m aws_verified
|
||||||
|
@ -159,7 +159,7 @@ CREATE_ACCESS_POINT_TEMPLATE = """<CreateAccessPointResult>
|
|||||||
<ResponseMetadata>
|
<ResponseMetadata>
|
||||||
<RequestId>1549581b-12b7-11e3-895e-1334aEXAMPLE</RequestId>
|
<RequestId>1549581b-12b7-11e3-895e-1334aEXAMPLE</RequestId>
|
||||||
</ResponseMetadata>
|
</ResponseMetadata>
|
||||||
<Alias>{{ access_point.name }}</Alias>
|
<Alias>{{ access_point.alias }}</Alias>
|
||||||
<AccessPointArn>{{ access_point.arn }}</AccessPointArn>
|
<AccessPointArn>{{ access_point.arn }}</AccessPointArn>
|
||||||
</CreateAccessPointResult>
|
</CreateAccessPointResult>
|
||||||
"""
|
"""
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import boto3
|
import boto3
|
||||||
import os
|
import os
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from moto import mock_s3
|
from moto import mock_s3, mock_sts, mock_s3control
|
||||||
from moto.s3.responses import DEFAULT_REGION_NAME
|
from moto.s3.responses import DEFAULT_REGION_NAME
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ def s3_aws_verified(func):
|
|||||||
print(f"Test {func} will create {bucket_name}")
|
print(f"Test {func} will create {bucket_name}")
|
||||||
resp = create_bucket_and_test(bucket_name, client)
|
resp = create_bucket_and_test(bucket_name, client)
|
||||||
else:
|
else:
|
||||||
with mock_s3():
|
with mock_s3(), mock_sts(), mock_s3control():
|
||||||
resp = create_bucket_and_test(bucket_name, client)
|
resp = create_bucket_and_test(bucket_name, client)
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
@ -4,18 +4,9 @@ import boto3
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from botocore.client import ClientError
|
from botocore.client import ClientError
|
||||||
|
from uuid import uuid4
|
||||||
from moto import mock_s3control
|
from moto import mock_s3control
|
||||||
|
from tests.test_s3 import s3_aws_verified
|
||||||
|
|
||||||
@mock_s3control
|
|
||||||
def test_create_access_point():
|
|
||||||
client = boto3.client("s3control", region_name="eu-west-1")
|
|
||||||
resp = client.create_access_point(
|
|
||||||
AccountId="111111111111", Name="ap_name", Bucket="mybucket"
|
|
||||||
)
|
|
||||||
|
|
||||||
assert "AccessPointArn" in resp
|
|
||||||
assert resp["Alias"] == "ap_name"
|
|
||||||
|
|
||||||
|
|
||||||
@mock_s3control
|
@mock_s3control
|
||||||
@ -96,17 +87,31 @@ def test_get_access_point_full():
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@mock_s3control
|
@pytest.mark.aws_verified
|
||||||
def test_delete_access_point():
|
@s3_aws_verified
|
||||||
client = boto3.client("s3control", region_name="ap-southeast-1")
|
def test_delete_access_point(bucket_name=None):
|
||||||
|
sts = boto3.client("sts", "us-east-1")
|
||||||
|
account_id = sts.get_caller_identity()["Account"]
|
||||||
|
|
||||||
client.create_access_point(
|
client = boto3.client("s3control", region_name="us-east-1")
|
||||||
AccountId="111111111111", Name="ap_name", Bucket="mybucket"
|
ap_name = "ap-" + str(uuid4())[0:6]
|
||||||
|
expected_arn = f"arn:aws:s3:us-east-1:{account_id}:accesspoint/{ap_name}"
|
||||||
|
|
||||||
|
create = client.create_access_point(
|
||||||
|
AccountId=account_id, Name=ap_name, Bucket=bucket_name
|
||||||
)
|
)
|
||||||
|
assert create["Alias"].startswith(ap_name)
|
||||||
|
assert create["Alias"].endswith("-s3alias")
|
||||||
|
assert create["AccessPointArn"] == expected_arn
|
||||||
|
|
||||||
client.delete_access_point(AccountId="111111111111", Name="ap_name")
|
get = client.get_access_point(AccountId=account_id, Name=ap_name)
|
||||||
|
assert get["Alias"] == create["Alias"]
|
||||||
|
assert get["AccessPointArn"] == expected_arn
|
||||||
|
|
||||||
|
client.delete_access_point(AccountId=account_id, Name=ap_name)
|
||||||
|
|
||||||
with pytest.raises(ClientError) as exc:
|
with pytest.raises(ClientError) as exc:
|
||||||
client.get_access_point(AccountId="111111111111", Name="ap_name")
|
client.get_access_point(AccountId=account_id, Name=ap_name)
|
||||||
err = exc.value.response["Error"]
|
err = exc.value.response["Error"]
|
||||||
assert err["Code"] == "NoSuchAccessPoint"
|
assert err["Code"] == "NoSuchAccessPoint"
|
||||||
|
assert err["Message"] == "The specified accesspoint does not exist"
|
||||||
|
Loading…
Reference in New Issue
Block a user