diff --git a/lemur/certificates/models.py b/lemur/certificates/models.py index bfe03d74..f807e1b6 100644 --- a/lemur/certificates/models.py +++ b/lemur/certificates/models.py @@ -51,6 +51,7 @@ def create_name(issuer, not_before, not_after, subject, san): # aws doesn't allow special chars except '-' disallowed_chars = ''.join(c for c in map(chr, range(256)) if not c.isalnum()) disallowed_chars = disallowed_chars.replace("-", "") + disallowed_chars = disallowed_chars.replace(".", "") temp = temp.replace('*', "WILDCARD") temp = temp.translate(None, disallowed_chars) # white space is silly too @@ -76,7 +77,7 @@ def cert_get_domains(cert): return the common name. :param cert: - :return: List of domainss + :return: List of domains """ domains = [] try: @@ -86,6 +87,7 @@ def cert_get_domains(cert): domains.append(entry) except Exception as e: current_app.logger.warning("Failed to get SubjectAltName: {0}".format(e)) + return domains @@ -122,6 +124,9 @@ def cert_is_wildcard(cert): if len(domains) == 1 and domains[0][0:1] == "*": return True + if cert.subject.get_attributes_for_oid(x509.OID_COMMON_NAME)[0].value[0:1] == "*": + return True + def cert_get_bitstrength(cert): """ diff --git a/lemur/destinations/service.py b/lemur/destinations/service.py index e98e4982..38dc600f 100644 --- a/lemur/destinations/service.py +++ b/lemur/destinations/service.py @@ -37,7 +37,7 @@ def update(destination_id, label, options, description): destination = get(destination_id) destination.label = label - description.options = options + destination.options = options destination.description = description return database.update(destination) diff --git a/lemur/manage.py b/lemur/manage.py index b104f157..c939fc58 100755 --- a/lemur/manage.py +++ b/lemur/manage.py @@ -54,54 +54,42 @@ ADMINS = frozenset(['']) THREADS_PER_PAGE = 8 -############# -## General ## -############# +# General # These will need to be set to `True` if you are developing locally CORS = False debug = False -# modify this if you are not using a local database -SQLALCHEMY_DATABASE_URI = 'postgresql://lemur:lemur@localhost:5432/lemur' - # this is the secret key used by flask session management SECRET_KEY = '{flask_secret_key}' # You should consider storing these separately from your config -LEMUR_SECRET_TOKEN = '{secret_token}' +LEMUR_TOKEN_SECRET = '{secret_token}' LEMUR_ENCRYPTION_KEY = '{encryption_key}' # this is a list of domains as regexes that only admins can issue LEMUR_RESTRICTED_DOMAINS = [] -################# -## Mail Server ## -################# +# Mail Server # Lemur currently only supports SES for sending email, this address # needs to be verified LEMUR_EMAIL = '' LEMUR_SECURITY_TEAM_EMAIL = [] -############# -## Logging ## -############# +# Logging LOG_LEVEL = "DEBUG" LOG_FILE = "lemur.log" -############## -## Database ## -############## +# Database -SQLALCHEMY_DATABASE_URI = '' +# modify this if you are not using a local database +SQLALCHEMY_DATABASE_URI = 'postgresql://lemur:lemur@localhost:5432/lemur' -######### -## AWS ## -######### +# AWS # Lemur will need STS assume role access to every destination you want to monitor #AWS_ACCOUNT_MAPPINGS = {{ diff --git a/lemur/tests/conftest.py b/lemur/tests/conftest.py index de9b3f44..e722e695 100644 --- a/lemur/tests/conftest.py +++ b/lemur/tests/conftest.py @@ -1,3 +1,4 @@ +import os import pytest from lemur import create_app @@ -33,14 +34,11 @@ def app(): Creates a new Flask application for a test duration. Uses application factory `create_app`. """ - app = create_app() - app.config['TESTING'] = True - app.config['LEMUR_ENCRYPTION_KEY'] = 'test' - - ctx = app.app_context() + _app = create_app(os.path.dirname(os.path.realpath(__file__)) + '/conf.py') + ctx = _app.app_context() ctx.push() - yield app + yield _app ctx.pop() diff --git a/lemur/tests/test_authorities.py b/lemur/tests/test_authorities.py index 3d9becbd..5bab6124 100644 --- a/lemur/tests/test_authorities.py +++ b/lemur/tests/test_authorities.py @@ -150,13 +150,3 @@ def test_admin_certificate_authorities_get(client): assert client.get(api.url_for(CertificateAuthority, certificate_id=1), headers=VALID_ADMIN_HEADER_TOKEN).status_code == 404 -def test_admin_certificate_authorities_post(client): - assert client.post(api.url_for(CertificateAuthority, certficate_id=1), headers=VALID_ADMIN_HEADER_TOKEN).status_code == 405 - - -def test_admin_certificate_authorities_put(client): - assert client.put(api.url_for(CertificateAuthority, certificate_id=1), headers=VALID_ADMIN_HEADER_TOKEN).status_code == 405 - - -def test_admin_certificate_authorities_delete(client): - assert client.delete(api.url_for(CertificateAuthority, certificate_id=1), headers=VALID_ADMIN_HEADER_TOKEN).status_code == 405 diff --git a/lemur/tests/test_certificates.py b/lemur/tests/test_certificates.py index 3d2757a4..9e573ec6 100644 --- a/lemur/tests/test_certificates.py +++ b/lemur/tests/test_certificates.py @@ -2,10 +2,6 @@ import pytest from lemur.certificates.views import * # noqa -def test_valid_authority(session): - assert 1 == 2 - - def test_pem_str(): from lemur.tests.certs import INTERNAL_VALID_LONG_STR assert pem_str(INTERNAL_VALID_LONG_STR, 'test') == INTERNAL_VALID_LONG_STR @@ -41,18 +37,6 @@ def test_create_basic_csr(): assert name.value in csr_config.values() -def test_import_certificate(): - assert 1 == 2 - - -def test_mint(): - assert 1 == 2 - - -def test_disassociate_aws_account(): - assert 1 == 2 - - def test_cert_get_cn(): from lemur.tests.certs import INTERNAL_VALID_LONG_CERT from lemur.certificates.models import cert_get_cn @@ -60,19 +44,19 @@ def test_cert_get_cn(): assert cert_get_cn(INTERNAL_VALID_LONG_CERT) == 'long.lived.com' -def test_cert_get_domains(): +def test_cert_get_subAltDomains(): from lemur.tests.certs import INTERNAL_VALID_SAN_CERT, INTERNAL_VALID_LONG_CERT from lemur.certificates.models import cert_get_domains - assert cert_get_domains(INTERNAL_VALID_LONG_CERT) == ['long.lived.com'] - assert cert_get_domains(INTERNAL_VALID_SAN_CERT) == ['example2.long.com', 'example3.long.com', 'san.example.com'] + assert cert_get_domains(INTERNAL_VALID_LONG_CERT) == [] + assert cert_get_domains(INTERNAL_VALID_SAN_CERT) == ['example2.long.com', 'example3.long.com'] def test_cert_is_san(): from lemur.tests.certs import INTERNAL_VALID_SAN_CERT, INTERNAL_VALID_LONG_CERT from lemur.certificates.models import cert_is_san - assert cert_is_san(INTERNAL_VALID_LONG_CERT) == False + assert cert_is_san(INTERNAL_VALID_LONG_CERT) == None assert cert_is_san(INTERNAL_VALID_SAN_CERT) == True @@ -80,7 +64,7 @@ def test_cert_is_wildcard(): from lemur.tests.certs import INTERNAL_VALID_WILDCARD_CERT, INTERNAL_VALID_LONG_CERT from lemur.certificates.models import cert_is_wildcard assert cert_is_wildcard(INTERNAL_VALID_WILDCARD_CERT) == True - assert cert_is_wildcard(INTERNAL_VALID_LONG_CERT) == False + assert cert_is_wildcard(INTERNAL_VALID_LONG_CERT) == None def test_cert_get_bitstrength(): diff --git a/lemur/tests/test_accounts.py b/lemur/tests/test_destinations.py similarity index 92% rename from lemur/tests/test_accounts.py rename to lemur/tests/test_destinations.py index f91c6525..4274bbe4 100644 --- a/lemur/tests/test_accounts.py +++ b/lemur/tests/test_destinations.py @@ -5,11 +5,11 @@ from json import dumps def test_crud(session): - destination = create('111111', 'destination1') + destination = create('testdest', 'aws-destination', {}, description='destination1') assert destination.id > 0 - destination = update(destination.id, 11111, 'destination2') - assert destination.label == 'destination2' + destination = update(destination.id, 'testdest2', {}, 'destination2') + assert destination.label == 'testdest2' assert len(get_all()) == 1 @@ -121,13 +121,13 @@ def test_admin_destinations_get(client): def test_admin_destinations_crud(client): assert client.post(api.url_for(DestinationsList), headers=VALID_ADMIN_HEADER_TOKEN).status_code == 400 - data = {'destinationNumber': 111, 'label': 'test', 'comments': 'test'} + data = {'plugin': {'slug': 'aws-destination', 'pluginOptions': {}}, 'label': 'test', 'description': 'test'} resp = client.post(api.url_for(DestinationsList), data=dumps(data), content_type='application/json', headers=VALID_ADMIN_HEADER_TOKEN) assert resp.status_code == 200 assert client.get(api.url_for(Destinations, destination_id=resp.json['id']), headers=VALID_ADMIN_HEADER_TOKEN).status_code == 200 resp = client.get(api.url_for(DestinationsList), headers=VALID_ADMIN_HEADER_TOKEN) assert resp.status_code == 200 - assert resp.json == {'items': [{'destinationNumber': 111, 'label': 'test', 'comments': 'test', 'id': 2}], 'total': 1} + assert resp.json['items'][0]['description'] == 'test' assert client.delete(api.url_for(Destinations, destination_id=2), headers=VALID_ADMIN_HEADER_TOKEN).status_code == 200 resp = client.get(api.url_for(DestinationsList), headers=VALID_ADMIN_HEADER_TOKEN) assert resp.status_code == 200