mirror of
https://github.com/certbot/certbot.git
synced 2026-01-26 07:41:33 +03:00
Add get_version test
This commit is contained in:
@@ -1320,13 +1320,13 @@ LogLevel warn \n\
|
||||
"""
|
||||
try:
|
||||
proc = subprocess.Popen(
|
||||
['/usr/sbin/apache2ctl', '-v'],
|
||||
[CONFIG.APACHE_CTL, '-v'],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
text = proc.communicate()[0]
|
||||
except (OSError, ValueError):
|
||||
raise errors.LetsEncryptConfiguratorError(
|
||||
"Unable to run /usr/sbin/apache2ctl -v")
|
||||
"Unable to run %s -v" % CONFIG.APACHE_CTL)
|
||||
|
||||
regex = re.compile(r"Apache/([0-9\.]*)", re.IGNORECASE)
|
||||
matches = regex.findall(text)
|
||||
@@ -1335,7 +1335,7 @@ LogLevel warn \n\
|
||||
raise errors.LetsEncryptConfiguratorError(
|
||||
"Unable to find Apache version")
|
||||
|
||||
return tuple(matches[0].split('.'))
|
||||
return tuple([int(i) for i in matches[0].split('.')])
|
||||
|
||||
def verify_setup(self):
|
||||
"""Verify the setup to ensure safe operating environment.
|
||||
|
||||
@@ -13,6 +13,7 @@ import unittest
|
||||
|
||||
from letsencrypt.client import apache_configurator
|
||||
from letsencrypt.client import display
|
||||
from letsencrypt.client import errors
|
||||
from letsencrypt.client import logger
|
||||
|
||||
# Some of these will likely go into a letsencrypt.tests.CONFIG file
|
||||
@@ -20,6 +21,7 @@ TESTING_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||
UBUNTU_CONFIGS = os.path.join(TESTING_DIR, "debian_apache_2_4/")
|
||||
TEMP_DIR = os.path.join(TESTING_DIR, "temp")
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUpModule():
|
||||
"""Run once before all unittests."""
|
||||
@@ -33,6 +35,7 @@ def setUpModule():
|
||||
|
||||
shutil.copytree(UBUNTU_CONFIGS, TEMP_DIR, symlinks=True)
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def tearDownModule():
|
||||
"""Run once after all unittests."""
|
||||
@@ -48,7 +51,7 @@ class TwoVhost80(unittest.TestCase):
|
||||
"""Run before each and every test."""
|
||||
|
||||
# This just states that the ssl module is already loaded
|
||||
mock_popen.return_value = MyPopen()
|
||||
mock_popen.return_value = MyPopen(("ssl_module", ""))
|
||||
|
||||
# Final slash is currently important
|
||||
self.config_path = os.path.join(TEMP_DIR, "two_vhost_80/apache2/")
|
||||
@@ -244,6 +247,32 @@ class TwoVhost80(unittest.TestCase):
|
||||
|
||||
self.assertTrue(len(self.config.vhosts) == 5)
|
||||
|
||||
@mock.patch("letsencrypt.client.apache_configurator."
|
||||
"subprocess.Popen")
|
||||
def test_get_version(self, mock_popen):
|
||||
"""test get_version."""
|
||||
mock_popen.return_value = MyPopen(
|
||||
("Server Version: Apache/2.4.2 (Debian)", ""))
|
||||
self.assertTrue(self.config.get_version() == (2, 4, 2))
|
||||
|
||||
mock_popen.return_value = MyPopen(
|
||||
("Server Version: Apache/2 (Linux)", ""))
|
||||
self.assertTrue(self.config.get_version() == tuple([2]))
|
||||
|
||||
mock_popen.return_value = MyPopen(
|
||||
("Server Version: Apache (Debian)", ""))
|
||||
self.assertRaises(
|
||||
errors.LetsEncryptConfiguratorError, self.config.get_version)
|
||||
|
||||
mock_popen.return_value = MyPopen(
|
||||
("Server Version: Apache/2.3\n Apache/2.4.7", ""))
|
||||
self.assertRaises(
|
||||
errors.LetsEncryptConfiguratorError, self.config.get_version)
|
||||
|
||||
mock_popen.side_effect = OSError("Can't find program")
|
||||
self.assertRaises(
|
||||
errors.LetsEncryptConfiguratorError, self.config.get_version)
|
||||
|
||||
# def _verify_redirect(self, config_path):
|
||||
# """Verifies that the vhost contains the REWRITE."""
|
||||
# with open(config_path, 'r') as config_fd:
|
||||
@@ -262,9 +291,12 @@ def debug_file(filepath):
|
||||
# pylint: disable=too-few-public-methods
|
||||
class MyPopen(object):
|
||||
"""Made for mock popen object."""
|
||||
def communicate(self): #pylint: disable=no-self-use
|
||||
def __init__(self, tup):
|
||||
self.tup = tup
|
||||
|
||||
def communicate(self): # pylint: disable=no-self-use
|
||||
"""Simply return that ssl_module is in output."""
|
||||
return "ssl_module", ""
|
||||
return self.tup
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user