mirror of
https://github.com/certbot/certbot.git
synced 2026-06-04 14:26:10 -04:00
test(postfix): coverage to 100
This commit is contained in:
parent
64feda281a
commit
591125dcb5
5 changed files with 27 additions and 14 deletions
|
|
@ -48,7 +48,8 @@ class Installer(plugins_common.Installer):
|
|||
help="Only set params to enable opportunistic TLS and install certificates.")
|
||||
add("server-only", action="store_true", default=constants.CLI_DEFAULTS["server_only"],
|
||||
help="Only set server params (prefixed with smtpd*)")
|
||||
add("ignore-master-overrides", action="store_true", default=constants.CLI_DEFAULTS["ignore_master_overrides"],
|
||||
add("ignore-master-overrides", action="store_true",
|
||||
default=constants.CLI_DEFAULTS["ignore_master_overrides"],
|
||||
help="Ignore errors reporting overridden TLS parameters in master.cf.")
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ class ConfigMain(util.PostfixUtilBase):
|
|||
super(ConfigMain, self).__init__(executable, config_dir)
|
||||
# Whether to ignore overrides from master.
|
||||
self._ignore_master_overrides = ignore_master_overrides
|
||||
print(self._ignore_master_overrides)
|
||||
# List of all current Postfix parameters, from `postconf` command.
|
||||
self._db = {}
|
||||
# List of current master.cf overrides from Postfix config. Dictionary
|
||||
|
|
|
|||
|
|
@ -22,7 +22,15 @@ class PostConfTest(unittest.TestCase):
|
|||
'service/type/overridden_by_master = master_value\n'
|
||||
'service2/type/overridden_by_master = master_value2\n'
|
||||
)
|
||||
self.config = ConfigMain('postconf', lambda x, y, z: None)
|
||||
self.config = ConfigMain('postconf', False)
|
||||
|
||||
@mock.patch('certbot_postfix.util.PostfixUtilBase._get_output')
|
||||
@mock.patch('certbot_postfix.postconf.util.verify_exe_exists')
|
||||
def test_get_output_master(self, mock_verify_exe, mock_get_output):
|
||||
from certbot_postfix.postconf import ConfigMain
|
||||
mock_verify_exe.return_value = True
|
||||
ConfigMain('postconf', lambda x, y, z: None)
|
||||
mock_get_output.assert_called_with('-P')
|
||||
|
||||
@mock.patch('certbot_postfix.util.PostfixUtilBase._get_output')
|
||||
def test_read_default(self, mock_get_output):
|
||||
|
|
@ -59,17 +67,18 @@ class PostConfTest(unittest.TestCase):
|
|||
('service2/type', 'master_value2')])
|
||||
|
||||
def test_set_check_override(self):
|
||||
expected_overrides = [
|
||||
('service/type', 'master_value'),
|
||||
('service2/type', 'master_value2')]
|
||||
def _check_overrides(name, overrides, acceptable_overrides):
|
||||
# pylint: disable=unused-argument
|
||||
self.assertEqual('overridden_by_master', name)
|
||||
self.assertEqual(expected_overrides, overrides)
|
||||
self.assertRaises(errors.PluginError, self.config.set,
|
||||
'overridden_by_master', 'new_value')
|
||||
|
||||
def test_ignore_check_override(self):
|
||||
# pylint: disable=protected-access
|
||||
self.config._handle_overrides = _check_overrides
|
||||
self.config._ignore_master_overrides = True
|
||||
self.config.set('overridden_by_master', 'new_value')
|
||||
|
||||
def test_check_acceptable_overrides(self):
|
||||
self.config.set('overridden_by_master', 'new_value',
|
||||
('master_value', 'master_value2'))
|
||||
|
||||
@mock.patch('certbot_postfix.util.PostfixUtilBase._get_output')
|
||||
def test_flush(self, mock_out):
|
||||
self.config.set('default_parameter', 'new_value')
|
||||
|
|
|
|||
|
|
@ -229,6 +229,10 @@ def report_master_overrides(name, overrides, acceptable_overrides=None):
|
|||
def is_acceptable_value(parameter, value, acceptable):
|
||||
""" Returns whether the `value` for this `parameter` is acceptable,
|
||||
given a string or tuple `acceptable`
|
||||
|
||||
:param str parameter: The name of the parameter being set.
|
||||
:param str value: Proposed new value for parameter.
|
||||
:param tuple acceptable: List of acceptable values for parameter.
|
||||
"""
|
||||
# If it's a tuple, there's multiple acceptable options.
|
||||
# Only set a param if it's not acceptable.
|
||||
|
|
@ -276,9 +280,9 @@ def _has_acceptable_tls_versions(parameter_string):
|
|||
if inclusion_list: # For any inclusion list, we still require TLS 1.2.
|
||||
if "TLSv1.2" not in supported_version_list or "!TLSv1.2" in supported_version_list:
|
||||
return False
|
||||
else:
|
||||
else:
|
||||
for bad_version in bad_versions:
|
||||
if "!" + bad_version not in supported_version_list:
|
||||
return False
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ cover () {
|
|||
elif [ "$1" = "certbot_nginx" ]; then
|
||||
min=97
|
||||
elif [ "$1" = "certbot_postfix" ]; then
|
||||
min=99
|
||||
min=100
|
||||
elif [ "$1" = "letshelp_certbot" ]; then
|
||||
min=100
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in a new issue