You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2016/01/16 14:34:36 UTC
[2/2] libcloud git commit: Add test cases for get_ssl_version
function.
Add test cases for get_ssl_version function.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/67b51312
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/67b51312
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/67b51312
Branch: refs/heads/use_sslv23_constant_in_newer_versions_of_python
Commit: 67b5131222ab72a583f203af69a9b0dd42876877
Parents: 4b218af
Author: Tomaz Muraus <to...@tomaz.me>
Authored: Sat Jan 16 14:31:06 2016 +0100
Committer: Tomaz Muraus <to...@tomaz.me>
Committed: Sat Jan 16 14:31:06 2016 +0100
----------------------------------------------------------------------
libcloud/test/test_httplib_ssl.py | 41 +++++++++++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/67b51312/libcloud/test/test_httplib_ssl.py
----------------------------------------------------------------------
diff --git a/libcloud/test/test_httplib_ssl.py b/libcloud/test/test_httplib_ssl.py
index 28eed69..65e1b70 100644
--- a/libcloud/test/test_httplib_ssl.py
+++ b/libcloud/test/test_httplib_ssl.py
@@ -15,6 +15,7 @@
import os
import sys
+import ssl
import os.path
import socket
@@ -22,7 +23,7 @@ import mock
from mock import patch
import libcloud.security
-
+from libcloud.security import get_ssl_version
from libcloud.utils.py3 import reload
from libcloud.httplib_ssl import LibcloudHTTPSConnection
@@ -142,6 +143,44 @@ class TestHttpLibSSLTests(unittest.TestCase):
self.assertEqual(e.errno, 104)
self.assertTrue(expected_msg in str(e))
+ def test_get_ssl_version(self):
+ # User provided value should always have precedence over dynamicaly
+ # retrieved values
+ libcloud.security.SSL_VERSION = 10
+
+ libcloud.security.PY2_post_279 = True
+ result = get_ssl_version()
+ self.assertEqual(result, 10)
+
+ libcloud.security.PY3_post_34 = True
+ result = get_ssl_version()
+ self.assertEqual(result, 10)
+
+ libcloud.security.PY2_post_279 = False
+ libcloud.security.PY3_post_34 = False
+ libcloud.security.SSL_VERSION = None
+
+ # Python >= 2.7.9 should use PROTOCOL_SSLv23
+ libcloud.security.PY2_post_279 = True
+ result = get_ssl_version()
+ self.assertEqual(result, ssl.PROTOCOL_SSLv23)
+
+ libcloud.security.PY2_post_279 = False
+ libcloud.security.PY3_post_34 = False
+
+ # Python >= 3.4 should use PROTOCOL_SSLv23
+ libcloud.security.PY3_post_34 = True
+ result = get_ssl_version()
+ self.assertEqual(result, ssl.PROTOCOL_SSLv23)
+
+ # Python < 2.7.9 and Python < 3.4, should use TLS_v1
+ libcloud.security.PY2_post_279 = False
+ libcloud.security.PY3_post_34 = False
+
+ # Python >= 3.4 should use PROTOCOL_SSLv23
+ result = get_ssl_version()
+ self.assertEqual(result, ssl.PROTOCOL_TLSv1)
+
if __name__ == '__main__':
sys.exit(unittest.main())