From a6a4f458e029f9a54cac57ecf284327d137406b5 Mon Sep 17 00:00:00 2001 From: sirferl Date: Fri, 9 Oct 2020 11:35:04 +0200 Subject: [PATCH 1/3] added Tests and removed problems in test-setup --- lemur/plugins/lemur_entrust/tests/test_entrust.py | 14 ++++++++++---- lemur/tests/conf.py | 6 +++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lemur/plugins/lemur_entrust/tests/test_entrust.py b/lemur/plugins/lemur_entrust/tests/test_entrust.py index b1cd4c83..b3f2e0c4 100644 --- a/lemur/plugins/lemur_entrust/tests/test_entrust.py +++ b/lemur/plugins/lemur_entrust/tests/test_entrust.py @@ -3,6 +3,7 @@ from unittest.mock import patch, Mock import arrow from cryptography import x509 from lemur.plugins.lemur_entrust import plugin +from freezegun import freeze_time def config_mock(*args): @@ -20,12 +21,17 @@ def config_mock(*args): } return values[args[0]] +@patch("lemur.plugins.lemur_digicert.plugin.current_app") +def test_determine_end_date(mock_current_app): + with freeze_time(time_to_freeze=arrow.get(2016, 11, 3).datetime): + assert arrow.get(2017, 12, 3).format('YYYY-MM-DD') == plugin.determine_end_date(0) # 1 year + 1 month + assert arrow.get(2017, 3, 5).format('YYYY-MM-DD') == plugin.determine_end_date(arrow.get(2017, 3, 5)) + assert arrow.get(2017, 12, 3).format('YYYY-MM-DD') == plugin.determine_end_date(arrow.get(2020, 5, 7)) @patch("lemur.plugins.lemur_entrust.plugin.current_app") def test_process_options(mock_current_app, authority): mock_current_app.config.get = Mock(side_effect=config_mock) - plugin.determine_end_date = Mock(return_value=arrow.get(2020, 10, 7).format('YYYY-MM-DD')) - + plugin.determine_end_date = Mock(return_value=arrow.get(2017, 11, 5).format('YYYY-MM-DD')) authority.name = "Entrust" names = [u"one.example.com", u"two.example.com", u"three.example.com"] options = { @@ -35,7 +41,7 @@ def test_process_options(mock_current_app, authority): "extensions": {"sub_alt_names": {"names": [x509.DNSName(x) for x in names]}}, "organization": "Example, Inc.", "organizational_unit": "Example Org", - "validity_end": arrow.get(2020, 10, 7), + "validity_end": arrow.utcnow().shift(years=1, months=+1), "authority": authority, } @@ -43,7 +49,7 @@ def test_process_options(mock_current_app, authority): "signingAlg": "SHA-2", "eku": "SERVER_AND_CLIENT_AUTH", "certType": "ADVANTAGE_SSL", - "certExpiryDate": arrow.get(2020, 10, 7).format('YYYY-MM-DD'), + "certExpiryDate": arrow.get(2017, 11, 5).format('YYYY-MM-DD'), "tracking": { "requesterName": mock_current_app.config.get("ENTRUST_NAME"), "requesterEmail": mock_current_app.config.get("ENTRUST_EMAIL"), diff --git a/lemur/tests/conf.py b/lemur/tests/conf.py index bf033421..0a288327 100644 --- a/lemur/tests/conf.py +++ b/lemur/tests/conf.py @@ -32,9 +32,9 @@ LEMUR_ENCRYPTION_KEYS = "o61sBLNBSGtAckngtNrfVNd8xy8Hp9LBGDstTbMbqCY=" # List of domain regular expressions that non-admin users can issue LEMUR_WHITELISTED_DOMAINS = [ - "^[a-zA-Z0-9-]+\.example\.com$", - "^[a-zA-Z0-9-]+\.example\.org$", - "^example\d+\.long\.com$", + r"^[a-zA-Z0-9-]+\.example\.com$", + r"^[a-zA-Z0-9-]+\.example\.org$", + r"^example\d+\.long\.com$", ] # Mail Server From d43e240a2a2be7ab879e696d026d630232c1544d Mon Sep 17 00:00:00 2001 From: sirferl Date: Fri, 9 Oct 2020 11:41:44 +0200 Subject: [PATCH 2/3] dded ELIF at determine_end_date, becuase of error. --- lemur/plugins/lemur_entrust/plugin.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lemur/plugins/lemur_entrust/plugin.py b/lemur/plugins/lemur_entrust/plugin.py index 9b7848ed..515e2400 100644 --- a/lemur/plugins/lemur_entrust/plugin.py +++ b/lemur/plugins/lemur_entrust/plugin.py @@ -34,8 +34,7 @@ def determine_end_date(end_date): if not end_date: end_date = max_validity_end - - if end_date > max_validity_end: + elif end_date > max_validity_end: end_date = max_validity_end return end_date.format('YYYY-MM-DD') From 5a968ffe6304dbaedd5a254a77c6c16c632765b5 Mon Sep 17 00:00:00 2001 From: sirferl Date: Fri, 9 Oct 2020 12:05:57 +0200 Subject: [PATCH 3/3] Lint errors --- lemur/plugins/lemur_entrust/tests/test_entrust.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lemur/plugins/lemur_entrust/tests/test_entrust.py b/lemur/plugins/lemur_entrust/tests/test_entrust.py index b3f2e0c4..354e204e 100644 --- a/lemur/plugins/lemur_entrust/tests/test_entrust.py +++ b/lemur/plugins/lemur_entrust/tests/test_entrust.py @@ -21,6 +21,7 @@ def config_mock(*args): } return values[args[0]] + @patch("lemur.plugins.lemur_digicert.plugin.current_app") def test_determine_end_date(mock_current_app): with freeze_time(time_to_freeze=arrow.get(2016, 11, 3).datetime): @@ -28,6 +29,7 @@ def test_determine_end_date(mock_current_app): assert arrow.get(2017, 3, 5).format('YYYY-MM-DD') == plugin.determine_end_date(arrow.get(2017, 3, 5)) assert arrow.get(2017, 12, 3).format('YYYY-MM-DD') == plugin.determine_end_date(arrow.get(2020, 5, 7)) + @patch("lemur.plugins.lemur_entrust.plugin.current_app") def test_process_options(mock_current_app, authority): mock_current_app.config.get = Mock(side_effect=config_mock)