Add context fix to tests, Add regex, Flake8
This commit is contained in:
parent
4a181aff6e
commit
99ca0ac78d
|
@ -123,9 +123,7 @@ class AcmeHandler(object):
|
||||||
current_app.config.get("IDENTRUST_CROSS_SIGNED_LE_ICA_EXPIRATION_DATE", "17/03/21"), '%d/%m/%y'):
|
current_app.config.get("IDENTRUST_CROSS_SIGNED_LE_ICA_EXPIRATION_DATE", "17/03/21"), '%d/%m/%y'):
|
||||||
pem_certificate_chain = current_app.config.get("IDENTRUST_CROSS_SIGNED_LE_ICA")
|
pem_certificate_chain = current_app.config.get("IDENTRUST_CROSS_SIGNED_LE_ICA")
|
||||||
else:
|
else:
|
||||||
pem_certificate_chain = orderr.fullchain_pem[
|
pem_certificate_chain = orderr.fullchain_pem[len(pem_certificate):].lstrip()
|
||||||
len(pem_certificate): # noqa
|
|
||||||
].lstrip()
|
|
||||||
|
|
||||||
current_app.logger.debug(
|
current_app.logger.debug(
|
||||||
"{0} {1}".format(type(pem_certificate), type(pem_certificate_chain))
|
"{0} {1}".format(type(pem_certificate), type(pem_certificate_chain))
|
||||||
|
|
|
@ -121,9 +121,7 @@ class AcmeHttpChallenge(AcmeChallenge):
|
||||||
current_app.config.get("IDENTRUST_CROSS_SIGNED_LE_ICA_EXPIRATION_DATE", "17/03/21"), '%d/%m/%y'):
|
current_app.config.get("IDENTRUST_CROSS_SIGNED_LE_ICA_EXPIRATION_DATE", "17/03/21"), '%d/%m/%y'):
|
||||||
pem_certificate_chain = current_app.config.get("IDENTRUST_CROSS_SIGNED_LE_ICA")
|
pem_certificate_chain = current_app.config.get("IDENTRUST_CROSS_SIGNED_LE_ICA")
|
||||||
else:
|
else:
|
||||||
pem_certificate_chain = finalized_orderr.fullchain_pem[
|
pem_certificate_chain = finalized_orderr.fullchain_pem[len(pem_certificate):].lstrip()
|
||||||
len(pem_certificate): # noqa
|
|
||||||
].lstrip()
|
|
||||||
|
|
||||||
# validation is a random string, we use it as external id, to make it possible to implement revoke_certificate
|
# validation is a random string, we use it as external id, to make it possible to implement revoke_certificate
|
||||||
return pem_certificate, pem_certificate_chain, None
|
return pem_certificate, pem_certificate_chain, None
|
||||||
|
|
|
@ -309,7 +309,7 @@ class ACMEHttpIssuerPlugin(IssuerPlugin):
|
||||||
"name": "acme_url",
|
"name": "acme_url",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"required": True,
|
"required": True,
|
||||||
"validation": "/^http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+$/",
|
"validation": r"/^http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+$/",
|
||||||
"helpMessage": "Must be a valid web url starting with http[s]://",
|
"helpMessage": "Must be a valid web url starting with http[s]://",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -322,7 +322,7 @@ class ACMEHttpIssuerPlugin(IssuerPlugin):
|
||||||
"name": "email",
|
"name": "email",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"default": "",
|
"default": "",
|
||||||
"validation": "/^?([-a-zA-Z0-9.`?{}]+@\w+\.\w+)$/",
|
"validation": r"/^?([-a-zA-Z0-9.`?{}]+@\w+\.\w+)$/",
|
||||||
"helpMessage": "Email to use",
|
"helpMessage": "Email to use",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import patch, Mock
|
from unittest.mock import patch, Mock
|
||||||
|
|
||||||
|
from flask import Flask
|
||||||
from cryptography.x509 import DNSName
|
from cryptography.x509 import DNSName
|
||||||
from lemur.plugins.lemur_acme import acme_handlers
|
from lemur.plugins.lemur_acme import acme_handlers
|
||||||
|
|
||||||
|
@ -9,6 +10,16 @@ class TestAcmeHandler(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.acme = acme_handlers.AcmeHandler()
|
self.acme = acme_handlers.AcmeHandler()
|
||||||
|
|
||||||
|
# Creates a new Flask application for a test duration. In python 3.8, manual push of application context is
|
||||||
|
# needed to run tests in dev environment without getting error 'Working outside of application context'.
|
||||||
|
_app = Flask('lemur_test_acme')
|
||||||
|
self.ctx = _app.app_context()
|
||||||
|
assert self.ctx
|
||||||
|
self.ctx.push()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.ctx.pop()
|
||||||
|
|
||||||
def test_strip_wildcard(self):
|
def test_strip_wildcard(self):
|
||||||
expected = ("example.com", False)
|
expected = ("example.com", False)
|
||||||
result = self.acme.strip_wildcard("example.com")
|
result = self.acme.strip_wildcard("example.com")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import patch, Mock
|
from unittest.mock import patch, Mock
|
||||||
|
|
||||||
|
from flask import Flask
|
||||||
from acme import challenges
|
from acme import challenges
|
||||||
from lemur.plugins.lemur_acme import plugin
|
from lemur.plugins.lemur_acme import plugin
|
||||||
|
|
||||||
|
@ -11,6 +12,16 @@ class TestAcmeHttp(unittest.TestCase):
|
||||||
self.ACMEHttpIssuerPlugin = plugin.ACMEHttpIssuerPlugin()
|
self.ACMEHttpIssuerPlugin = plugin.ACMEHttpIssuerPlugin()
|
||||||
self.acme = plugin.AcmeHandler()
|
self.acme = plugin.AcmeHandler()
|
||||||
|
|
||||||
|
# Creates a new Flask application for a test duration. In python 3.8, manual push of application context is
|
||||||
|
# needed to run tests in dev environment without getting error 'Working outside of application context'.
|
||||||
|
_app = Flask('lemur_test_acme')
|
||||||
|
self.ctx = _app.app_context()
|
||||||
|
assert self.ctx
|
||||||
|
self.ctx.push()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.ctx.pop()
|
||||||
|
|
||||||
@patch("lemur.plugins.lemur_acme.plugin.current_app")
|
@patch("lemur.plugins.lemur_acme.plugin.current_app")
|
||||||
def test_create_authority(self, mock_current_app):
|
def test_create_authority(self, mock_current_app):
|
||||||
mock_current_app.config = Mock()
|
mock_current_app.config = Mock()
|
||||||
|
|
Loading…
Reference in New Issue