The following issues were found

acme/tests/errors_test.py
10 issues
Unable to import 'acme.errors'
Error

Line: 10 Column: 9

                  """Tests for acme.errors.BadNonce."""

    def setUp(self):
        from acme.errors import BadNonce
        self.error = BadNonce(nonce="xxx", error="error")

    def test_str(self):
        self.assertEqual("Invalid nonce ('xxx'): error", str(self.error))


            

Reported by Pylint.

Unable to import 'acme.errors'
Error

Line: 21 Column: 9

                  """Tests for acme.errors.MissingNonce."""

    def setUp(self):
        from acme.errors import MissingNonce
        self.response = mock.MagicMock(headers={})
        self.response.request.method = 'FOO'
        self.error = MissingNonce(self.response)

    def test_str(self):

            

Reported by Pylint.

Unable to import 'acme.errors'
Error

Line: 35 Column: 9

                  """Tests for acme.errors.PollError."""

    def setUp(self):
        from acme.errors import PollError
        self.timeout = PollError(
            exhausted={mock.sentinel.AR},
            updated={})
        self.invalid = PollError(exhausted=set(), updated={
            mock.sentinel.AR: mock.sentinel.AR2})

            

Reported by Pylint.

Import outside toplevel (acme.errors.BadNonce)
Error

Line: 10 Column: 9

                  """Tests for acme.errors.BadNonce."""

    def setUp(self):
        from acme.errors import BadNonce
        self.error = BadNonce(nonce="xxx", error="error")

    def test_str(self):
        self.assertEqual("Invalid nonce ('xxx'): error", str(self.error))


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 13 Column: 5

                      from acme.errors import BadNonce
        self.error = BadNonce(nonce="xxx", error="error")

    def test_str(self):
        self.assertEqual("Invalid nonce ('xxx'): error", str(self.error))


class MissingNonceTest(unittest.TestCase):
    """Tests for acme.errors.MissingNonce."""

            

Reported by Pylint.

Import outside toplevel (acme.errors.MissingNonce)
Error

Line: 21 Column: 9

                  """Tests for acme.errors.MissingNonce."""

    def setUp(self):
        from acme.errors import MissingNonce
        self.response = mock.MagicMock(headers={})
        self.response.request.method = 'FOO'
        self.error = MissingNonce(self.response)

    def test_str(self):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 26 Column: 5

                      self.response.request.method = 'FOO'
        self.error = MissingNonce(self.response)

    def test_str(self):
        self.assertIn("FOO", str(self.error))
        self.assertIn("{}", str(self.error))


class PollErrorTest(unittest.TestCase):

            

Reported by Pylint.

Import outside toplevel (acme.errors.PollError)
Error

