[ Avaa Bypassed ]




Upload:

Command:

www-data@3.139.85.192: ~ $
"""Tests for new style enhancements"""
import unittest
import mock

from certbot.plugins import enhancements
from certbot.plugins import null

import certbot.tests.util as test_util


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

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


    @test_util.patch_get_utility()
    def test_enhancement_enabled_enhancements(self, _):
        FAKEINDEX = [
            {
                "name": "autohsts",
                "cli_dest": "auto_hsts",
            },
            {
                "name": "somethingelse",
                "cli_dest": "something",
            }
        ]
        with mock.patch("certbot.plugins.enhancements._INDEX", FAKEINDEX):
            self.config.auto_hsts = True
            self.config.something = True
            enabled = list(enhancements.enabled_enhancements(self.config))
        self.assertEqual(len(enabled), 2)
        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([i for i in enhancements.enabled_enhancements(self.config)]), 0)
        self.assertFalse(enhancements.are_requested(self.config))
        self.config.auto_hsts = True
        self.assertEqual(
            len([i for i in 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))

    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)
        self.assertEqual(self.mockinstaller.enable_autohsts.call_args[0],
                          (lineage, domains))


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