Fixes a bug where certificates discovered by lemur's source plugins were not given the appropriate default notifications. (#447)

This commit is contained in:
kevgliss 2016-10-11 21:08:13 -07:00 committed by GitHub
parent ee028382df
commit 708d85abeb
4 changed files with 45 additions and 3 deletions

View File

@ -17,6 +17,8 @@ from lemur.certificates import service as cert_service
from lemur.endpoints import service as endpoint_service
from lemur.destinations import service as destination_service
from lemur.certificates.schemas import CertificateUploadInputSchema
from lemur.plugins.base import plugins
@ -62,11 +64,17 @@ def _disassociate_endpoints_from_source(endpoints, source):
def certificate_create(certificate, source):
cert = cert_service.import_certificate(**certificate)
data, errors = CertificateUploadInputSchema().load(certificate)
if errors:
raise Exception("Unable to import certificate: {reasons}".format(reasons=errors))
cert = cert_service.import_certificate(**data)
cert.description = "This certificate was automatically discovered by Lemur"
cert.sources.append(source)
sync_update_destination(cert, source)
database.update(cert)
return cert
def certificate_update(certificate, source):

View File

@ -10,7 +10,7 @@ from lemur.database import db as _db
from lemur.auth.service import create_token
from .factories import AuthorityFactory, NotificationFactory, DestinationFactory, \
CertificateFactory, UserFactory, RoleFactory
CertificateFactory, UserFactory, RoleFactory, SourceFactory
def pytest_runtest_setup(item):
@ -91,6 +91,13 @@ def destination(session):
return d
@pytest.fixture
def source(session):
s = SourceFactory()
session.commit()
return s
@pytest.fixture
def notification(session):
n = NotificationFactory()

View File

@ -10,6 +10,7 @@ from lemur.database import db
from lemur.authorities.models import Authority
from lemur.certificates.models import Certificate
from lemur.destinations.models import Destination
from lemur.sources.models import Source
from lemur.notifications.models import Notification
from lemur.users.models import User
from lemur.roles.models import Role
@ -145,6 +146,16 @@ class DestinationFactory(BaseFactory):
model = Destination
class SourceFactory(BaseFactory):
"""Source factory."""
plugin_name = 'test-source'
label = Sequence(lambda n: 'source{0}'.format(n))
class Meta:
"""Factory Configuration."""
model = Source
class NotificationFactory(BaseFactory):
"""Notification factory."""
plugin_name = 'test-notification'

View File

@ -2,7 +2,7 @@ import pytest
from lemur.sources.views import * # noqa
from .vectors import VALID_ADMIN_HEADER_TOKEN, VALID_USER_HEADER_TOKEN
from .vectors import VALID_ADMIN_HEADER_TOKEN, VALID_USER_HEADER_TOKEN, INTERNAL_PRIVATE_KEY_A_STR, INTERNAL_VALID_WILDCARD_STR
def validate_source_schema(client):
@ -18,6 +18,22 @@ def validate_source_schema(client):
assert not errors
def test_create_certificate(source):
from lemur.sources.service import certificate_create
with pytest.raises(Exception):
certificate_create({}, source)
data = {
'body': INTERNAL_VALID_WILDCARD_STR,
'private_key': INTERNAL_PRIVATE_KEY_A_STR,
'owner': 'bob@example.com'
}
cert = certificate_create(data, source)
assert cert.notifications
@pytest.mark.parametrize("token,status", [
(VALID_USER_HEADER_TOKEN, 404),
(VALID_ADMIN_HEADER_TOKEN, 404),