Fixes a bug where certificates discovered by lemur's source plugins were not given the appropriate default notifications. (#447)
This commit is contained in:
@ -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()
|
||||
|
@ -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'
|
||||
|
@ -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),
|
||||
|
Reference in New Issue
Block a user