def test_delete(acm_client, ssm_client): actions = certifier.actions() certificates = actions.query(identifier="certificate1") success, failed = actions.delete((certificates[0], )) assert len(success) == 1 assert len(failed) == 0 assert len(actions.query(identifier="certificate1")) == 2
def test_request_certificate(acm_client): actions = certifier.actions() actions.request_certificate("certificate1", ("example.com", )) assert len( actions.query(identifier="certificate1", state=certifier.States.PENDING)) == 1 assert len( actions.query(identifier="certificate1", state=certifier.States.MARKED_FOR_DELETION)) >= 1
def test_query_with_acm_state(acm_client): actions = certifier.actions() certificates = actions.query(with_acm_state=True) assert len(certificates) >= 1 for certificate in certificates: assert certificate.acm_state in ( "PENDING_VALIDATION", "FAILED", "ISSUED", )
def test_mark_for_deletion(acm_client): actions = certifier.actions() certificates = actions.query(identifier="certificate1") actions.mark_for_deletion(certificates) certificates = actions.query(identifier="certificate1") assert ( certifier.States.MARKED_FOR_DELETION, certifier.States.MARKED_FOR_DELETION, certifier.States.MARKED_FOR_DELETION, ) == tuple(certificate.state for certificate in certificates)
def test_delete_non_existing(acm_client): actions = certifier.actions() certificates = actions.query(identifier="certificate1") deleted_certificate = certificates[0] _, _ = actions.delete((deleted_certificate, )) certificates = actions.query(identifier="certificate1") success, failed = actions.delete((deleted_certificate, )) print(success) assert len(success) == 1 assert len(failed) == 0 assert len(actions.query(identifier="certificate1")) == 2
def test_certificate_transition(acm_client, ssm_client): actions = certifier.actions() certificate = actions.query(state=certifier.States.PENDING, with_acm_state=True)[0] assert certificate.acm_state == "PENDING_VALIDATION" # Wait for validation (moto internally validates after 60s) time.sleep(60) transition_certificates = actions.query(identifier=certificate.identifier, state=certifier.States.PENDING, with_acm_state=True) assert transition_certificates[0].acm_state == "ISSUED" assert transition_certificates[0].arn == certificate.arn actions.transition_to_available(transition_certificates) available_certificates = actions.query(identifier=certificate.identifier, state=certifier.States.AVAILABLE) assert available_certificates[0].arn == certificate.arn assert len(available_certificates) == 1
# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>. import os import re from typing import List, Generator, Tuple, Dict import boto3 # type: ignore from certifier import certifier actions = certifier.actions() s3_client = boto3.client("s3") def get_certificates_from_s3_event( event: Dict, ) -> Tuple[List[Tuple[str, str, str]], List[Tuple[str, str, str]], List[Tuple[ str, str, str]]]: """ Returns a tuple containing three lists. The first one is a list of certificates to delete, the second is a list of certificates to create, and the third one contains certificates that failed a validation. Each create and delete list item is a tuple formed by the s3 bucket name, the key of the object in the bucket and the key stripped of file extensions (up to the first dot). The third element of tuples in the list of failed items is the reason for the failure instead of the object key stripped of extensions. The following validation is performed: * Make sure the S3 key only contains letters, numbers and the characters .-_ to make sure it can be used as the name of a parameter in Parameter Store.
def test_query_marked_for_deletion_state(acm_client): actions = certifier.actions() certificates = actions.query(identifier="certificate1", state=certifier.States.MARKED_FOR_DELETION) assert len(certificates) == 1 assert certificates[0].state == certifier.States.MARKED_FOR_DELETION
def test_query_pending_state(acm_client): actions = certifier.actions() certificates = actions.query(identifier="certificate1", state=certifier.States.PENDING) assert len(certificates) == 1 assert certificates[0].state == certifier.States.PENDING
def test_query_all(acm_client): actions = certifier.actions() assert len(actions.query()) == 3
def test_query_all_states(acm_client): actions = certifier.actions() actions.request_certificate("certificate1", ("example.com", )) assert len(actions.query(identifier="certificate1")) == 4
def test_get_acm_state(acm_client): actions = certifier.actions() certificate = actions.query()[0] assert actions._get_acm_state(certificate) == "PENDING_VALIDATION"
def test_delete_invalid_arn(acm_client): actions = certifier.actions() success, failed = actions.delete((None, ), ) assert len(success) == 0 assert len(failed) == 1 assert len(actions.query(identifier="certificate1")) == 3
def test_query_available_state(acm_client): actions = certifier.actions() certificates = actions.query(identifier="certificate1", state=certifier.States.AVAILABLE) assert len(certificates) == 1 assert certificates[0].state == certifier.States.AVAILABLE