OXIESEC PANEL
- Current Dir:
/
/
usr
/
lib
/
python3
/
dist-packages
/
certbot
/
plugins
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
05/25/2021 01:14:26 PM
rwxr-xr-x
📄
__init__.py
30 bytes
02/07/2019 09:20:29 PM
rw-r--r--
📁
__pycache__
-
05/25/2021 01:14:27 PM
rwxr-xr-x
📄
common.py
16.9 KB
02/07/2019 09:20:29 PM
rw-r--r--
📄
common_test.py
16.53 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
disco.py
9.92 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
disco_test.py
11.34 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
dns_common.py
11.7 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
dns_common_lexicon.py
5.39 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
dns_common_lexicon_test.py
651 bytes
02/07/2019 09:20:30 PM
rw-r--r--
📄
dns_common_test.py
8.25 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
dns_test_common.py
1.61 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
dns_test_common_lexicon.py
5.48 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
enhancements.py
5.58 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
enhancements_test.py
2.36 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
manual.py
10.6 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
manual_test.py
7.37 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
null.py
1.34 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
null_test.py
624 bytes
02/07/2019 09:20:30 PM
rw-r--r--
📄
selection.py
13.55 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
selection_test.py
7.76 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
standalone.py
11.36 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
standalone_test.py
9.26 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
storage.py
4.08 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
storage_test.py
5.37 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
util.py
1.7 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
util_test.py
1.61 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
webroot.py
11.9 KB
02/07/2019 09:20:30 PM
rw-r--r--
📄
webroot_test.py
11.95 KB
02/07/2019 09:20:30 PM
rw-r--r--
Editing: storage_test.py
Close
"""Tests for certbot.plugins.storage.PluginStorage""" import json import mock import os import unittest from certbot import errors from certbot.plugins import common from certbot.tests import util as test_util class PluginStorageTest(test_util.ConfigTestCase): """Test for certbot.plugins.storage.PluginStorage""" def setUp(self): super(PluginStorageTest, self).setUp() self.plugin_cls = common.Installer os.mkdir(self.config.config_dir) with mock.patch("certbot.reverter.util"): self.plugin = self.plugin_cls(config=self.config, name="mockplugin") def test_load_errors_cant_read(self): with open(os.path.join(self.config.config_dir, ".pluginstorage.json"), "w") as fh: fh.write("dummy") # When unable to read file that exists mock_open = mock.mock_open() mock_open.side_effect = IOError self.plugin.storage.storagepath = os.path.join(self.config.config_dir, ".pluginstorage.json") with mock.patch("six.moves.builtins.open", mock_open): with mock.patch('os.path.isfile', return_value=True): with mock.patch("certbot.reverter.util"): self.assertRaises(errors.PluginStorageError, self.plugin.storage._load) # pylint: disable=protected-access def test_load_errors_empty(self): with open(os.path.join(self.config.config_dir, ".pluginstorage.json"), "w") as fh: fh.write('') with mock.patch("certbot.plugins.storage.logger.debug") as mock_log: # Should not error out but write a debug log line instead with mock.patch("certbot.reverter.util"): nocontent = self.plugin_cls(self.config, "mockplugin") self.assertRaises(KeyError, nocontent.storage.fetch, "value") self.assertTrue(mock_log.called) self.assertTrue("no values loaded" in mock_log.call_args[0][0]) def test_load_errors_corrupted(self): with open(os.path.join(self.config.config_dir, ".pluginstorage.json"), "w") as fh: fh.write('invalid json') with mock.patch("certbot.plugins.storage.logger.error") as mock_log: with mock.patch("certbot.reverter.util"): corrupted = self.plugin_cls(self.config, "mockplugin") self.assertRaises(errors.PluginError, corrupted.storage.fetch, "value") self.assertTrue("is corrupted" in mock_log.call_args[0][0]) def test_save_errors_cant_serialize(self): with mock.patch("certbot.plugins.storage.logger.error") as mock_log: # Set data as something that can't be serialized self.plugin.storage._initialized = True # pylint: disable=protected-access self.plugin.storage.storagepath = "/tmp/whatever" self.plugin.storage._data = self.plugin_cls # pylint: disable=protected-access self.assertRaises(errors.PluginStorageError, self.plugin.storage.save) self.assertTrue("Could not serialize" in mock_log.call_args[0][0]) def test_save_errors_unable_to_write_file(self): mock_open = mock.mock_open() mock_open.side_effect = IOError with mock.patch("os.open", mock_open): with mock.patch("certbot.plugins.storage.logger.error") as mock_log: self.plugin.storage._data = {"valid": "data"} # pylint: disable=protected-access self.plugin.storage._initialized = True # pylint: disable=protected-access self.assertRaises(errors.PluginStorageError, self.plugin.storage.save) self.assertTrue("Could not write" in mock_log.call_args[0][0]) def test_save_uninitialized(self): with mock.patch("certbot.reverter.util"): self.assertRaises(errors.PluginStorageError, self.plugin_cls(self.config, "x").storage.save) def test_namespace_isolation(self): with mock.patch("certbot.reverter.util"): plugin1 = self.plugin_cls(self.config, "first") plugin2 = self.plugin_cls(self.config, "second") plugin1.storage.put("first_key", "first_value") self.assertRaises(KeyError, plugin2.storage.fetch, "first_key") self.assertRaises(KeyError, plugin2.storage.fetch, "first") self.assertEqual(plugin1.storage.fetch("first_key"), "first_value") def test_saved_state(self): self.plugin.storage.put("testkey", "testvalue") # Write to disk self.plugin.storage.save() with mock.patch("certbot.reverter.util"): another = self.plugin_cls(self.config, "mockplugin") self.assertEqual(another.storage.fetch("testkey"), "testvalue") with open(os.path.join(self.config.config_dir, ".pluginstorage.json"), 'r') as fh: psdata = fh.read() psjson = json.loads(psdata) self.assertTrue("mockplugin" in psjson.keys()) self.assertEqual(len(psjson), 1) self.assertEqual(psjson["mockplugin"]["testkey"], "testvalue") if __name__ == "__main__": unittest.main() # pragma: no cover