def create_cert_that_expires_in_days(days, serial=None, domains=None, owner=None): import random from random import randrange from string import ascii_lowercase now = arrow.utcnow() not_after = now + timedelta( days=days, hours=1) # a bit more than specified since we'll check in the future certificate = CertificateFactory() certificate.not_after = not_after certificate.notify = True certificate.owner = ''.join( random.choice(ascii_lowercase) for _ in range(10)) + '@example.com' endpoints = [] for i in range(0, randrange(0, 5)): endpoints.append(EndpointFactory()) certificate.endpoints = endpoints if serial: certificate.serial = serial if owner: certificate.owner = owner if domains: certificate.domains = domains return certificate
def test_rotate_certificate(client, source_plugin): from lemur.deployment.service import rotate_certificate new_certificate = CertificateFactory() endpoint = EndpointFactory() rotate_certificate(endpoint, new_certificate) assert endpoint.certificate == new_certificate
def test_send_rotation_notification(notification_plugin, certificate): from lemur.notifications.messaging import send_rotation_notification verify_sender_email() new_cert = CertificateFactory() new_cert.replaces.append(certificate) assert send_rotation_notification(new_cert) new_cert.endpoints = [EndpointFactory()] assert send_rotation_notification(new_cert)
def test_send_rotation_notification(certificate, endpoint, source_plugin): from lemur.notifications.messaging import send_rotation_notification from lemur.deployment.service import rotate_certificate new_certificate = CertificateFactory() rotate_certificate(endpoint, new_certificate) new_certificate.replaces.append(certificate) assert endpoint.certificate == new_certificate verify_sender_email() assert send_rotation_notification(new_certificate) new_certificate.endpoints = [EndpointFactory()] assert send_rotation_notification(new_certificate)
def create_cert_that_expires_in_days(days): from random import randrange now = arrow.utcnow() not_after = now + timedelta(days=days, hours=1) # a bit more than specified since we'll check in the future certificate = CertificateFactory() certificate.not_after = not_after certificate.notify = True endpoints = [] for i in range(0, randrange(0, 5)): endpoints.append(EndpointFactory()) certificate.endpoints = endpoints return certificate
def test_get_all_certs_attached_to_endpoint_without_autorotate(session): from lemur.certificates.service import get_all_certs_attached_to_endpoint_without_autorotate, \ cleanup_after_revoke from lemur.tests.factories import EndpointFactory # add a certificate with endpoint EndpointFactory() list_before = get_all_certs_attached_to_endpoint_without_autorotate() len_list_before = len(list_before) assert len_list_before > 0 # revoked the first certificate first_cert_with_endpoint = list_before[0] cleanup_after_revoke(first_cert_with_endpoint) list_after = get_all_certs_attached_to_endpoint_without_autorotate() assert len(list_after) + 1 == len_list_before
def test_send_evocation_notification(notification_plugin, certificate): from lemur.notifications.messaging import send_revocation_notification verify_sender_email() certificate.endpoints = [EndpointFactory()] assert send_revocation_notification(certificate)
def test_send_reissue_failed_notification(certificate): from lemur.notifications.messaging import send_reissue_failed_notification verify_sender_email() certificate.endpoints = [EndpointFactory()] assert send_reissue_failed_notification(certificate)