From abe78a892e8ddcdf2ac2fffd57fbe88cb862c812 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Mon, 23 Oct 2023 21:58:52 +0000 Subject: [PATCH] S3Control: create_access_point() now returns the correct Alias (#6945) --- .github/workflows/tests_real_aws.yml | 2 +- moto/s3control/responses.py | 2 +- tests/test_s3/__init__.py | 4 +- .../test_s3control_access_points.py | 41 +++++++++++-------- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/.github/workflows/tests_real_aws.yml b/.github/workflows/tests_real_aws.yml index 4ff82f327..64303effd 100644 --- a/.github/workflows/tests_real_aws.yml +++ b/.github/workflows/tests_real_aws.yml @@ -42,4 +42,4 @@ jobs: env: MOTO_TEST_ALLOW_AWS_REQUEST: ${{ true }} 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 diff --git a/moto/s3control/responses.py b/moto/s3control/responses.py index 2e1713e19..536672f2c 100644 --- a/moto/s3control/responses.py +++ b/moto/s3control/responses.py @@ -159,7 +159,7 @@ CREATE_ACCESS_POINT_TEMPLATE = """ 1549581b-12b7-11e3-895e-1334aEXAMPLE - {{ access_point.name }} + {{ access_point.alias }} {{ access_point.arn }} """ diff --git a/tests/test_s3/__init__.py b/tests/test_s3/__init__.py index c65c7d84f..d5cda0981 100644 --- a/tests/test_s3/__init__.py +++ b/tests/test_s3/__init__.py @@ -1,7 +1,7 @@ import boto3 import os 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 uuid import uuid4 @@ -33,7 +33,7 @@ def s3_aws_verified(func): print(f"Test {func} will create {bucket_name}") resp = create_bucket_and_test(bucket_name, client) else: - with mock_s3(): + with mock_s3(), mock_sts(), mock_s3control(): resp = create_bucket_and_test(bucket_name, client) return resp diff --git a/tests/test_s3control/test_s3control_access_points.py b/tests/test_s3control/test_s3control_access_points.py index 7e7bc0993..265a0b83e 100644 --- a/tests/test_s3control/test_s3control_access_points.py +++ b/tests/test_s3control/test_s3control_access_points.py @@ -4,18 +4,9 @@ import boto3 import pytest from botocore.client import ClientError +from uuid import uuid4 from moto import mock_s3control - - -@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" +from tests.test_s3 import s3_aws_verified @mock_s3control @@ -96,17 +87,31 @@ def test_get_access_point_full(): } -@mock_s3control -def test_delete_access_point(): - client = boto3.client("s3control", region_name="ap-southeast-1") +@pytest.mark.aws_verified +@s3_aws_verified +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( - AccountId="111111111111", Name="ap_name", Bucket="mybucket" + client = boto3.client("s3control", region_name="us-east-1") + 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: - client.get_access_point(AccountId="111111111111", Name="ap_name") + client.get_access_point(AccountId=account_id, Name=ap_name) err = exc.value.response["Error"] assert err["Code"] == "NoSuchAccessPoint" + assert err["Message"] == "The specified accesspoint does not exist"