11import pytest
2+ from botocore .exceptions import ClientError
23from localstack_snapshot .snapshots .transformer import SortingTransformer
34from moto import settings as moto_settings
45
56from localstack .testing .aws .util import is_aws_cloud
67from localstack .testing .pytest import markers
78from localstack .utils .crypto import generate_ssl_cert
89from localstack .utils .strings import short_uid
9- from localstack .utils .sync import retry
10+ from localstack .utils .sync import retry , wait_until
1011
1112
1213class TestACM :
@@ -27,7 +28,7 @@ class TestACM:
2728 ]
2829 )
2930 def test_import_certificate (self , tmp_path , aws_client , cleanups , snapshot ):
30- with pytest .raises (Exception ) as exc_info :
31+ with pytest .raises (ClientError ) as exc_info :
3132 aws_client .acm .import_certificate (Certificate = b"CERT123" , PrivateKey = b"KEY123" )
3233 assert exc_info .value .response ["Error" ]["Code" ] == "ValidationException"
3334
@@ -72,6 +73,15 @@ def test_domain_validation(self, acm_request_certificate, aws_client, snapshot):
7273 snapshot .add_transformer (snapshot .transform .key_value ("SignatureAlgorithm" ))
7374
7475 certificate_arn = acm_request_certificate ()["CertificateArn" ]
76+
77+ # we are manually waiting for some fields to be returned, as they are missing soon after creating the cert
78+ def _cert_has_required_fields () -> bool :
79+ _resp = aws_client .acm .describe_certificate (CertificateArn = certificate_arn )
80+ return "DomainName" in _resp ["Certificate" ]
81+
82+ if is_aws_cloud ():
83+ wait_until (_cert_has_required_fields , wait = 2 , max_retries = 20 )
84+
7585 result = aws_client .acm .describe_certificate (CertificateArn = certificate_arn )
7686 snapshot .match ("describe-certificate" , result )
7787
@@ -84,8 +94,17 @@ def test_boto_wait_for_certificate_validation(
8494 waiter = aws_client .acm .get_waiter ("certificate_validated" )
8595 waiter .wait (CertificateArn = certificate_arn , WaiterConfig = {"Delay" : 0.5 , "MaxAttempts" : 3 })
8696
87- @markers .aws .validated
88- @markers .snapshot .skip_snapshot_verify (paths = ["$..Certificate.SignatureAlgorithm" ])
97+ @markers .aws .manual_setup_required
98+ # this test requires manual input to our DNS provider
99+ @markers .snapshot .skip_snapshot_verify (
100+ paths = [
101+ "$..Certificate.SignatureAlgorithm" ,
102+ # those should also be returned by AWS, but regenerating the snapshots needs manual input
103+ # skipped for now, validated by other tests
104+ "$..Certificate.Options.Export" ,
105+ "$..Exported" ,
106+ ]
107+ )
89108 def test_certificate_for_subdomain_wildcard (
90109 self , acm_request_certificate , aws_client , snapshot , monkeypatch
91110 ):
@@ -123,7 +142,7 @@ def _get_cert_with_records():
123142 if is_aws_cloud ():
124143 # Wait until DNS entry has been added (needs to be done manually!)
125144 # Note: When running parity tests against AWS, we need to add the CNAME record to our DNS
126- # server (currently with gandi.net ), to enable validation of the certificate.
145+ # server (currently with Route53 ), to enable validation of the certificate.
127146 prompt = (
128147 f"Please add the following CNAME entry to the LocalStack DNS server, then hit [ENTER] once "
129148 f"the certificate has been validated in AWS: { dns_options ['Name' ]} = { dns_options ['Value' ]} "
@@ -161,6 +180,7 @@ def _get_cert_issued():
161180 "$..ResourceRecord" ,
162181 "$..SignatureAlgorithm" ,
163182 "$..Serial" ,
183+ "$..ExportOption" ,
164184 ]
165185 )
166186 def test_create_certificate_for_multiple_alternative_domains (
0 commit comments