libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From quent...@apache.org
Subject [1/4] libcloud git commit: Test 'CA_CERTS_PATH defined as list' warning
Date Fri, 06 Oct 2017 19:34:47 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 8eab5d210 -> 2075b87f6


Test 'CA_CERTS_PATH defined as list' warning


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

Branch: refs/heads/trunk
Commit: c2e71ecb4c2b97d858eebac8cae384438338f268
Parents: 6333ca7
Author: Quentin Pradet <quentinp@apache.org>
Authored: Tue Oct 3 09:24:00 2017 +0400
Committer: Quentin Pradet <quentinp@apache.org>
Committed: Fri Oct 6 23:28:20 2017 +0400

----------------------------------------------------------------------
 libcloud/http.py           | 26 ++++++++++++++------------
 libcloud/test/test_http.py | 11 ++++++++++-
 2 files changed, 24 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/c2e71ecb/libcloud/http.py
----------------------------------------------------------------------
diff --git a/libcloud/http.py b/libcloud/http.py
index b855b42..9149995 100644
--- a/libcloud/http.py
+++ b/libcloud/http.py
@@ -144,22 +144,24 @@ class LibcloudBaseConnection(object):
     def _setup_verify(self):
         self.verify = libcloud.security.VERIFY_SSL_CERT
 
-    def _setup_ca_cert(self):
+    def _setup_ca_cert(self, **kwargs):
+        # simulating keyword-only argument in Python 2
+        ca_certs_path = kwargs.get('ca_cert', libcloud.security.CA_CERTS_PATH)
+
         if self.verify is False:
             pass
         else:
-            if isinstance(libcloud.security.CA_CERTS_PATH, list):
-                if len(libcloud.security.CA_CERTS_PATH) > 1:
-                    msg = ('Providing a list of CA trusts is no longer '
-                           'supported since libcloud 2.0. Using the first '
-                           'element in the list. See '
-                           'http://libcloud.readthedocs.io/en/latest/other/'
-                           'changes_in_2_0.html#providing-a-list-of-ca-trusts-'
-                           'is-no-longer-supported')
-                    warnings.warn(msg)
-                self.ca_cert = libcloud.security.CA_CERTS_PATH[0]
+            if isinstance(ca_certs_path, list):
+                msg = (
+                    'Providing a list of CA trusts is no longer supported '
+                    'since libcloud 2.0. Using the first element in the list. '
+                    'See http://libcloud.readthedocs.io/en/latest/other/'
+                    'changes_in_2_0.html#providing-a-list-of-ca-trusts-is-no-'
+                    'longer-supported')
+                warnings.warn(msg, DeprecationWarning)
+                self.ca_cert = ca_certs_path[0]
             else:
-                self.ca_cert = libcloud.security.CA_CERTS_PATH
+                self.ca_cert = ca_certs_path
 
     def _setup_signing(self, cert_file=None, key_file=None):
         """

http://git-wip-us.apache.org/repos/asf/libcloud/blob/c2e71ecb/libcloud/test/test_http.py
----------------------------------------------------------------------
diff --git a/libcloud/test/test_http.py b/libcloud/test/test_http.py
index dbe742c..2e9eeb1 100644
--- a/libcloud/test/test_http.py
+++ b/libcloud/test/test_http.py
@@ -16,7 +16,7 @@
 import os
 import sys
 import os.path
-from mock import patch
+import warnings
 
 import libcloud.security
 
@@ -66,6 +66,15 @@ class TestHttpLibSSLTests(unittest.TestCase):
 
         self.assertEqual(libcloud.security.CA_CERTS_PATH, file_path)
 
+    def test_ca_cert_list_warning(self):
+        with warnings.catch_warnings(record=True) as w:
+            self.httplib_object.verify = True
+            self.httplib_object._setup_ca_cert(
+                ca_cert=[ORIGINAL_CA_CERTS_PATH])
+            self.assertEqual(self.httplib_object.ca_cert,
+                             ORIGINAL_CA_CERTS_PATH)
+            self.assertEqual(w[0].category, DeprecationWarning)
+
     def test_setup_ca_cert(self):
         # verify = False, _setup_ca_cert should be a no-op
         self.httplib_object.verify = False


Mime
View raw message