summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Paul Calderone <exarkun@twistedmatrix.com>2014-02-09 08:49:06 -0500
committerJean-Paul Calderone <exarkun@twistedmatrix.com>2014-02-09 08:49:06 -0500
commitf73a3cb6eea1cb122a1621926994cc8124f2c872 (patch)
treef4a54e7f77b216542146542657662e7613665158
parentbef4f4c324fdb1b4040901993ffd590603a59690 (diff)
downloadpyopenssl-f73a3cb6eea1cb122a1621926994cc8124f2c872.tar.gz
tests and fixes for other int/long cases
-rw-r--r--OpenSSL/SSL.py8
-rw-r--r--OpenSSL/test/test_ssl.py54
2 files changed, 58 insertions, 4 deletions
diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py
index 9c375b0..a257f16 100644
--- a/OpenSSL/SSL.py
+++ b/OpenSSL/SSL.py
@@ -252,7 +252,7 @@ class Context(object):
:param method: One of SSLv2_METHOD, SSLv3_METHOD, SSLv23_METHOD, or
TLSv1_METHOD.
"""
- if not isinstance(method, int):
+ if not isinstance(method, integer_types):
raise TypeError("method must be an integer")
try:
@@ -383,7 +383,7 @@ class Context(object):
certfile = certfile.encode("utf-8")
if not isinstance(certfile, bytes):
raise TypeError("certfile must be bytes or unicode")
- if not isinstance(filetype, int):
+ if not isinstance(filetype, integer_types):
raise TypeError("filetype must be an integer")
use_result = _lib.SSL_CTX_use_certificate_file(self._context, certfile, filetype)
@@ -449,7 +449,7 @@ class Context(object):
if filetype is _unspecified:
filetype = FILETYPE_PEM
- elif not isinstance(filetype, int):
+ elif not isinstance(filetype, integer_types):
raise TypeError("filetype must be an integer")
use_result = _lib.SSL_CTX_use_PrivateKey_file(
@@ -1250,7 +1250,7 @@ class Connection(object):
:param state - bitvector of SENT_SHUTDOWN, RECEIVED_SHUTDOWN.
:return: None
"""
- if not isinstance(state, int):
+ if not isinstance(state, integer_types):
raise TypeError("state must be an integer")
_lib.SSL_set_shutdown(self._ssl, state)
diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py
index 4ec057f..ecee95f 100644
--- a/OpenSSL/test/test_ssl.py
+++ b/OpenSSL/test/test_ssl.py
@@ -337,6 +337,16 @@ class ContextTests(TestCase, _LoopbackMixin):
self.assertRaises(ValueError, Context, 10)
+ if not PY3:
+ def test_method_long(self):
+ """
+ On Python 2 :py:class:`Context` accepts values of type
+ :py:obj:`long` as well as :py:obj:`int`.
+ """
+ Context(long(TLSv1_METHOD))
+
+
+
def test_type(self):
"""
:py:obj:`Context` and :py:obj:`ContextType` refer to the same type object and can be
@@ -366,6 +376,25 @@ class ContextTests(TestCase, _LoopbackMixin):
self.assertRaises(Error, ctx.use_privatekey_file, self.mktemp())
+ if not PY3:
+ def test_use_privatekey_file_long(self):
+ """
+ On Python 2 :py:obj:`Context.use_privatekey_file` accepts a
+ filetype of type :py:obj:`long` as well as :py:obj:`int`.
+ """
+ pemfile = self.mktemp()
+
+ key = PKey()
+ key.generate_key(TYPE_RSA, 128)
+
+ with open(pemfile, "wt") as pem:
+ pem.write(
+ dump_privatekey(FILETYPE_PEM, key).decode("ascii"))
+
+ ctx = Context(TLSv1_METHOD)
+ ctx.use_privatekey_file(pemfile, long(FILETYPE_PEM))
+
+
def test_use_certificate_wrong_args(self):
"""
:py:obj:`Context.use_certificate_wrong_args` raises :py:obj:`TypeError`
@@ -445,6 +474,20 @@ class ContextTests(TestCase, _LoopbackMixin):
ctx.use_certificate_file(pem_filename)
+ if not PY3:
+ def test_use_certificate_file_long(self):
+ """
+ On Python 2 :py:obj:`Context.use_certificate_file` accepts a
+ filetype of type :py:obj:`long` as well as :py:obj:`int`.
+ """
+ pem_filename = self.mktemp()
+ with open(pem_filename, "wb") as pem_file:
+ pem_file.write(cleartextCertificatePEM)
+
+ ctx = Context(TLSv1_METHOD)
+ ctx.use_certificate_file(pem_filename, long(FILETYPE_PEM))
+
+
def test_set_app_data_wrong_args(self):
"""
:py:obj:`Context.set_app_data` raises :py:obj:`TypeError` if called with other than
@@ -1617,6 +1660,17 @@ class ConnectionTests(TestCase, _LoopbackMixin):
self.assertEquals(connection.get_shutdown(), RECEIVED_SHUTDOWN)
+ if not PY3:
+ def test_set_shutdown_long(self):
+ """
+ On Python 2 :py:obj:`Connection.set_shutdown` accepts an argument
+ of type :py:obj:`long` as well as :py:obj:`int`.
+ """
+ connection = Connection(Context(TLSv1_METHOD), socket())
+ connection.set_shutdown(long(RECEIVED_SHUTDOWN))
+ self.assertEquals(connection.get_shutdown(), RECEIVED_SHUTDOWN)
+
+
def test_app_data_wrong_args(self):
"""
:py:obj:`Connection.set_app_data` raises :py:obj:`TypeError` if called with other than