aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/conftest.py13
-rw-r--r--test/mitmproxy/addons/test_check_alpn.py23
-rw-r--r--test/mitmproxy/net/test_tcp.py41
-rw-r--r--test/mitmproxy/proxy/protocol/test_http2.py12
-rw-r--r--test/mitmproxy/utils/test_version_check.py25
-rw-r--r--test/pathod/protocols/test_http2.py4
-rw-r--r--test/pathod/test_pathoc.py15
-rw-r--r--test/pathod/test_pathod.py6
8 files changed, 10 insertions, 129 deletions
diff --git a/test/conftest.py b/test/conftest.py
index bb913548..b0842bc3 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -1,15 +1,8 @@
import os
import pytest
-import OpenSSL
-
-import mitmproxy.net.tcp
pytest_plugins = ('test.full_coverage_plugin',)
-requires_alpn = pytest.mark.skipif(
- not mitmproxy.net.tcp.HAS_ALPN,
- reason='requires OpenSSL with ALPN support')
-
skip_windows = pytest.mark.skipif(
os.name == "nt",
reason='Skipping due to Windows'
@@ -24,9 +17,3 @@ skip_appveyor = pytest.mark.skipif(
"APPVEYOR" in os.environ,
reason='Skipping due to Appveyor'
)
-
-
-@pytest.fixture()
-def disable_alpn(monkeypatch):
- monkeypatch.setattr(mitmproxy.net.tcp, 'HAS_ALPN', False)
- monkeypatch.setattr(OpenSSL.SSL._lib, 'Cryptography_HAS_ALPN', False)
diff --git a/test/mitmproxy/addons/test_check_alpn.py b/test/mitmproxy/addons/test_check_alpn.py
deleted file mode 100644
index 2b1d6058..00000000
--- a/test/mitmproxy/addons/test_check_alpn.py
+++ /dev/null
@@ -1,23 +0,0 @@
-from mitmproxy.addons import check_alpn
-from mitmproxy.test import taddons
-from ...conftest import requires_alpn
-
-
-class TestCheckALPN:
-
- @requires_alpn
- def test_check_alpn(self):
- msg = 'ALPN support missing'
-
- with taddons.context() as tctx:
- a = check_alpn.CheckALPN()
- tctx.configure(a)
- assert not tctx.master.has_log(msg)
-
- def test_check_no_alpn(self, disable_alpn):
- msg = 'ALPN support missing'
-
- with taddons.context() as tctx:
- a = check_alpn.CheckALPN()
- tctx.configure(a)
- assert tctx.master.has_log(msg)
diff --git a/test/mitmproxy/net/test_tcp.py b/test/mitmproxy/net/test_tcp.py
index 73de0879..3345840e 100644
--- a/test/mitmproxy/net/test_tcp.py
+++ b/test/mitmproxy/net/test_tcp.py
@@ -3,7 +3,6 @@ import queue
import time
import socket
import random
-import os
import threading
import pytest
from unittest import mock
@@ -15,7 +14,6 @@ from mitmproxy import exceptions
from mitmproxy.test import tutils
from . import tservers
-from ...conftest import requires_alpn
class EchoHandler(tcp.BaseHandler):
@@ -534,36 +532,18 @@ class TestTimeOut(tservers.ServerTestBase):
c.rfile.read(10)
-class TestCryptographyALPN:
-
- def test_has_alpn(self):
- if os.environ.get("OPENSSL") == "with-alpn":
- assert tcp.HAS_ALPN
- assert SSL._lib.Cryptography_HAS_ALPN
- elif os.environ.get("OPENSSL") == "old":
- assert not tcp.HAS_ALPN
- assert not SSL._lib.Cryptography_HAS_ALPN
-
-
class TestALPNClient(tservers.ServerTestBase):
handler = ALPNHandler
ssl = dict(
alpn_select=b"bar"
)
- @requires_alpn
- @pytest.mark.parametrize('has_alpn,alpn_protos, expected_negotiated, expected_response', [
- (True, [b"foo", b"bar", b"fasel"], b'bar', b'bar'),
- (True, [], b'', b'NONE'),
- (True, None, b'', b'NONE'),
- (False, [b"foo", b"bar", b"fasel"], b'', b'NONE'),
- (False, [], b'', b'NONE'),
- (False, None, b'', b'NONE'),
+ @pytest.mark.parametrize('alpn_protos, expected_negotiated, expected_response', [
+ ([b"foo", b"bar", b"fasel"], b'bar', b'bar'),
+ ([], b'', b'NONE'),
+ (None, b'', b'NONE'),
])
- def test_alpn(self, monkeypatch, has_alpn, alpn_protos, expected_negotiated, expected_response):
- monkeypatch.setattr(tcp, 'HAS_ALPN', has_alpn)
- monkeypatch.setattr(SSL._lib, 'Cryptography_HAS_ALPN', has_alpn)
-
+ def test_alpn(self, monkeypatch, alpn_protos, expected_negotiated, expected_response):
c = tcp.TCPClient(("127.0.0.1", self.port))
with c.connect():
c.convert_to_ssl(alpn_protos=alpn_protos)
@@ -574,7 +554,7 @@ class TestALPNClient(tservers.ServerTestBase):
class TestNoSSLNoALPNClient(tservers.ServerTestBase):
handler = ALPNHandler
- def test_no_ssl_no_alpn(self, disable_alpn):
+ def test_no_ssl_no_alpn(self):
c = tcp.TCPClient(("127.0.0.1", self.port))
with c.connect():
assert c.get_alpn_proto_negotiated() == b""
@@ -857,9 +837,8 @@ class TestSSLInvalid(tservers.ServerTestBase):
def test_alpn_error(self):
c = tcp.TCPClient(("127.0.0.1", self.port))
with c.connect():
- if tcp.HAS_ALPN:
- with pytest.raises(exceptions.TlsException, match="must be a function"):
- c.create_ssl_context(alpn_select_callback="foo")
+ with pytest.raises(exceptions.TlsException, match="must be a function"):
+ c.create_ssl_context(alpn_select_callback="foo")
- with pytest.raises(exceptions.TlsException, match="ALPN error"):
- c.create_ssl_context(alpn_select="foo", alpn_select_callback="bar")
+ with pytest.raises(exceptions.TlsException, match="ALPN error"):
+ c.create_ssl_context(alpn_select="foo", alpn_select_callback="bar")
diff --git a/test/mitmproxy/proxy/protocol/test_http2.py b/test/mitmproxy/proxy/protocol/test_http2.py
index 487d8890..583e6e27 100644
--- a/test/mitmproxy/proxy/protocol/test_http2.py
+++ b/test/mitmproxy/proxy/protocol/test_http2.py
@@ -17,7 +17,6 @@ from mitmproxy.net.http import http1, http2
from pathod.language import generators
from ... import tservers
-from ....conftest import requires_alpn
import logging
logging.getLogger("hyper.packages.hpack.hpack").setLevel(logging.WARNING)
@@ -203,7 +202,6 @@ class _Http2Test(_Http2TestBase, _Http2ServerBase):
_Http2ServerBase.teardown_class()
-@requires_alpn
class TestSimple(_Http2Test):
request_body_buffer = b''
@@ -286,7 +284,6 @@ class TestSimple(_Http2Test):
assert response_body_buffer == b'response body'
-@requires_alpn
class TestRequestWithPriority(_Http2Test):
@classmethod
@@ -368,7 +365,6 @@ class TestRequestWithPriority(_Http2Test):
assert resp.headers.get('priority_weight', None) == expected_priority[2]
-@requires_alpn
class TestPriority(_Http2Test):
@classmethod
@@ -453,7 +449,6 @@ class TestPriority(_Http2Test):
assert self.priority_data == expected_priority
-@requires_alpn
class TestStreamResetFromServer(_Http2Test):
@classmethod
@@ -504,7 +499,6 @@ class TestStreamResetFromServer(_Http2Test):
assert self.master.state.flows[0].response is None
-@requires_alpn
class TestBodySizeLimit(_Http2Test):
@classmethod
@@ -554,7 +548,6 @@ class TestBodySizeLimit(_Http2Test):
assert len(self.master.state.flows) == 0
-@requires_alpn
class TestPushPromise(_Http2Test):
@classmethod
@@ -723,7 +716,6 @@ class TestPushPromise(_Http2Test):
# the other two bodies might not be transmitted before the reset
-@requires_alpn
class TestConnectionLost(_Http2Test):
@classmethod
@@ -765,7 +757,6 @@ class TestConnectionLost(_Http2Test):
assert self.master.state.flows[0].response is None
-@requires_alpn
class TestMaxConcurrentStreams(_Http2Test):
@classmethod
@@ -826,7 +817,6 @@ class TestMaxConcurrentStreams(_Http2Test):
assert b"Stream-ID " in flow.response.content
-@requires_alpn
class TestConnectionTerminated(_Http2Test):
@classmethod
@@ -867,7 +857,6 @@ class TestConnectionTerminated(_Http2Test):
assert connection_terminated_event.additional_data == b'foobar'
-@requires_alpn
class TestRequestStreaming(_Http2Test):
@classmethod
@@ -926,7 +915,6 @@ class TestRequestStreaming(_Http2Test):
assert connection_terminated_event is None
-@requires_alpn
class TestResponseStreaming(_Http2Test):
@classmethod
diff --git a/test/mitmproxy/utils/test_version_check.py b/test/mitmproxy/utils/test_version_check.py
deleted file mode 100644
index d7929378..00000000
--- a/test/mitmproxy/utils/test_version_check.py
+++ /dev/null
@@ -1,25 +0,0 @@
-import io
-from unittest import mock
-from mitmproxy.utils import version_check
-
-
-@mock.patch("sys.exit")
-def test_check_pyopenssl_version(sexit):
- fp = io.StringIO()
- version_check.check_pyopenssl_version(fp=fp)
- assert not fp.getvalue()
- assert not sexit.called
-
- version_check.check_pyopenssl_version((9999,), fp=fp)
- assert "outdated" in fp.getvalue()
- assert sexit.called
-
-
-@mock.patch("sys.exit")
-@mock.patch("OpenSSL.__version__")
-def test_unparseable_pyopenssl_version(version, sexit):
- version.split.return_value = ["foo", "bar"]
- fp = io.StringIO()
- version_check.check_pyopenssl_version(fp=fp)
- assert "Cannot parse" in fp.getvalue()
- assert not sexit.called
diff --git a/test/pathod/protocols/test_http2.py b/test/pathod/protocols/test_http2.py
index c16a6d40..b1eebc73 100644
--- a/test/pathod/protocols/test_http2.py
+++ b/test/pathod/protocols/test_http2.py
@@ -11,8 +11,6 @@ from ...mitmproxy.net import tservers as net_tservers
from pathod.protocols.http2 import HTTP2StateProtocol, TCPHandler
-from ...conftest import requires_alpn
-
class TestTCPHandlerWrapper:
def test_wrapped(self):
@@ -68,7 +66,6 @@ class TestProtocol:
assert mock_server_method.called
-@requires_alpn
class TestCheckALPNMatch(net_tservers.ServerTestBase):
handler = EchoHandler
ssl = dict(
@@ -83,7 +80,6 @@ class TestCheckALPNMatch(net_tservers.ServerTestBase):
assert protocol.check_alpn()
-@requires_alpn
class TestCheckALPNMismatch(net_tservers.ServerTestBase):
handler = EchoHandler
ssl = dict(
diff --git a/test/pathod/test_pathoc.py b/test/pathod/test_pathoc.py
index 2dd29e20..4b50e2a7 100644
--- a/test/pathod/test_pathoc.py
+++ b/test/pathod/test_pathoc.py
@@ -11,7 +11,6 @@ from pathod.protocols.http2 import HTTP2StateProtocol
from mitmproxy.test import tutils
from . import tservers
-from ..conftest import requires_alpn
def test_response():
@@ -216,7 +215,6 @@ class TestDaemonHTTP2(PathocTestDaemon):
ssl = True
explain = False
- @requires_alpn
def test_http2(self):
c = pathoc.Pathoc(
("127.0.0.1", self.d.port),
@@ -231,7 +229,6 @@ class TestDaemonHTTP2(PathocTestDaemon):
)
assert c.protocol == http1
- @requires_alpn
def test_http2_alpn(self):
c = pathoc.Pathoc(
("127.0.0.1", self.d.port),
@@ -248,7 +245,6 @@ class TestDaemonHTTP2(PathocTestDaemon):
_, kwargs = c.convert_to_ssl.call_args
assert set(kwargs['alpn_protos']) == set([b'http/1.1', b'h2'])
- @requires_alpn
def test_request(self):
c = pathoc.Pathoc(
("127.0.0.1", self.d.port),
@@ -259,14 +255,3 @@ class TestDaemonHTTP2(PathocTestDaemon):
with c.connect():
resp = c.request("get:/p/200")
assert resp.status_code == 200
-
- def test_failing_request(self, disable_alpn):
- c = pathoc.Pathoc(
- ("127.0.0.1", self.d.port),
- fp=None,
- ssl=True,
- use_http2=True,
- )
- with pytest.raises(NotImplementedError):
- with c.connect():
- c.request("get:/p/200")
diff --git a/test/pathod/test_pathod.py b/test/pathod/test_pathod.py
index 88480a59..5f191c0d 100644
--- a/test/pathod/test_pathod.py
+++ b/test/pathod/test_pathod.py
@@ -8,7 +8,6 @@ from mitmproxy import exceptions
from mitmproxy.test import tutils
from . import tservers
-from ..conftest import requires_alpn
class TestPathod:
@@ -257,11 +256,6 @@ class TestHTTP2(tservers.DaemonTests):
ssl = True
nohang = True
- @requires_alpn
def test_http2(self):
r, _ = self.pathoc(["GET:/"], ssl=True, use_http2=True)
assert r[0].status_code == 800
-
- def test_no_http2(self, disable_alpn):
- with pytest.raises(NotImplementedError):
- r, _ = self.pathoc(["GET:/"], ssl=True, use_http2=True)