aboutsummaryrefslogtreecommitdiffstats
path: root/test/mitmproxy/net/test_tcp.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/mitmproxy/net/test_tcp.py')
-rw-r--r--test/mitmproxy/net/test_tcp.py50
1 files changed, 18 insertions, 32 deletions
diff --git a/test/mitmproxy/net/test_tcp.py b/test/mitmproxy/net/test_tcp.py
index f0e8b776..9d521533 100644
--- a/test/mitmproxy/net/test_tcp.py
+++ b/test/mitmproxy/net/test_tcp.py
@@ -206,7 +206,7 @@ class TestInvalidTrustFile(tservers.ServerTestBase):
with pytest.raises(exceptions.TlsException):
c.convert_to_ssl(
sni="example.mitmproxy.org",
- verify_options=SSL.VERIFY_PEER,
+ verify=SSL.VERIFY_PEER,
ca_pemfile=tutils.test_data.path("mitmproxy/net/data/verificationcerts/generate.py")
)
@@ -236,7 +236,7 @@ class TestSSLUpstreamCertVerificationWBadServerCert(tservers.ServerTestBase):
def test_mode_none_should_pass(self):
c = tcp.TCPClient(("127.0.0.1", self.port))
with c.connect():
- c.convert_to_ssl(verify_options=SSL.VERIFY_NONE)
+ c.convert_to_ssl(verify=SSL.VERIFY_NONE)
# Verification errors should be saved even if connection isn't aborted
assert c.ssl_verification_error
@@ -252,7 +252,7 @@ class TestSSLUpstreamCertVerificationWBadServerCert(tservers.ServerTestBase):
with pytest.raises(exceptions.InvalidCertificateException):
c.convert_to_ssl(
sni="example.mitmproxy.org",
- verify_options=SSL.VERIFY_PEER,
+ verify=SSL.VERIFY_PEER,
ca_pemfile=tutils.test_data.path("mitmproxy/net/data/verificationcerts/trusted-root.crt")
)
@@ -276,17 +276,27 @@ class TestSSLUpstreamCertVerificationWBadHostname(tservers.ServerTestBase):
with c.connect():
with pytest.raises(exceptions.TlsException):
c.convert_to_ssl(
- verify_options=SSL.VERIFY_PEER,
+ verify=SSL.VERIFY_PEER,
ca_pemfile=tutils.test_data.path("mitmproxy/net/data/verificationcerts/trusted-root.crt")
)
+ def test_mode_none_should_pass_without_sni(self):
+ c = tcp.TCPClient(("127.0.0.1", self.port))
+ with c.connect():
+ c.convert_to_ssl(
+ verify=SSL.VERIFY_NONE,
+ ca_path=tutils.test_data.path("mitmproxy/net/data/verificationcerts/")
+ )
+
+ assert "'no-hostname' doesn't match" in str(c.ssl_verification_error)
+
def test_should_fail(self):
c = tcp.TCPClient(("127.0.0.1", self.port))
with c.connect():
with pytest.raises(exceptions.InvalidCertificateException):
c.convert_to_ssl(
sni="mitmproxy.org",
- verify_options=SSL.VERIFY_PEER,
+ verify=SSL.VERIFY_PEER,
ca_pemfile=tutils.test_data.path("mitmproxy/net/data/verificationcerts/trusted-root.crt")
)
assert c.ssl_verification_error
@@ -305,7 +315,7 @@ class TestSSLUpstreamCertVerificationWValidCertChain(tservers.ServerTestBase):
with c.connect():
c.convert_to_ssl(
sni="example.mitmproxy.org",
- verify_options=SSL.VERIFY_PEER,
+ verify=SSL.VERIFY_PEER,
ca_pemfile=tutils.test_data.path("mitmproxy/net/data/verificationcerts/trusted-root.crt")
)
@@ -321,7 +331,7 @@ class TestSSLUpstreamCertVerificationWValidCertChain(tservers.ServerTestBase):
with c.connect():
c.convert_to_ssl(
sni="example.mitmproxy.org",
- verify_options=SSL.VERIFY_PEER,
+ verify=SSL.VERIFY_PEER,
ca_path=tutils.test_data.path("mitmproxy/net/data/verificationcerts/")
)
@@ -774,10 +784,7 @@ class TestPeek(tservers.ServerTestBase):
c.close()
with pytest.raises(exceptions.NetlibException):
- if c.rfile.peek(1) == b"":
- # Workaround for Python 2 on Unix:
- # Peeking a closed connection does not raise an exception here.
- raise exceptions.NetlibException()
+ c.rfile.peek(1)
class TestPeekSSL(TestPeek):
@@ -787,24 +794,3 @@ class TestPeekSSL(TestPeek):
with c.connect() as conn:
c.convert_to_ssl()
return conn.pop()
-
-
-class TestSSLInvalid(tservers.ServerTestBase):
- handler = EchoHandler
- ssl = True
-
- def test_invalid_ssl_method_should_fail(self):
- fake_ssl_method = 100500
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- with pytest.raises(exceptions.TlsException):
- c.convert_to_ssl(method=fake_ssl_method)
-
- def test_alpn_error(self):
- c = tcp.TCPClient(("127.0.0.1", self.port))
- with c.connect():
- 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")