fixes pylint warnings;

adds more tests to load_verify_locations;
fixes data type when calling C functions;
fixes result verification when calling C functions.
This commit is contained in:
Moisés Guimarães
2016-11-15 12:56:35 -03:00
parent 7201435f2d
commit 760ddd14f5
7 changed files with 133 additions and 56 deletions

View File

@@ -17,28 +17,31 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# pylint: disable=missing-docstring, invalid-name, import-error
import unittest
import socket
import wolfssl
import ssl
# import wolfssl
class SSLClientTest(unittest.TestCase):
ssl_provider = ssl
host = "www.google.com"
port = 443
def setUp(self):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def test_wrap_socket(self):
self.secure_sock = self.ssl_provider.wrap_socket(
self.sock, ssl_version=ssl.PROTOCOL_SSLv23)
self.secure_sock.connect((self.host, self.port))
secure_sock = self.ssl_provider.wrap_socket(
self.sock, ssl_version=ssl.PROTOCOL_SSLv23)
secure_sock.connect((self.host, self.port))
self.secure_sock.send(b"GET / HTTP/1.1\n\n")
self.assertEquals(b"HTTP", self.secure_sock.recv(4))
secure_sock.send(b"GET / HTTP/1.1\n\n")
self.assertEqual(b"HTTP", secure_sock.recv(4))
self.secure_sock.close()
secure_sock.close()
#class TestWolfSSL(SSLClientTest):

View File

@@ -17,9 +17,12 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# pylint: disable=missing-docstring, invalid-name, import-error
import unittest
import wolfssl
import ssl
import wolfssl
class TestSSLContext(unittest.TestCase):
@@ -34,8 +37,11 @@ class TestSSLContext(unittest.TestCase):
def test_load_cert_chain(self):
self.assertRaises(TypeError, self.ctx.load_cert_chain, None)
def test_load_verify_locations(self):
def test_load_verify_locations_raises(self):
self.assertRaises(TypeError, self.ctx.load_verify_locations, None)
def test_load_verify_locations_with_cafile(self):
self.ctx.load_verify_locations(cafile="../../../certs/ca-cert.pem")
class TestWolfSSLContext(TestSSLContext):
provider = wolfssl
provider = wolfssl

View File

@@ -17,8 +17,13 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# pylint: disable=missing-docstring, invalid-name, import-error
import unittest
from wolfssl._methods import *
from wolfssl._methods import (WolfSSLMethod, PROTOCOL_SSLv3, PROTOCOL_SSLv23,
PROTOCOL_TLS, PROTOCOL_TLSv1, PROTOCOL_TLSv1_1,
PROTOCOL_TLSv1_2)
from wolfssl._ffi import ffi as _ffi
@@ -41,31 +46,31 @@ class TestMethods(unittest.TestCase):
def test_SSLv23_doesnt_raises(self):
client = WolfSSLMethod(PROTOCOL_SSLv23, False)
server = WolfSSLMethod(PROTOCOL_SSLv23, True)
self.assertIsInstance(client, WolfSSLMethod)
self.assertIsInstance(server, WolfSSLMethod)
self.assertNotEquals(client.native_object, _ffi.NULL)
self.assertNotEquals(server.native_object, _ffi.NULL)
self.assertNotEqual(client.native_object, _ffi.NULL)
self.assertNotEqual(server.native_object, _ffi.NULL)
def test_TLS_doesnt_raises(self):
client = WolfSSLMethod(PROTOCOL_TLS, False)
server = WolfSSLMethod(PROTOCOL_TLS, True)
self.assertIsInstance(client, WolfSSLMethod)
self.assertIsInstance(server, WolfSSLMethod)
self.assertNotEquals(client.native_object, _ffi.NULL)
self.assertNotEquals(server.native_object, _ffi.NULL)
self.assertNotEqual(client.native_object, _ffi.NULL)
self.assertNotEqual(server.native_object, _ffi.NULL)
def test_TLSv1_2_doesnt_raises(self):
client = WolfSSLMethod(PROTOCOL_TLSv1_2, False)
server = WolfSSLMethod(PROTOCOL_TLSv1_2, True)
self.assertIsInstance(client, WolfSSLMethod)
self.assertIsInstance(server, WolfSSLMethod)
self.assertNotEquals(client.native_object, _ffi.NULL)
self.assertNotEquals(server.native_object, _ffi.NULL)
self.assertNotEqual(client.native_object, _ffi.NULL)
self.assertNotEqual(server.native_object, _ffi.NULL)