libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [1/4] libcloud git commit: Add tests for certifi CA bundle path stuff.
Date Fri, 17 Jun 2016 06:39:31 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk a4a58f9c5 -> 01c9bafbd


Add tests for certifi CA bundle path stuff.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/f777da60
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/f777da60
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/f777da60

Branch: refs/heads/trunk
Commit: f777da60d520c06373f6182e5ef44aa10e9b5837
Parents: ec78da2
Author: Tomaz Muraus <tomaz@tomaz.me>
Authored: Tue Jun 14 19:06:27 2016 +0200
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Fri Jun 17 16:36:42 2016 +1000

----------------------------------------------------------------------
 libcloud/test/test_httplib_ssl.py | 47 ++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/f777da60/libcloud/test/test_httplib_ssl.py
----------------------------------------------------------------------
diff --git a/libcloud/test/test_httplib_ssl.py b/libcloud/test/test_httplib_ssl.py
index 996498f..0fac77d 100644
--- a/libcloud/test/test_httplib_ssl.py
+++ b/libcloud/test/test_httplib_ssl.py
@@ -152,6 +152,53 @@ class TestHttpLibSSLTests(unittest.TestCase):
         self.assertEqual(e.errno, 105)
         self.assertTrue('Some random error' in str(e))
 
+    def test_certifi_ca_bundle_in_search_path(self):
+        mock_certifi_ca_bundle_path = '/certifi/bundle/path'
+
+        # Certifi not available
+        import libcloud.security
+        reload(libcloud.security)
+
+        original_length = len(libcloud.security.CA_CERTS_PATH)
+
+        self.assertTrue(mock_certifi_ca_bundle_path not in
+                        libcloud.security.CA_CERTS_PATH)
+
+        # Certifi is available
+        mock_certifi = mock.Mock()
+        mock_certifi.where.return_value = mock_certifi_ca_bundle_path
+        sys.modules['certifi'] = mock_certifi
+
+        # Certifi CA bundle path should be injected at the begining of search list
+        import libcloud.security
+        reload(libcloud.security)
+
+        self.assertEqual(libcloud.security.CA_CERTS_PATH[0],
+                         mock_certifi_ca_bundle_path)
+        self.assertEqual(len(libcloud.security.CA_CERTS_PATH),
+                         (original_length + 1))
+
+        # Certifi is available, but USE_CERTIFI is set to False
+        os.environ['LIBCLOUD_SSL_USE_CERTIFI'] = 'false'
+
+        import libcloud.security
+        reload(libcloud.security)
+
+        self.assertTrue(mock_certifi_ca_bundle_path not in
+                        libcloud.security.CA_CERTS_PATH)
+        self.assertEqual(len(libcloud.security.CA_CERTS_PATH), original_length)
+
+        # And enabled
+        os.environ['LIBCLOUD_SSL_USE_CERTIFI'] = 'true'
+
+        import libcloud.security
+        reload(libcloud.security)
+
+        self.assertEqual(libcloud.security.CA_CERTS_PATH[0],
+                         mock_certifi_ca_bundle_path)
+        self.assertEqual(len(libcloud.security.CA_CERTS_PATH),
+                         (original_length + 1))
+
 
 if __name__ == '__main__':
     sys.exit(unittest.main())


Mime
View raw message