From 0a9f66338c9d7ab0939e8c5ffdaa20a251c72695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moise=CC=81s=20Guimara=CC=83es?= Date: Sun, 15 Jan 2017 12:51:09 -0200 Subject: [PATCH] adds coverity tests --- wrapper/python/wolfssl/.gitignore | 3 +++ wrapper/python/wolfssl/test/conftest.py | 5 ++--- wrapper/python/wolfssl/test/test_context.py | 6 ++++++ wrapper/python/wolfssl/test/test_methods.py | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/wrapper/python/wolfssl/.gitignore b/wrapper/python/wolfssl/.gitignore index 5e6f6f9bd..101697443 100644 --- a/wrapper/python/wolfssl/.gitignore +++ b/wrapper/python/wolfssl/.gitignore @@ -11,6 +11,9 @@ dist/ # Unit test .tox/ +htmlcov/ +.coverage + # Sphinx documentation docs/_build/ diff --git a/wrapper/python/wolfssl/test/conftest.py b/wrapper/python/wolfssl/test/conftest.py index 1128f4448..09d52618a 100644 --- a/wrapper/python/wolfssl/test/conftest.py +++ b/wrapper/python/wolfssl/test/conftest.py @@ -29,9 +29,8 @@ import pytest @pytest.fixture def tcp_socket(): - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - yield sock - sock.close() + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: + yield sock @pytest.fixture(params=[ssl, wolfssl], ids=["ssl", "wolfssl"]) def ssl_provider(request): diff --git a/wrapper/python/wolfssl/test/test_context.py b/wrapper/python/wolfssl/test/test_context.py index b8692781d..3d545fc5b 100644 --- a/wrapper/python/wolfssl/test/test_context.py +++ b/wrapper/python/wolfssl/test/test_context.py @@ -121,6 +121,9 @@ def test_context_creation(ssl_context): assert ssl_context != None def test_verify_mode(ssl_provider, ssl_context): + with pytest.raises(ValueError): + ssl_context.verify_mode = -1 + assert ssl_context.verify_mode == ssl_provider.CERT_NONE ssl_context.verify_mode = ssl_provider.CERT_REQUIRED @@ -129,6 +132,9 @@ def test_verify_mode(ssl_provider, ssl_context): def test_set_ciphers(ssl_context): ssl_context.set_ciphers("DHE-RSA-AES256-SHA256") + with pytest.raises(Exception): + ssl_context.set_ciphers("foo") + def test_load_cert_chain_raises(ssl_context): with pytest.raises(TypeError): ssl_context.load_cert_chain(None) diff --git a/wrapper/python/wolfssl/test/test_methods.py b/wrapper/python/wolfssl/test/test_methods.py index 21fede687..70d068c9c 100644 --- a/wrapper/python/wolfssl/test/test_methods.py +++ b/wrapper/python/wolfssl/test/test_methods.py @@ -29,8 +29,8 @@ from wolfssl._methods import (WolfSSLMethod, PROTOCOL_SSLv3, PROTOCOL_SSLv23, from wolfssl._ffi import ffi as _ffi @pytest.fixture( - params=[PROTOCOL_SSLv3, PROTOCOL_TLSv1, PROTOCOL_TLSv1_1], - ids=["SSLv3", "TLSv1", "TLSv1_1"]) + params=[-1, PROTOCOL_SSLv3, PROTOCOL_TLSv1, PROTOCOL_TLSv1_1], + ids=["invalid", "SSLv3", "TLSv1", "TLSv1_1"]) def unsupported_method(request): yield request.param