mirror of
https://github.com/certbot/certbot.git
synced 2026-05-28 04:34:11 -04:00
This changes the apache plugin behaviour to only parse enabled configuration files and respecting the --apache-vhost-root CLI parameter for new SSL vhost creation. If --apache-vhost-root isn't defined, or doesn't exist, the SSL vhost will be created to originating non-SSL vhost directory. This PR also implements actual check for vhost enabled state, and makes sure parser.parse_file() does not discard changes in Augeas DOM, by doing an autosave. Also handles enabling the new SSL vhost, if it's on a path that's not parsed by Apache. Fixes: #1328 Fixes: #3545 Fixes: #3791 Fixes: #4523 Fixes: #4837 Fixes: #4905 * First changes * Handle rest of the errors * Test fixes * Final fixes * Make parse_files accessible and fix linter problems * Activate vhost at later time * Cleanup * Add a new test case, and fix old * Enable site later in deploy_cert * Make apache-conf-test default dummy configuration enabled * Remove is_sites_available as obsolete * Cleanup * Brought back conditional vhost_path parsing * Parenthesis * Fix merge leftovers * Fix to work with the recent changes to new file creation * Added fix and tests for non-symlink vhost in sites-enabled * Made vhostroot parameter for ApacheParser optional, and removed extra_path * Respect vhost-root, and add Include statements to root configuration if needed * Fixed site enabling order to prevent apache restart error while enabling mod_ssl * Don't exclude Ubuntu / Debian vhost-root cli argument * Changed the SSL vhost directory selection priority * Requested fixes for paths and vhost discovery * Make sure the Augeas DOM is written to disk before loading new files * Actual checking for if the file is parsed within existing Apache configuration * Fix the order of dummy SSL directives addition and enabling modules * Restructured site_enabled checks * Enabling vhost correctly for non-debian systems
117 lines
3.8 KiB
Python
117 lines
3.8 KiB
Python
"""Test for certbot_apache.augeas_configurator."""
|
|
import os
|
|
import shutil
|
|
import unittest
|
|
|
|
import mock
|
|
|
|
from certbot import errors
|
|
|
|
from certbot_apache.tests import util
|
|
|
|
|
|
class AugeasConfiguratorTest(util.ApacheTest):
|
|
"""Test for Augeas Configurator base class."""
|
|
|
|
_multiprocess_can_split_ = True
|
|
|
|
def setUp(self): # pylint: disable=arguments-differ
|
|
super(AugeasConfiguratorTest, self).setUp()
|
|
|
|
self.config = util.get_apache_configurator(
|
|
self.config_path, self.vhost_path, self.config_dir, self.work_dir)
|
|
|
|
self.vh_truth = util.get_vh_truth(
|
|
self.temp_dir, "debian_apache_2_4/multiple_vhosts")
|
|
|
|
def tearDown(self):
|
|
shutil.rmtree(self.config_dir)
|
|
shutil.rmtree(self.work_dir)
|
|
shutil.rmtree(self.temp_dir)
|
|
|
|
def test_bad_parse(self):
|
|
# pylint: disable=protected-access
|
|
self.config.parser.parse_file(os.path.join(
|
|
self.config.parser.root, "conf-available", "bad_conf_file.conf"))
|
|
self.assertRaises(
|
|
errors.PluginError, self.config.check_parsing_errors, "httpd.aug")
|
|
|
|
def test_bad_save(self):
|
|
mock_save = mock.Mock()
|
|
mock_save.side_effect = IOError
|
|
self.config.aug.save = mock_save
|
|
|
|
self.assertRaises(errors.PluginError, self.config.save)
|
|
|
|
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)
|
|
|
|
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")
|
|
|
|
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)
|
|
|
|
def test_recovery_routine(self):
|
|
mock_load = mock.Mock()
|
|
self.config.aug.load = mock_load
|
|
|
|
self.config.recovery_routine()
|
|
self.assertEqual(mock_load.call_count, 1)
|
|
|
|
def test_recovery_routine_error(self):
|
|
self.config.reverter.recovery_routine = mock.Mock(
|
|
side_effect=errors.ReverterError)
|
|
|
|
self.assertRaises(
|
|
errors.PluginError, self.config.recovery_routine)
|
|
|
|
def test_revert_challenge_config(self):
|
|
mock_load = mock.Mock()
|
|
self.config.aug.load = mock_load
|
|
|
|
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)
|
|
|
|
def test_rollback_checkpoints(self):
|
|
mock_load = mock.Mock()
|
|
self.config.aug.load = mock_load
|
|
|
|
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_view_config_changes(self):
|
|
self.config.view_config_changes()
|
|
|
|
def test_view_config_changes_error(self):
|
|
self.config.reverter.view_config_changes = mock.Mock(
|
|
side_effect=errors.ReverterError)
|
|
self.assertRaises(errors.PluginError, self.config.view_config_changes)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main() # pragma: no cover
|