don't use strings

This commit is contained in:
Erica Portnoy 2020-02-13 17:28:32 -08:00
parent 6c75064318
commit fb0bd9300c
2 changed files with 11 additions and 16 deletions

View file

@ -257,18 +257,13 @@ class ApacheConfigurator(common.Installer):
return None
# Grep in the .so for openssl version
try:
proc = subprocess.Popen(
["strings", ssl_module_location],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
strings = proc.communicate()[0] # strings prints output to stdout
except (OSError, ValueError) as error:
with open(ssl_module_location) as f:
contents = f.read()
except IOError as error:
logger.debug(str(error), exc_info=True)
raise errors.PluginError(
"Unable to run strings")
raise errors.PluginError("Unable to open ssl_module file")
# looks like: OpenSSL 1.0.2s 28 May 2019
matches = re.findall(r"OpenSSL ([0-9]\.[^ ]+) ", strings)
matches = re.findall(r"OpenSSL ([0-9]\.[^ ]+) ", contents)
if not matches:
logger.warning("Could not find OpenSSL version; not disabling session tickets.")
return None

View file

@ -1782,9 +1782,7 @@ class InstallSslOptionsConfTest(util.ApacheTest):
@mock.patch("certbot_apache._internal.configurator.subprocess.Popen")
def test_openssl_version(self, mock_popen):
# pylint: disable=protected-access
mock_popen().communicate.return_value = (
"""
some_string_contents = """
SSLOpenSSLConfCmd
OpenSSL configuration command
SSLv3 not supported by this version of OpenSSL
@ -1794,9 +1792,11 @@ class InstallSslOptionsConfTest(util.ApacheTest):
AH02407: "SSLOpenSSLConfCmd %s %s" failed for %s
AH02556: "SSLOpenSSLConfCmd %s %s" applied to %s
OpenSSL 1.0.2g 1 Mar 2016
""", "")
self.config.parser.modules['ssl_module'] = '/fake/path'
self.assertEqual(self.config.openssl_version, "1.0.2g")
"""
with mock.patch("%s.open" % six.moves.builtins.__name__,
mock.mock_open(read_data=some_string_contents)) as mock_file:
self.config.parser.modules['ssl_module'] = '/fake/path'
self.assertEqual(self.config.openssl_version, "1.0.2g")
if __name__ == "__main__":