mirror of
https://github.com/certbot/certbot.git
synced 2026-06-05 06:42:10 -04:00
Python 3 fixes and Postconf tester extends TempDir test class
This commit is contained in:
parent
d744602279
commit
5fa405214b
3 changed files with 26 additions and 40 deletions
|
|
@ -5,6 +5,7 @@ import os
|
|||
from functools import partial
|
||||
|
||||
import zope.interface
|
||||
import six
|
||||
|
||||
from certbot import errors
|
||||
from certbot import interfaces
|
||||
|
|
@ -188,7 +189,7 @@ class Installer(plugins_common.Installer):
|
|||
def _set_vars(self, var_dict):
|
||||
"""Sets all parameters in var_dict to config file.
|
||||
"""
|
||||
for param, acceptable in var_dict.iteritems():
|
||||
for param, acceptable in six.iteritems(var_dict):
|
||||
if isinstance(acceptable, tuple):
|
||||
if self.postconf.get(param) not in acceptable:
|
||||
self.postconf.set(param, acceptable[0],
|
||||
|
|
@ -223,10 +224,10 @@ class Installer(plugins_common.Installer):
|
|||
check_override=util.report_master_overrides)
|
||||
|
||||
def _enable_policy_list(self, domain, options):
|
||||
# pylint: disable=unused-argument
|
||||
if self._starttls_policy_enabled:
|
||||
return
|
||||
self._starttls_policy_enabled = True
|
||||
# pylint: disable=unused-argument
|
||||
try:
|
||||
from starttls_policy import policy
|
||||
except ImportError:
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ class ConfigMain(util.PostfixUtilBase):
|
|||
self._get_output(args)
|
||||
except:
|
||||
raise errors.PluginError("Unable to save to Postfix config!")
|
||||
for name, value in self._updated.iteritems():
|
||||
for name, value in six.iteritems(self._updated):
|
||||
self._db[name] = value
|
||||
self._updated = {}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,63 +2,48 @@
|
|||
|
||||
import os
|
||||
import pkg_resources
|
||||
import random
|
||||
import shutil
|
||||
import string
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from certbot.tests import util as test_util
|
||||
|
||||
# TODO (sydneyli): Mock out calls to postconf
|
||||
# TODO (sydneyli): inherit certbot.tests.util.TempDirTestCase
|
||||
|
||||
def _rand_str(n):
|
||||
"""Returns a random string with length n, for use as a temporary directory."""
|
||||
return ''.join([random.choice(string.lowercase) for _ in xrange(n)])
|
||||
|
||||
class PostConfTest(unittest.TestCase):
|
||||
class PostConfTest(test_util.TempDirTestCase):
|
||||
"""Tests for certbot_postfix.util.PostfixUtilBase."""
|
||||
def setUp(self):
|
||||
from certbot_postfix.postconf import ConfigMain
|
||||
self.tmpdir = tempfile.mkdtemp(suffix=_rand_str(10))
|
||||
super(PostConfTest, self).setUp()
|
||||
_config_file = pkg_resources.resource_filename("certbot_postfix.tests",
|
||||
os.path.join("testdata", "small.cf"))
|
||||
self.config_path = os.path.join(self.tmpdir, 'main.cf')
|
||||
self.config_path = os.path.join(self.tempdir, 'main.cf')
|
||||
shutil.copyfile(_config_file, self.config_path)
|
||||
self.config = ConfigMain('postconf', self.tmpdir)
|
||||
self.config = ConfigMain('postconf', self.tempdir)
|
||||
|
||||
def test_read_defalut(self):
|
||||
self.assertEqual(self.config.get_default('smtpd_sasl_auth_enable'), 'no')
|
||||
|
||||
def test_read_write(self):
|
||||
try:
|
||||
self.config.set('inet_interfaces', '127.0.0.1')
|
||||
self.config.flush()
|
||||
with open(self.config_path) as f:
|
||||
self.assertTrue('inet_interfaces = 127.0.0.1\n' in f.readlines())
|
||||
finally:
|
||||
shutil.rmtree(self.tmpdir)
|
||||
self.config.set('inet_interfaces', '127.0.0.1')
|
||||
self.config.flush()
|
||||
with open(self.config_path) as f:
|
||||
self.assertTrue('inet_interfaces = 127.0.0.1\n' in f.readlines())
|
||||
|
||||
def test_write_revert(self):
|
||||
try:
|
||||
self.config.set('postscreen_forbidden_commands', 'dummy_value')
|
||||
# revert config set
|
||||
self.config.set('postscreen_forbidden_commands', '$smtpd_forbidden_commands')
|
||||
self.config.flush()
|
||||
with open(self.config_path) as f:
|
||||
self.assertTrue(not any('postscreen_forbidden_commands' in line \
|
||||
for line in f.readlines()))
|
||||
finally:
|
||||
shutil.rmtree(self.tmpdir)
|
||||
self.config.set('postscreen_forbidden_commands', 'dummy_value')
|
||||
# revert config set
|
||||
self.config.set('postscreen_forbidden_commands', '$smtpd_forbidden_commands')
|
||||
self.config.flush()
|
||||
with open(self.config_path) as f:
|
||||
self.assertTrue(not any('postscreen_forbidden_commands' in line \
|
||||
for line in f.readlines()))
|
||||
|
||||
def test_write_default(self):
|
||||
try:
|
||||
self.config.set('postscreen_forbidden_commands', '$smtpd_forbidden_commands')
|
||||
self.config.flush()
|
||||
with open(self.config_path) as f:
|
||||
self.assertTrue(not any('postscreen_forbidden_commands' in line \
|
||||
for line in f.readlines()))
|
||||
finally:
|
||||
shutil.rmtree(self.tmpdir)
|
||||
self.config.set('postscreen_forbidden_commands', '$smtpd_forbidden_commands')
|
||||
self.config.flush()
|
||||
with open(self.config_path) as f:
|
||||
self.assertTrue(not any('postscreen_forbidden_commands' in line \
|
||||
for line in f.readlines()))
|
||||
|
||||
if __name__ == '__main__': # pragma: no cover
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Reference in a new issue