def test_find_libcrypto_with_system_before_catalina(self): """ Test _find_libcrypto on a pre-Catalina macOS host by simulating not finding any other libcryptos and verifying that it defaults to system. """ lib_path = _find_libcrypto() self.assertEqual(lib_path, "/usr/lib/libcrypto.dylib")
def test_find_libcrypto_smartos(self): """ Test _find_libcrypto on a SmartOS host. """ lib_path = _find_libcrypto() self.assertTrue( fnmatch.fnmatch( lib_path, os.path.join(os.path.dirname(sys.executable), "libcrypto*")))
def test_find_libcrypto_darwin_bigsur_packaged(self): """ Test _find_libcrypto on a Darwin-like macOS host where there isn't a lacation returned by ctypes.util.find_library() and the libcrypto installation comes from a package manager (ports, brew, salt). """ managed_paths = { "salt": "/opt/salt/lib/libcrypto.dylib", "brew": "/test/homebrew/prefix/opt/openssl/lib/libcrypto.dylib", "port": "/opt/local/lib/libcrypto.dylib", } saved_getenv = os.getenv def mock_getenv(env): def test_getenv(var, default=None): return env.get(var, saved_getenv(var, default)) return test_getenv def mock_glob(expected_lib): def test_glob(pattern): if fnmatch.fnmatch(expected_lib, pattern): return [expected_lib] return [] return test_glob for package_manager, expected_lib in managed_paths.items(): if package_manager == "brew": env = {"HOMEBREW_PREFIX": "/test/homebrew/prefix"} else: env = {"HOMEBREW_PREFIX": ""} with patch.object(os, "getenv", mock_getenv(env)): with patch.object(glob, "glob", mock_glob(expected_lib)): lib_path = _find_libcrypto() self.assertEqual(expected_lib, lib_path) # On Big Sur, there's nothing else to fall back on. with patch.object(glob, "glob", lambda _: []): with self.assertRaises(OSError): lib_path = _find_libcrypto()
def test_find_libcrypto_aix(self): """ Test _find_libcrypto on an IBM AIX host. """ lib_path = _find_libcrypto() if os.path.isdir("/opt/salt/lib"): self.assertTrue( fnmatch.fnmatch(lib_path, "/opt/salt/lib/libcrypto.so*")) else: self.assertTrue( fnmatch.fnmatch(lib_path, "/opt/freeware/lib/libcrypto.so*"))
def test_find_libcrypto_sunos(self): """ Test _find_libcrypto on a Solaris-like host. """ lib_path = _find_libcrypto() passed = False for i in ("/opt/local/lib/libcrypto.so*", "/opt/tools/lib/libcrypto.so*"): if fnmatch.fnmatch(lib_path, i): passed = True break self.assertTrue(passed)
def test_find_libcrypto_darwin(self): """ Test _find_libcrypto on a Darwin-like or macOS host. """ lib_path = _find_libcrypto() passed = False for i in ( "/usr/lib/libcrypto.*.dylib", "/usr/local/opt/openssl/lib/libcrypto.dylib", "/usr/local/opt/openssl@*/lib/libcrypto.dylib", ): if fnmatch.fnmatch(lib_path, i): passed = True break self.assertTrue(passed)
def test_find_libcrypto_darwin_catalina(self): """ Test _find_libcrypto on a Darwin-like macOS host where there isn't a lacation returned by ctypes.util.find_library() """ lib_path = _find_libcrypto() passed = False for i in ( "/opt/salt/lib/libcrypto.dylib", "/usr/local/opt/openssl/lib/libcrypto.dylib", "/usr/local/opt/openssl@*/lib/libcrypto.dylib", "/opt/local/lib/libcrypto.dylib", "/usr/lib/libcrypto.*.dylib", ): if fnmatch.fnmatch(lib_path, i): passed = True break self.assertTrue(passed)
def test_find_libcrypto_with_system_and_not_catalina(self): """ Test _find_libcrypto on a Catalina-like macOS host, simulate not finding any other libcryptos and just defaulting to system. """ lib_path = _find_libcrypto() passed = False for i in ( "/opt/salt/lib/libcrypto.dylib", "/usr/local/opt/openssl/lib/libcrypto.dylib", "/usr/local/opt/openssl@*/lib/libcrypto.dylib", "/opt/local/lib/libcrypto.dylib", "/usr/lib/libcrypto.*.dylib", ): if fnmatch.fnmatch(lib_path, i): passed = True break self.assertFalse(passed) self.assertEqual(lib_path, "/usr/lib/libcrypto.dylib")
def test_find_libcrypto_darwin_catalina(self): """ Test _find_libcrypto on a macOS Catalina host where there are no custom libcryptos and defaulting to the versioned system libraries. """ available = [ "/usr/lib/libcrypto.0.9.7.dylib", "/usr/lib/libcrypto.0.9.8.dylib", "/usr/lib/libcrypto.35.dylib", "/usr/lib/libcrypto.41.dylib", "/usr/lib/libcrypto.42.dylib", "/usr/lib/libcrypto.44.dylib", "/usr/lib/libcrypto.dylib", ] def test_glob(pattern): return [lib for lib in available if fnmatch.fnmatch(lib, pattern)] with patch.object(glob, "glob", test_glob): lib_path = _find_libcrypto() self.assertEqual("/usr/lib/libcrypto.44.dylib", lib_path)
def test_find_libcrypto_unsupported(self): """ Ensure that _find_libcrypto works correctly on an unsupported host OS. """ with self.assertRaises(OSError): _find_libcrypto()
def test_find_libcrypto_win32(self): """ Test _find_libcrypto on Windows hosts. """ lib_path = _find_libcrypto() self.assertEqual(lib_path, "libeay32")