Exemplo n.º 1
0
    def test_remove_validation_records(self, cfngin_context, monkeypatch):
        """Test remove_validation_records."""
        # setup context
        acm_stubber = cfngin_context.add_stubber('acm', 'us-east-1')
        r53_stubber = cfngin_context.add_stubber('route53', 'us-east-1')
        cfngin_context.config.namespace = 'test'

        cert_arn = 'arn:aws:acm:us-east-1:012345678901:certificate/test'
        expected_cert_request = {'CertificateArn': cert_arn}

        cert = Certificate(context=cfngin_context,
                           provider=MagicMock(),
                           domain='example.com',
                           hosted_zone_id='test')
        monkeypatch.setattr(cert, 'get_certificate', lambda: cert_arn)

        acm_stubber.add_response(
            'describe_certificate',
            gen_certificate(
                CertificateArn=cert_arn,
                DomainValidationOptions=[gen_domain_validation_option()]),
            expected_cert_request)
        acm_stubber.add_response(
            'describe_certificate',
            gen_certificate(
                CertificateArn=cert_arn,
                DomainValidationOptions=[
                    gen_domain_validation_option(ValidationMethod='EMAIL')
                ]), expected_cert_request)

        r53_stubber.add_response(
            'change_resource_record_sets', gen_change_resource_record_sets(), {
                'HostedZoneId':
                cert.args.hosted_zone_id,
                'ChangeBatch':
                gen_change_batch(changes=[
                    gen_change(action='DELETE',
                               record_set=gen_record_set(
                                   use_resource_record=True,
                                   TTL=cert.args.ttl,
                                   **gen_domain_validation_option()
                                   ['ResourceRecord']))
                ])
            })

        with acm_stubber, r53_stubber, pytest.raises(ValueError) as excinfo:
            assert not cert.remove_validation_records()
            cert.remove_validation_records()

        acm_stubber.assert_no_pending_responses()
        r53_stubber.assert_no_pending_responses()
        assert str(excinfo.value) == 'Must provide one of more record sets'
Exemplo n.º 2
0
    def test_remove_validation_records(self, cfngin_context: MockCFNginContext,
                                       monkeypatch: MonkeyPatch) -> None:
        """Test remove_validation_records."""
        # setup context
        acm_stubber = cfngin_context.add_stubber("acm", "us-east-1")
        r53_stubber = cfngin_context.add_stubber("route53", "us-east-1")
        cfngin_context.config.namespace = "test"

        cert_arn = "arn:aws:acm:us-east-1:012345678901:certificate/test"
        expected_cert_request = {"CertificateArn": cert_arn}

        cert = Certificate(
            context=cfngin_context,
            provider=MagicMock(),
            domain="example.com",
            hosted_zone_id="test",
        )
        monkeypatch.setattr(cert, "get_certificate", lambda: cert_arn)

        acm_stubber.add_response(
            "describe_certificate",
            gen_certificate(
                CertificateArn=cert_arn,
                DomainValidationOptions=[gen_domain_validation_option()],
            ),
            expected_cert_request,
        )
        acm_stubber.add_response(
            "describe_certificate",
            gen_certificate(
                CertificateArn=cert_arn,
                DomainValidationOptions=[
                    gen_domain_validation_option(ValidationMethod="EMAIL")
                ],
            ),
            expected_cert_request,
        )

        r53_stubber.add_response(
            "change_resource_record_sets",
            gen_change_resource_record_sets(),
            {
                "HostedZoneId":
                cert.args.hosted_zone_id,
                "ChangeBatch":
                gen_change_batch(changes=[
                    gen_change(
                        action="DELETE",
                        record_set=cast(
                            "ResourceRecordSetTypeDef",
                            gen_record_set(
                                use_resource_record=True,
                                TTL=cert.args.ttl,
                                **gen_domain_validation_option()
                                ["ResourceRecord"],
                            ),
                        ),
                    )
                ]),
            },
        )

        with acm_stubber, r53_stubber, pytest.raises(ValueError) as excinfo:
            assert not cert.remove_validation_records()
            cert.remove_validation_records()

        acm_stubber.assert_no_pending_responses()
        r53_stubber.assert_no_pending_responses()
        assert str(excinfo.value) == "Must provide one of more record sets"