Line: 35 Column: 9

                  """Tests for acme.errors.PollError."""

    def setUp(self):
        from acme.errors import PollError
        self.timeout = PollError(
            exhausted={mock.sentinel.AR},
            updated={})
        self.invalid = PollError(exhausted=set(), updated={
            mock.sentinel.AR: mock.sentinel.AR2})

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 42 Column: 5

                      self.invalid = PollError(exhausted=set(), updated={
            mock.sentinel.AR: mock.sentinel.AR2})

    def test_timeout(self):
        self.assertTrue(self.timeout.timeout)
        self.assertFalse(self.invalid.timeout)

    def test_repr(self):
        self.assertEqual('PollError(exhausted=%s, updated={sentinel.AR: '

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 46 Column: 5

                      self.assertTrue(self.timeout.timeout)
        self.assertFalse(self.invalid.timeout)

    def test_repr(self):
        self.assertEqual('PollError(exhausted=%s, updated={sentinel.AR: '
                         'sentinel.AR2})' % repr(set()), repr(self.invalid))


if __name__ == "__main__":

            

Reported by Pylint.

certbot/tests/plugins/enhancements_test.py
10 issues
Unable to import 'certbot._internal.plugins'
Error

Line: 9 Column: 1

              except ImportError: # pragma: no cover
    from unittest import mock

from certbot._internal.plugins import null
from certbot.plugins import enhancements
import certbot.tests.util as test_util


class EnhancementTest(test_util.ConfigTestCase):

            

Reported by Pylint.

Unable to import 'certbot.plugins'
Error

Line: 10 Column: 1

                  from unittest import mock

from certbot._internal.plugins import null
from certbot.plugins import enhancements
import certbot.tests.util as test_util


class EnhancementTest(test_util.ConfigTestCase):
    """Tests for new style enhancements in certbot.plugins.enhancements"""

            

Reported by Pylint.

Unable to import 'certbot.tests.util'
Error

Line: 11 Column: 1

              
from certbot._internal.plugins import null
from certbot.plugins import enhancements
import certbot.tests.util as test_util


class EnhancementTest(test_util.ConfigTestCase):
    """Tests for new style enhancements in certbot.plugins.enhancements"""


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 17 Column: 5

              class EnhancementTest(test_util.ConfigTestCase):
    """Tests for new style enhancements in certbot.plugins.enhancements"""

    def setUp(self):
        super().setUp()
        self.mockinstaller = mock.MagicMock(spec=enhancements.AutoHSTSEnhancement)


    @test_util.patch_display_util()

            

Reported by Pylint.

Method name "setUp" doesn't conform to snake_case naming style
Error

Line: 17 Column: 5

              class EnhancementTest(test_util.ConfigTestCase):
    """Tests for new style enhancements in certbot.plugins.enhancements"""

    def setUp(self):
        super().setUp()
        self.mockinstaller = mock.MagicMock(spec=enhancements.AutoHSTSEnhancement)


    @test_util.patch_display_util()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 23 Column: 5

              

    @test_util.patch_display_util()
    def test_enhancement_enabled_enhancements(self, _):
        FAKEINDEX = [
            {
                "name": "autohsts",
                "cli_dest": "auto_hsts",
            },

            

Reported by Pylint.

Variable name "FAKEINDEX" doesn't conform to snake_case naming style
Error

Line: 24 Column: 9

              
    @test_util.patch_display_util()
    def test_enhancement_enabled_enhancements(self, _):
        FAKEINDEX = [
            {
                "name": "autohsts",
                "cli_dest": "auto_hsts",
            },
            {

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 42 Column: 5

                      self.assertTrue([i for i in enabled if i["name"] == "autohsts"])
        self.assertTrue([i for i in enabled if i["name"] == "somethingelse"])

    def test_are_requested(self):
        self.assertEqual(len(list(enhancements.enabled_enhancements(self.config))), 0)
        self.assertFalse(enhancements.are_requested(self.config))
        self.config.auto_hsts = True
        self.assertEqual(len(list(enhancements.enabled_enhancements(self.config))), 1)
        self.assertTrue(enhancements.are_requested(self.config))

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 49 Column: 5

                      self.assertEqual(len(list(enhancements.enabled_enhancements(self.config))), 1)
        self.assertTrue(enhancements.are_requested(self.config))

    def test_are_supported(self):
        self.config.auto_hsts = True
        unsupported = null.Installer(self.config, "null")
        self.assertTrue(enhancements.are_supported(self.config, self.mockinstaller))
        self.assertFalse(enhancements.are_supported(self.config, unsupported))


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 55 Column: 5

                      self.assertTrue(enhancements.are_supported(self.config, self.mockinstaller))
        self.assertFalse(enhancements.are_supported(self.config, unsupported))

    def test_enable(self):
        self.config.auto_hsts = True
        domains = ["example.com", "www.example.com"]
        lineage = "lineage"
        enhancements.enable(lineage, domains, self.mockinstaller, self.config)
        self.assertTrue(self.mockinstaller.enable_autohsts.called)

            

Reported by Pylint.

certbot-compatibility-test/certbot_compatibility_test/test_driver.py
10 issues
Unable to import 'acme'
Error

Line: 17 Column: 1

              import OpenSSL
from urllib3.util import connection

from acme import challenges
from acme import crypto_util
from acme import messages
from certbot import achallenges
from certbot import errors as le_errors
from certbot.display import util as display_util

            

Reported by Pylint.

Unable to import 'acme'
Error

Line: 18 Column: 1

              from urllib3.util import connection

from acme import challenges
from acme import crypto_util
from acme import messages
from certbot import achallenges
from certbot import errors as le_errors
from certbot.display import util as display_util
from certbot._internal.display import obj as display_obj

            

Reported by Pylint.

Unable to import 'acme'
Error

Line: 19 Column: 1

              
from acme import challenges
from acme import crypto_util
from acme import messages
from certbot import achallenges
from certbot import errors as le_errors
from certbot.display import util as display_util
from certbot._internal.display import obj as display_obj
from certbot.tests import acme_util

            

Reported by Pylint.

Unable to import 'certbot'
Error

Line: 20 Column: 1

              from acme import challenges
from acme import crypto_util
from acme import messages
from certbot import achallenges
from certbot import errors as le_errors
from certbot.display import util as display_util
from certbot._internal.display import obj as display_obj
from certbot.tests import acme_util
from certbot_compatibility_test import errors

            

Reported by Pylint.

Unable to import 'certbot'
Error

Line: 21 Column: 1

              from acme import crypto_util
from acme import messages
from certbot import achallenges
from certbot import errors as le_errors
from certbot.display import util as display_util
from certbot._internal.display import obj as display_obj
from certbot.tests import acme_util
from certbot_compatibility_test import errors
from certbot_compatibility_test import util

            

Reported by Pylint.

Unable to import 'certbot.display'
Error

Line: 22 Column: 1

              from acme import messages
from certbot import achallenges
from certbot import errors as le_errors
from certbot.display import util as display_util
from certbot._internal.display import obj as display_obj
from certbot.tests import acme_util
from certbot_compatibility_test import errors
from certbot_compatibility_test import util
from certbot_compatibility_test import validator

            

Reported by Pylint.

Unable to import 'certbot._internal.display'
Error

Line: 23 Column: 1

              from certbot import achallenges
from certbot import errors as le_errors
from certbot.display import util as display_util
from certbot._internal.display import obj as display_obj
from certbot.tests import acme_util
from certbot_compatibility_test import errors
from certbot_compatibility_test import util
from certbot_compatibility_test import validator
from certbot_compatibility_test.configurators.apache import common as a_common

            

Reported by Pylint.

Unable to import 'certbot.tests'
Error

Line: 24 Column: 1

              from certbot import errors as le_errors
from certbot.display import util as display_util
from certbot._internal.display import obj as display_obj
from certbot.tests import acme_util
from certbot_compatibility_test import errors
from certbot_compatibility_test import util
from certbot_compatibility_test import validator
from certbot_compatibility_test.configurators.apache import common as a_common
from certbot_compatibility_test.configurators.nginx import common as n_common

            

Reported by Pylint.

Variable name "f" doesn't conform to snake_case naming style
Error

Line: 144 Column: 35

                  """Tests deploy_cert returning True if the tests are successful"""
    cert = crypto_util.gen_ss_cert(util.KEY, domains)
    cert_path = os.path.join(temp_dir, "cert.pem")
    with open(cert_path, "wb") as f:
        f.write(OpenSSL.crypto.dump_certificate(
            OpenSSL.crypto.FILETYPE_PEM, cert))

    for domain in domains:
        try:

            

Reported by Pylint.

Unnecessary "elif" after "return"
Error

Line: 259 Column: 9

                  dircmps = [filecmp.dircmp(dir1, dir2)]
    while dircmps:
        dircmp = dircmps.pop()
        if dircmp.left_only or dircmp.right_only:
            logger.error("The following files and directories are only "
                         "present in one directory")
            if dircmp.left_only:
                logger.error(str(dircmp.left_only))
            else:

            

Reported by Pylint.

certbot-dns-cloudxns/certbot_dns_cloudxns/_internal/dns_cloudxns.py
10 issues
Unable to import 'lexicon.providers'
Error

Line: 5 Column: 1

              import logging
from typing import Optional

from lexicon.providers import cloudxns

from certbot import errors
from certbot.plugins import dns_common
from certbot.plugins import dns_common_lexicon
from certbot.plugins.dns_common import CredentialsConfiguration

            

Reported by Pylint.

Unable to import 'certbot'
Error

Line: 7 Column: 1

              
from lexicon.providers import cloudxns

from certbot import errors
from certbot.plugins import dns_common
from certbot.plugins import dns_common_lexicon
from certbot.plugins.dns_common import CredentialsConfiguration

logger = logging.getLogger(__name__)

            

Reported by Pylint.

Unable to import 'certbot.plugins'
Error

Line: 8 Column: 1

              from lexicon.providers import cloudxns

from certbot import errors
from certbot.plugins import dns_common
from certbot.plugins import dns_common_lexicon
from certbot.plugins.dns_common import CredentialsConfiguration

logger = logging.getLogger(__name__)


            

Reported by Pylint.

Unable to import 'certbot.plugins'
Error

Line: 9 Column: 1

              
from certbot import errors
from certbot.plugins import dns_common
from certbot.plugins import dns_common_lexicon
from certbot.plugins.dns_common import CredentialsConfiguration

logger = logging.getLogger(__name__)

ACCOUNT_URL = 'https://www.cloudxns.net/en/AccountManage/apimanage.html'

            

Reported by Pylint.

Unable to import 'certbot.plugins.dns_common'
Error

Line: 10 Column: 1

              from certbot import errors
from certbot.plugins import dns_common
from certbot.plugins import dns_common_lexicon
from certbot.plugins.dns_common import CredentialsConfiguration

logger = logging.getLogger(__name__)

ACCOUNT_URL = 'https://www.cloudxns.net/en/AccountManage/apimanage.html'


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 31 Column: 5

                      self.credentials: Optional[CredentialsConfiguration] = None

    @classmethod
    def add_parser_arguments(cls, add):  # pylint: disable=arguments-differ
        super().add_parser_arguments(add, default_propagation_seconds=30)
        add('credentials', help='CloudXNS credentials INI file.')

    def more_info(self):  # pylint: disable=missing-function-docstring
        return 'This plugin configures a DNS TXT record to respond to a dns-01 challenge using ' + \

            

Reported by Pylint.

Method could be a function
Error

Line: 35 Column: 5

                      super().add_parser_arguments(add, default_propagation_seconds=30)
        add('credentials', help='CloudXNS credentials INI file.')

    def more_info(self):  # pylint: disable=missing-function-docstring
        return 'This plugin configures a DNS TXT record to respond to a dns-01 challenge using ' + \
               'the CloudXNS API.'

    def _setup_credentials(self):
        self.credentials = self._configure_credentials(

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 64 Column: 1

                                                    self.ttl)


class _CloudXNSLexiconClient(dns_common_lexicon.LexiconClient):
    """
    Encapsulates all communication with the CloudXNS via Lexicon.
    """

    def __init__(self, api_key, secret_key, ttl):

            

Reported by Pylint.

Argument name "e" doesn't conform to snake_case naming style
Error

Line: 81 Column: 5

              
        self.provider = cloudxns.Provider(config)

    def _handle_http_error(self, e, domain_name):
        hint = None
        if str(e).startswith('400 Client Error:'):
            hint = 'Are your API key and Secret key values correct?'

        return errors.PluginError('Error determining zone identifier for {0}: {1}.{2}'

            

Reported by Pylint.

Method could be a function
Error

Line: 81 Column: 5

              
        self.provider = cloudxns.Provider(config)

    def _handle_http_error(self, e, domain_name):
        hint = None
        if str(e).startswith('400 Client Error:'):
            hint = 'Are your API key and Secret key values correct?'

        return errors.PluginError('Error determining zone identifier for {0}: {1}.{2}'

            

Reported by Pylint.

certbot/tests/plugins/util_test.py
9 issues
Unable to import 'certbot.compat'
Error

Line: 9 Column: 1

              except ImportError: # pragma: no cover
    from unittest import mock

from certbot.compat import os


class GetPrefixTest(unittest.TestCase):
    """Tests for certbot.plugins.get_prefixes."""
    def test_get_prefix(self):

            

Reported by Pylint.

Unable to import 'certbot.plugins.util'
Error

Line: 15 Column: 9

              class GetPrefixTest(unittest.TestCase):
    """Tests for certbot.plugins.get_prefixes."""
    def test_get_prefix(self):
        from certbot.plugins.util import get_prefixes
        self.assertEqual(
            get_prefixes('/a/b/c'),
            [os.path.normpath(path) for path in ['/a/b/c', '/a/b', '/a', '/']])
        self.assertEqual(get_prefixes('/'), [os.path.normpath('/')])
        self.assertEqual(get_prefixes('a'), ['a'])

            

Reported by Pylint.

Unable to import 'certbot.plugins.util'
Error

Line: 28 Column: 9

              
    @mock.patch("certbot.plugins.util.logger.debug")
    def test_path_surgery(self, mock_debug):
        from certbot.plugins.util import path_surgery
        all_path = {"PATH": "/usr/local/bin:/bin/:/usr/sbin/:/usr/local/sbin/"}
        with mock.patch.dict('os.environ', all_path):
            with mock.patch('certbot.util.exe_exists') as mock_exists:
                mock_exists.return_value = True
                self.assertIs(path_surgery("eg"), True)

            

Reported by Pylint.

Probable insecure usage of temp file/directory.
Security

Line: 38
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b108_hardcoded_tmp_directory.html

                              self.assertEqual(os.environ["PATH"], all_path["PATH"])
        if os.name != 'nt':
            # This part is specific to Linux since on Windows no PATH surgery is ever done.
            no_path = {"PATH": "/tmp/"}
            with mock.patch.dict('os.environ', no_path):
                path_surgery("thingy")
                self.assertEqual(mock_debug.call_count, 2 if os.name != 'nt' else 1)
                self.assertIn("Failed to find", mock_debug.call_args[0][0])
                self.assertIn("/usr/local/bin", os.environ["PATH"])

            

Reported by Bandit.

Probable insecure usage of temp file/directory.
Security

Line: 44
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b108_hardcoded_tmp_directory.html

                              self.assertEqual(mock_debug.call_count, 2 if os.name != 'nt' else 1)
                self.assertIn("Failed to find", mock_debug.call_args[0][0])
                self.assertIn("/usr/local/bin", os.environ["PATH"])
                self.assertIn("/tmp", os.environ["PATH"])


if __name__ == "__main__":
    unittest.main()  # pragma: no cover

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 14 Column: 5

              
class GetPrefixTest(unittest.TestCase):
    """Tests for certbot.plugins.get_prefixes."""
    def test_get_prefix(self):
        from certbot.plugins.util import get_prefixes
        self.assertEqual(
            get_prefixes('/a/b/c'),
            [os.path.normpath(path) for path in ['/a/b/c', '/a/b', '/a', '/']])
        self.assertEqual(get_prefixes('/'), [os.path.normpath('/')])

            

Reported by Pylint.

Import outside toplevel (certbot.plugins.util.get_prefixes)
Error

Line: 15 Column: 9

              class GetPrefixTest(unittest.TestCase):
    """Tests for certbot.plugins.get_prefixes."""
    def test_get_prefix(self):
        from certbot.plugins.util import get_prefixes
        self.assertEqual(
            get_prefixes('/a/b/c'),
            [os.path.normpath(path) for path in ['/a/b/c', '/a/b', '/a', '/']])
        self.assertEqual(get_prefixes('/'), [os.path.normpath('/')])
        self.assertEqual(get_prefixes('a'), ['a'])

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 27 Column: 5

                  """Tests for certbot.plugins.path_surgery."""

    @mock.patch("certbot.plugins.util.logger.debug")
    def test_path_surgery(self, mock_debug):
        from certbot.plugins.util import path_surgery
        all_path = {"PATH": "/usr/local/bin:/bin/:/usr/sbin/:/usr/local/sbin/"}
        with mock.patch.dict('os.environ', all_path):
            with mock.patch('certbot.util.exe_exists') as mock_exists:
                mock_exists.return_value = True

            

Reported by Pylint.

Import outside toplevel (certbot.plugins.util.path_surgery)
Error

Line: 28 Column: 9

              
    @mock.patch("certbot.plugins.util.logger.debug")
    def test_path_surgery(self, mock_debug):
        from certbot.plugins.util import path_surgery
        all_path = {"PATH": "/usr/local/bin:/bin/:/usr/sbin/:/usr/local/sbin/"}
        with mock.patch.dict('os.environ', all_path):
            with mock.patch('certbot.util.exe_exists') as mock_exists:
                mock_exists.return_value = True
                self.assertIs(path_surgery("eg"), True)

            

Reported by Pylint.

certbot-apache/tests/configurator_reverter_test.py
9 issues
Unable to import 'certbot'
Error

Line: 10 Column: 1

              except ImportError: # pragma: no cover
    from unittest import mock # type: ignore

from certbot import errors
import util


class ConfiguratorReverterTest(util.ApacheTest):
    """Test for ApacheConfigurator reverter methods"""

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 32 Column: 5

                      shutil.rmtree(self.work_dir)
        shutil.rmtree(self.temp_dir)

    def test_bad_save_checkpoint(self):
        self.config.reverter.add_to_checkpoint = mock.Mock(
            side_effect=errors.ReverterError)
        self.config.parser.add_dir(
            self.vh_truth[0].path, "Test", "bad_save_ckpt")
        self.assertRaises(errors.PluginError, self.config.save)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 39 Column: 5

                          self.vh_truth[0].path, "Test", "bad_save_ckpt")
        self.assertRaises(errors.PluginError, self.config.save)

    def test_bad_save_finalize_checkpoint(self):
        self.config.reverter.finalize_checkpoint = mock.Mock(
            side_effect=errors.ReverterError)
        self.config.parser.add_dir(
            self.vh_truth[0].path, "Test", "bad_save_ckpt")
        self.assertRaises(errors.PluginError, self.config.save, "Title")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 46 Column: 5

                          self.vh_truth[0].path, "Test", "bad_save_ckpt")
        self.assertRaises(errors.PluginError, self.config.save, "Title")

    def test_finalize_save(self):
        mock_finalize = mock.Mock()
        self.config.reverter = mock_finalize
        self.config.save("Example Title")

        self.assertTrue(mock_finalize.is_called)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 53 Column: 5

              
        self.assertTrue(mock_finalize.is_called)

    def test_revert_challenge_config(self):
        mock_load = mock.Mock()
        self.config.parser.aug.load = mock_load

        self.config.revert_challenge_config()
        self.assertEqual(mock_load.call_count, 1)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 60 Column: 5

                      self.config.revert_challenge_config()
        self.assertEqual(mock_load.call_count, 1)

    def test_revert_challenge_config_error(self):
        self.config.reverter.revert_temporary_config = mock.Mock(
            side_effect=errors.ReverterError)

        self.assertRaises(
            errors.PluginError, self.config.revert_challenge_config)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 67 Column: 5

                      self.assertRaises(
            errors.PluginError, self.config.revert_challenge_config)

    def test_rollback_checkpoints(self):
        mock_load = mock.Mock()
        self.config.parser.aug.load = mock_load

        self.config.rollback_checkpoints()
        self.assertEqual(mock_load.call_count, 1)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 74 Column: 5

                      self.config.rollback_checkpoints()
        self.assertEqual(mock_load.call_count, 1)

    def test_rollback_error(self):
        self.config.reverter.rollback_checkpoints = mock.Mock(
            side_effect=errors.ReverterError)
        self.assertRaises(errors.PluginError, self.config.rollback_checkpoints)

    def test_recovery_routine_reload(self):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 79 Column: 5

                          side_effect=errors.ReverterError)
        self.assertRaises(errors.PluginError, self.config.rollback_checkpoints)

    def test_recovery_routine_reload(self):
        mock_load = mock.Mock()
        self.config.parser.aug.load = mock_load
        self.config.recovery_routine()
        self.assertEqual(mock_load.call_count, 1)


            

Reported by Pylint.

certbot-compatibility-test/nginx/roundtrip.py
9 issues
Unable to import 'certbot_nginx._internal'
Error

Line: 6 Column: 1

              import os
import sys

from certbot_nginx._internal import nginxparser


def roundtrip(stuff):
    success = True
    for t in stuff:

            

Reported by Pylint.

Redefining name 'success' from outer scope (line 30)
Error

Line: 10 Column: 5

              

def roundtrip(stuff):
    success = True
    for t in stuff:
        print(t)
        if not os.path.isfile(t):
            continue
        with open(t, "r") as f:

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 21 Column: 20

                              if nginxparser.dumps(nginxparser.loads(config)) != config:
                    print("Failed parsing round-trip for {0}".format(t))
                    success = False
            except Exception as e:
                print("Failed parsing {0} ({1})".format(t, e))
                success = False
    return success

if __name__ == "__main__":

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python

import os
import sys

from certbot_nginx._internal import nginxparser


def roundtrip(stuff):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 1

              from certbot_nginx._internal import nginxparser


def roundtrip(stuff):
    success = True
    for t in stuff:
        print(t)
        if not os.path.isfile(t):
            continue

            

Reported by Pylint.

Variable name "t" doesn't conform to snake_case naming style
Error

Line: 11 Column: 9

              
def roundtrip(stuff):
    success = True
    for t in stuff:
        print(t)
        if not os.path.isfile(t):
            continue
        with open(t, "r") as f:
            config = f.read()

            

Reported by Pylint.

Variable name "f" doesn't conform to snake_case naming style
Error

Line: 15 Column: 30

                      print(t)
        if not os.path.isfile(t):
            continue
        with open(t, "r") as f:
            config = f.read()
            try:
                if nginxparser.dumps(nginxparser.loads(config)) != config:
                    print("Failed parsing round-trip for {0}".format(t))
                    success = False

            

Reported by Pylint.

Variable name "e" doesn't conform to snake_case naming style
Error

Line: 21 Column: 13

                              if nginxparser.dumps(nginxparser.loads(config)) != config:
                    print("Failed parsing round-trip for {0}".format(t))
                    success = False
            except Exception as e:
                print("Failed parsing {0} ({1})".format(t, e))
                success = False
    return success

if __name__ == "__main__":

            

Reported by Pylint.

Constant name "success" doesn't conform to UPPER_CASE naming style
Error

Line: 30 Column: 5

                  if len(sys.argv) != 2:
        print("usage: %s directory" % sys.argv[0])
        sys.exit(1)
    success = True
    for where, _, files in os.walk(sys.argv[1]):
        if files:
            success &= roundtrip(os.path.join(where, f) for f in files)

    sys.exit(0 if success else 1)

            

Reported by Pylint.

certbot/tests/reporter_test.py
9 issues
Unable to import 'certbot._internal'
Error

Line: 16 Column: 9

              class ReporterTest(unittest.TestCase):
    """Tests for certbot._internal.reporter.Reporter."""
    def setUp(self):
        from certbot._internal import reporter
        self.reporter = reporter.Reporter(mock.MagicMock(quiet=False))

        self.old_stdout = sys.stdout
        sys.stdout = io.StringIO()


            

Reported by Pylint.

Import outside toplevel (certbot._internal.reporter)
Error

Line: 16 Column: 9

              class ReporterTest(unittest.TestCase):
    """Tests for certbot._internal.reporter.Reporter."""
    def setUp(self):
        from certbot._internal import reporter
        self.reporter = reporter.Reporter(mock.MagicMock(quiet=False))

        self.old_stdout = sys.stdout
        sys.stdout = io.StringIO()


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 25 Column: 5

                  def tearDown(self):
        sys.stdout = self.old_stdout

    def test_multiline_message(self):
        self.reporter.add_message("Line 1\nLine 2", self.reporter.LOW_PRIORITY)
        self.reporter.print_messages()
        output = sys.stdout.getvalue()
        self.assertIn("Line 1\n", output)
        self.assertIn("Line 2", output)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 32 Column: 5

                      self.assertIn("Line 1\n", output)
        self.assertIn("Line 2", output)

    def test_tty_print_empty(self):
        sys.stdout.isatty = lambda: True
        self.test_no_tty_print_empty()

    def test_no_tty_print_empty(self):
        self.reporter.print_messages()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 36 Column: 5

                      sys.stdout.isatty = lambda: True
        self.test_no_tty_print_empty()

    def test_no_tty_print_empty(self):
        self.reporter.print_messages()
        self.assertEqual(sys.stdout.getvalue(), "")
        try:
            raise ValueError
        except ValueError:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 45 Column: 5

                          self.reporter.print_messages()
        self.assertEqual(sys.stdout.getvalue(), "")

    def test_tty_successful_exit(self):
        sys.stdout.isatty = lambda: True
        self._successful_exit_common()

    def test_no_tty_successful_exit(self):
        self._successful_exit_common()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 49 Column: 5

                      sys.stdout.isatty = lambda: True
        self._successful_exit_common()

    def test_no_tty_successful_exit(self):
        self._successful_exit_common()

    def test_tty_unsuccessful_exit(self):
        sys.stdout.isatty = lambda: True
        self._unsuccessful_exit_common()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 52 Column: 5

                  def test_no_tty_successful_exit(self):
        self._successful_exit_common()

    def test_tty_unsuccessful_exit(self):
        sys.stdout.isatty = lambda: True
        self._unsuccessful_exit_common()

    def test_no_tty_unsuccessful_exit(self):
        self._unsuccessful_exit_common()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 56 Column: 5

                      sys.stdout.isatty = lambda: True
        self._unsuccessful_exit_common()

    def test_no_tty_unsuccessful_exit(self):
        self._unsuccessful_exit_common()

    def _successful_exit_common(self):
        self._add_messages()
        self.reporter.print_messages()

            

Reported by Pylint.

certbot-compatibility-test/certbot_compatibility_test/configurators/nginx/common.py
9 issues
Unable to import 'certbot'
Error

Line: 8 Column: 1

              from typing import cast
from typing import Set

from certbot import configuration
from certbot_compatibility_test import errors
from certbot_compatibility_test import interfaces
from certbot_compatibility_test import util
from certbot_compatibility_test.configurators import common as configurators_common
from certbot_nginx._internal import configurator

            

Reported by Pylint.

Unable to import 'certbot_nginx._internal'
Error

Line: 13 Column: 1

              from certbot_compatibility_test import interfaces
from certbot_compatibility_test import util
from certbot_compatibility_test.configurators import common as configurators_common
from certbot_nginx._internal import configurator
from certbot_nginx._internal import constants


class Proxy(configurators_common.Proxy):
    """A common base for Nginx test configurators"""

            

Reported by Pylint.

Unable to import 'certbot_nginx._internal'
Error

Line: 14 Column: 1

              from certbot_compatibility_test import util
from certbot_compatibility_test.configurators import common as configurators_common
from certbot_nginx._internal import configurator
from certbot_nginx._internal import constants


class Proxy(configurators_common.Proxy):
    """A common base for Nginx test configurators"""


            

Reported by Pylint.

XXX: Deleting all of this is kind of scary unless the test
Error

Line: 27 Column: 3

              
        server_root = _get_server_root(config)

        # XXX: Deleting all of this is kind of scary unless the test
        #      instances really each have a complete configuration!
        shutil.rmtree("/etc/nginx")
        shutil.copytree(server_root, "/etc/nginx", symlinks=True)

        self._prepare_configurator()

            

Reported by Pylint.

Consider explicitly re-raising using the 'from' keyword
Error

Line: 37 Column: 13

                      try:
            subprocess.check_call("service nginx reload".split())
        except errors.Error:
            raise errors.Error(
                "Nginx failed to load {0} before tests started".format(
                    config))

        return config


            

Reported by Pylint.

Consider possible security implications associated with subprocess module.
Security blacklist

Line: 4
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess

              """Provides a common base for Nginx proxies"""
import os
import shutil
import subprocess
from typing import cast
from typing import Set

from certbot import configuration
from certbot_compatibility_test import errors

            

Reported by Bandit.

subprocess call - check for execution of untrusted input.
Security injection

Line: 35
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b603_subprocess_without_shell_equals_true.html

                      self._prepare_configurator()

        try:
            subprocess.check_call("service nginx reload".split())
        except errors.Error:
            raise errors.Error(
                "Nginx failed to load {0} before tests started".format(
                    config))


            

Reported by Bandit.

Variable name "f" doesn't conform to snake_case naming style
Error

Line: 83 Column: 48

              def _get_server_names(root, filename):
    """Returns all names in a config file path"""
    all_names = set()
    with open(os.path.join(root, filename)) as f:
        for line in f:
            if line.strip().startswith("server_name"):
                names = line.partition("server_name")[2].rpartition(";")[0]
                for n in names.split():
                    # Filter out wildcards in both all_names and test_names

            

Reported by Pylint.

Variable name "n" doesn't conform to snake_case naming style
Error

Line: 87 Column: 21

                      for line in f:
            if line.strip().startswith("server_name"):
                names = line.partition("server_name")[2].rpartition(";")[0]
                for n in names.split():
                    # Filter out wildcards in both all_names and test_names
                    if not n.startswith("*."):
                        all_names.add(n)
    return all_names

            

Reported by Pylint.

acme/acme/jws.py
9 issues
Unable to import 'josepy'
Error

Line: 7 Column: 1

              order to support the new header fields defined in ACME, this module defines some
ACME-specific classes that layer on top of josepy.
"""
import josepy as jose


class Header(jose.Header):
    """ACME-specific JOSE Header. Implements nonce, kid, and url.
    """

            

Reported by Pylint.

TODO: custom error
Error

Line: 24 Column: 3

                      try:
            return jose.decode_b64jose(value)
        except jose.DeserializationError as error:
            # TODO: custom error
            raise jose.DeserializationError("Invalid nonce: {0}".format(error))


class Signature(jose.Signature):
    """ACME-specific Signature. Uses ACME-specific Header for customer fields."""

            

Reported by Pylint.

TODO: decoder/encoder should accept cls? Otherwise, subclassing
Error

Line: 32 Column: 3

                  """ACME-specific Signature. Uses ACME-specific Header for customer fields."""
    __slots__ = jose.Signature._orig_slots  # pylint: disable=no-member

    # TODO: decoder/encoder should accept cls? Otherwise, subclassing
    # JSONObjectWithFields is tricky...
    header_cls = Header
    header = jose.Field(
        'header', omitempty=True, default=header_cls(),
        decoder=header_cls.from_json)

            

Reported by Pylint.

TODO: decoder should check that nonce is in the protected header
Error

Line: 39 Column: 3

                      'header', omitempty=True, default=header_cls(),
        decoder=header_cls.from_json)

    # TODO: decoder should check that nonce is in the protected header


class JWS(jose.JWS):
    """ACME-specific JWS. Includes none, url, and kid in protected header."""
    signature_cls = Signature

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 10 Column: 1

              import josepy as jose


class Header(jose.Header):
    """ACME-specific JOSE Header. Implements nonce, kid, and url.
    """
    nonce = jose.Field('nonce', omitempty=True, encoder=jose.encode_b64jose)
    kid = jose.Field('kid', omitempty=True)
    url = jose.Field('url', omitempty=True)

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 28 Column: 1

                          raise jose.DeserializationError("Invalid nonce: {0}".format(error))


class Signature(jose.Signature):
    """ACME-specific Signature. Uses ACME-specific Header for customer fields."""
    __slots__ = jose.Signature._orig_slots  # pylint: disable=no-member

    # TODO: decoder/encoder should accept cls? Otherwise, subclassing
    # JSONObjectWithFields is tricky...

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 42 Column: 1

                  # TODO: decoder should check that nonce is in the protected header


class JWS(jose.JWS):
    """ACME-specific JWS. Includes none, url, and kid in protected header."""
    signature_cls = Signature
    __slots__ = jose.JWS._orig_slots

    @classmethod

            

Reported by Pylint.

Too many arguments (7/5)
Error

Line: 48 Column: 5

                  __slots__ = jose.JWS._orig_slots

    @classmethod
    # pylint: disable=arguments-differ
    def sign(cls, payload, key, alg, nonce, url=None, kid=None):
        # Per ACME spec, jwk and kid are mutually exclusive, so only include a
        # jwk field if kid is not provided.
        include_jwk = kid is None
        return super().sign(payload, key=key, alg=alg,

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 48 Column: 5

                  __slots__ = jose.JWS._orig_slots

    @classmethod
    # pylint: disable=arguments-differ
    def sign(cls, payload, key, alg, nonce, url=None, kid=None):
        # Per ACME spec, jwk and kid are mutually exclusive, so only include a
        # jwk field if kid is not provided.
        include_jwk = kid is None
        return super().sign(payload, key=key, alg=alg,

            

Reported by Pylint.