[ Avaa Bypassed ]




Upload:

Command:

www-data@3.139.85.192: ~ $
"""Tests for certbot.plugins.util."""
import unittest

import mock

from certbot.compat import os


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'])


class PathSurgeryTest(unittest.TestCase):
    """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
                self.assertEqual(path_surgery("eg"), True)
                self.assertEqual(mock_debug.call_count, 0)
                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.assertTrue("Failed to find" in mock_debug.call_args[0][0])
                self.assertTrue("/usr/local/bin" in os.environ["PATH"])
                self.assertTrue("/tmp" in os.environ["PATH"])


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

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
__init__.py File 30 B 0644
common.py File 18.68 KB 0644
common_test.py File 14.89 KB 0644
disco.py File 9.96 KB 0644
disco_test.py File 11.34 KB 0644
dns_common.py File 11.69 KB 0644
dns_common_lexicon.py File 5.41 KB 0644
dns_common_lexicon_test.py File 651 B 0644
dns_common_test.py File 8.18 KB 0644
dns_test_common.py File 1.65 KB 0644
dns_test_common_lexicon.py File 5.48 KB 0644
enhancements.py File 5.58 KB 0644
enhancements_test.py File 2.36 KB 0644
manual.py File 7.88 KB 0644
manual_test.py File 5.6 KB 0644
null.py File 1.27 KB 0644
null_test.py File 624 B 0644
selection.py File 13.55 KB 0644
selection_test.py File 7.78 KB 0644
standalone.py File 7.72 KB 0644
standalone_test.py File 6.64 KB 0644
storage.py File 4.14 KB 0644
storage_test.py File 5.47 KB 0644
util.py File 1.69 KB 0644
util_test.py File 1.81 KB 0644
webroot.py File 12.08 KB 0644
webroot_test.py File 13.11 KB 0644