mirror of
https://github.com/certbot/certbot.git
synced 2026-08-03 03:32:13 +02:00
pep8 letsencrypt
This commit is contained in:
@@ -244,7 +244,7 @@ class AuthHandler(object):
|
||||
|
||||
"""
|
||||
for authzr_challb in authzr.body.challenges:
|
||||
if type(authzr_challb.chall) is type(achall.challb.chall):
|
||||
if type(authzr_challb.chall) is type(achall.challb.chall): # noqa
|
||||
return authzr_challb
|
||||
raise errors.AuthorizationError(
|
||||
"Target challenge not found in authorization resource")
|
||||
@@ -512,7 +512,8 @@ _ERROR_HELP = {
|
||||
"to date TLS configuration that allows the server to communicate with "
|
||||
"the Let's Encrypt client.",
|
||||
"unauthorized": _ERROR_HELP_COMMON,
|
||||
"unknownHost": _ERROR_HELP_COMMON,}
|
||||
"unknownHost": _ERROR_HELP_COMMON,
|
||||
}
|
||||
|
||||
|
||||
def _report_failed_challs(failed_achalls):
|
||||
|
||||
+3
-1
@@ -334,6 +334,7 @@ class SilentParser(object): # pylint: disable=too-few-public-methods
|
||||
"""
|
||||
def __init__(self, parser):
|
||||
self.parser = parser
|
||||
|
||||
def add_argument(self, *args, **kwargs):
|
||||
"""Wrap, but silence help"""
|
||||
kwargs["help"] = argparse.SUPPRESS
|
||||
@@ -369,7 +370,7 @@ class HelpfulArgumentParser(object):
|
||||
help2 = self.prescan_for_flag("--help", self.help_topics)
|
||||
assert max(True, "a") == "a", "Gravity changed direction"
|
||||
help_arg = max(help1, help2)
|
||||
if help_arg == True:
|
||||
if help_arg:
|
||||
# just --help with no topic; avoid argparse altogether
|
||||
print USAGE
|
||||
sys.exit(0)
|
||||
@@ -546,6 +547,7 @@ def create_parser(plugins, args):
|
||||
|
||||
def _create_subparsers(helpful):
|
||||
subparsers = helpful.parser.add_subparsers(metavar="SUBCOMMAND")
|
||||
|
||||
def add_subparser(name, func): # pylint: disable=missing-docstring
|
||||
subparser = subparsers.add_parser(
|
||||
name, help=func.__doc__.splitlines()[0], description=func.__doc__)
|
||||
|
||||
@@ -279,8 +279,8 @@ class Client(object):
|
||||
:param .RenewableCert cert: Newly issued certificate
|
||||
|
||||
"""
|
||||
if ("autorenew" not in cert.configuration
|
||||
or cert.configuration.as_bool("autorenew")):
|
||||
if ("autorenew" not in cert.configuration or
|
||||
cert.configuration.as_bool("autorenew")):
|
||||
if ("autodeploy" not in cert.configuration or
|
||||
cert.configuration.as_bool("autodeploy")):
|
||||
msg = "Automatic renewal and deployment has "
|
||||
|
||||
@@ -205,6 +205,7 @@ def _pyopenssl_load(data, method, types=(
|
||||
raise errors.Error("Unable to load: {0}".format(",".join(
|
||||
str(error) for error in openssl_errors)))
|
||||
|
||||
|
||||
def pyopenssl_load_certificate(data):
|
||||
"""Load PEM/DER certificate.
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ def choose_plugin(prepared, question):
|
||||
:rtype: `~.PluginEntryPoint`
|
||||
|
||||
"""
|
||||
opts = [plugin_ep.description_with_name
|
||||
+ (" [Misconfigured]" if plugin_ep.misconfigured else "")
|
||||
opts = [plugin_ep.description_with_name +
|
||||
(" [Misconfigured]" if plugin_ep.misconfigured else "")
|
||||
for plugin_ep in prepared]
|
||||
|
||||
while True:
|
||||
|
||||
@@ -73,6 +73,7 @@ class NoInstallationError(PluginError):
|
||||
class MisconfigurationError(PluginError):
|
||||
"""Let's Encrypt Misconfiguration error."""
|
||||
|
||||
|
||||
class NotSupportedError(PluginError):
|
||||
"""Let's Encrypt Plugin function not supported error."""
|
||||
|
||||
|
||||
@@ -440,7 +440,6 @@ class IValidator(zope.interface.Interface):
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def hsts(name):
|
||||
"""Verify HSTS header is enabled
|
||||
|
||||
|
||||
@@ -196,6 +196,8 @@ def safely_remove(path):
|
||||
# start with a period or have two consecutive periods <- this needs to
|
||||
# be done in addition to the regex
|
||||
EMAIL_REGEX = re.compile("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+$")
|
||||
|
||||
|
||||
def safe_email(email):
|
||||
"""Scrub email address before using it."""
|
||||
if EMAIL_REGEX.match(email) is not None:
|
||||
|
||||
@@ -18,6 +18,7 @@ def option_namespace(name):
|
||||
"""ArgumentParser options namespace (prefix of all options)."""
|
||||
return name + "-"
|
||||
|
||||
|
||||
def dest_namespace(name):
|
||||
"""ArgumentParser dest namespace (prefix of all destinations)."""
|
||||
return name.replace("-", "_") + "_"
|
||||
@@ -86,6 +87,7 @@ class Plugin(object):
|
||||
|
||||
# other
|
||||
|
||||
|
||||
class Addr(object):
|
||||
r"""Represents an virtual host address.
|
||||
|
||||
|
||||
@@ -101,6 +101,7 @@ class PluginEntryPointTest(unittest.TestCase):
|
||||
with mock.patch("letsencrypt.plugins."
|
||||
"disco.zope.interface") as mock_zope:
|
||||
mock_zope.exceptions = exceptions
|
||||
|
||||
def verify_object(iface, obj): # pylint: disable=missing-docstring
|
||||
assert obj is plugin
|
||||
assert iface is iface1 or iface is iface2 or iface is iface3
|
||||
|
||||
@@ -321,10 +321,8 @@ class PerformTest(unittest.TestCase):
|
||||
self.authenticator.already_listening = mock.Mock(return_value=False)
|
||||
result = self.authenticator.perform(self.achalls)
|
||||
self.assertEqual(len(self.authenticator.tasks), 2)
|
||||
self.assertTrue(
|
||||
self.authenticator.tasks.has_key(self.achall1.token))
|
||||
self.assertTrue(
|
||||
self.authenticator.tasks.has_key(self.achall2.token))
|
||||
self.assertTrue(self.achall1.token in self.authenticator.tasks)
|
||||
self.assertTrue(self.achall2.token in self.authenticator.tasks)
|
||||
self.assertTrue(isinstance(result, list))
|
||||
self.assertEqual(len(result), 3)
|
||||
self.assertTrue(isinstance(result[0], challenges.ChallengeResponse))
|
||||
@@ -340,10 +338,8 @@ class PerformTest(unittest.TestCase):
|
||||
self.authenticator.already_listening = mock.Mock(return_value=False)
|
||||
result = self.authenticator.perform(self.achalls)
|
||||
self.assertEqual(len(self.authenticator.tasks), 2)
|
||||
self.assertTrue(
|
||||
self.authenticator.tasks.has_key(self.achall1.token))
|
||||
self.assertTrue(
|
||||
self.authenticator.tasks.has_key(self.achall2.token))
|
||||
self.assertTrue(self.achall1.token in self.authenticator.tasks)
|
||||
self.assertTrue(self.achall2.token in self.authenticator.tasks)
|
||||
self.assertTrue(isinstance(result, list))
|
||||
self.assertEqual(len(result), 3)
|
||||
self.assertEqual(result, [None, None, False])
|
||||
|
||||
@@ -486,8 +486,8 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes
|
||||
:rtype: bool
|
||||
|
||||
"""
|
||||
if ("autorenew" not in self.configuration
|
||||
or self.configuration.as_bool("autorenew")):
|
||||
if ("autorenew" not in self.configuration or
|
||||
self.configuration.as_bool("autorenew")):
|
||||
# Consider whether to attempt to autorenew this cert now
|
||||
|
||||
# Renewals on the basis of revocation
|
||||
@@ -603,7 +603,6 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes
|
||||
new_config.write()
|
||||
return cls(new_config, config, cli_config)
|
||||
|
||||
|
||||
def save_successor(self, prior_version, new_cert, new_privkey, new_chain):
|
||||
"""Save new cert and chain as a successor of a prior version.
|
||||
|
||||
|
||||
@@ -282,6 +282,7 @@ class PollChallengesTest(unittest.TestCase):
|
||||
)
|
||||
return (new_authzr, "response")
|
||||
|
||||
|
||||
class GenChallengePathTest(unittest.TestCase):
|
||||
"""Tests for letsencrypt.auth_handler.gen_challenge_path.
|
||||
|
||||
@@ -434,19 +435,22 @@ class ReportFailedChallsTest(unittest.TestCase):
|
||||
}
|
||||
|
||||
self.simple_http = achallenges.SimpleHTTP(
|
||||
challb=messages.ChallengeBody(**kwargs),# pylint: disable=star-args
|
||||
# pylint: disable=star-args
|
||||
challb=messages.ChallengeBody(**kwargs),
|
||||
domain="example.com",
|
||||
account_key="key")
|
||||
|
||||
kwargs["chall"] = acme_util.DVSNI
|
||||
self.dvsni_same = achallenges.DVSNI(
|
||||
challb=messages.ChallengeBody(**kwargs),# pylint: disable=star-args
|
||||
# pylint: disable=star-args
|
||||
challb=messages.ChallengeBody(**kwargs),
|
||||
domain="example.com",
|
||||
account_key="key")
|
||||
|
||||
kwargs["error"] = messages.Error(typ="dnssec", detail="detail")
|
||||
self.dvsni_diff = achallenges.DVSNI(
|
||||
challb=messages.ChallengeBody(**kwargs),# pylint: disable=star-args
|
||||
# pylint: disable=star-args
|
||||
challb=messages.ChallengeBody(**kwargs),
|
||||
domain="foo.bar",
|
||||
account_key="key")
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ class CLITest(unittest.TestCase):
|
||||
for args in itertools.chain(
|
||||
*(itertools.combinations(flags, r)
|
||||
for r in xrange(len(flags)))):
|
||||
self._call(['plugins',] + list(args))
|
||||
self._call(['plugins'] + list(args))
|
||||
|
||||
@mock.patch("letsencrypt.cli.sys")
|
||||
def test_handle_exception(self, mock_sys):
|
||||
|
||||
@@ -35,7 +35,7 @@ class PerformTest(unittest.TestCase):
|
||||
self.assertRaises(
|
||||
errors.ContAuthError, self.auth.perform, [
|
||||
achallenges.DVSNI(
|
||||
challb=None, domain="0", account_key="invalid_key"),])
|
||||
challb=None, domain="0", account_key="invalid_key")])
|
||||
|
||||
def test_chall_pref(self):
|
||||
self.assertEqual(
|
||||
|
||||
@@ -250,6 +250,7 @@ class GenSSLLabURLs(unittest.TestCase):
|
||||
self.assertTrue("eff.org" in urls[0])
|
||||
self.assertTrue("umich.edu" in urls[1])
|
||||
|
||||
|
||||
class GenHttpsNamesTest(unittest.TestCase):
|
||||
"""Test _gen_https_names."""
|
||||
def setUp(self):
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
"""Tests for letsencrypt.notify."""
|
||||
|
||||
import mock
|
||||
import socket
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
|
||||
class NotifyTests(unittest.TestCase):
|
||||
"""Tests for the notifier."""
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ def unlink_all(rc_object):
|
||||
for kind in ALL_FOUR:
|
||||
os.unlink(getattr(rc_object, kind))
|
||||
|
||||
|
||||
def fill_with_sample_data(rc_object):
|
||||
"""Put dummy data into all four files of this RenewableCert."""
|
||||
for kind in ALL_FOUR:
|
||||
@@ -608,7 +609,6 @@ class RenewableCertTests(unittest.TestCase):
|
||||
# This should fail because the renewal itself appears to fail
|
||||
self.assertFalse(renewer.renew(self.test_rc, 1))
|
||||
|
||||
|
||||
@mock.patch("letsencrypt.renewer.notify")
|
||||
@mock.patch("letsencrypt.storage.RenewableCert")
|
||||
@mock.patch("letsencrypt.renewer.renew")
|
||||
|
||||
@@ -106,6 +106,7 @@ class ValidatorTest(unittest.TestCase):
|
||||
self.assertRaises(
|
||||
NotImplementedError, self.validator.ocsp_stapling, "test.com")
|
||||
|
||||
|
||||
def create_response(status_code=200, headers=None):
|
||||
"""Creates a requests.Response object for testing"""
|
||||
response = requests.Response()
|
||||
|
||||
Reference in New Issue
Block a user