aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2017-04-30 13:41:53 +1200
committerAldo Cortesi <aldo@corte.si>2017-04-30 14:05:45 +1200
commit075d452a6d4e9f21ffd7b3293ec9270ee961917a (patch)
tree7084cb7c4575e81909bc7911442bb221c346252e /test
parent7ffb2c7981b76ed2e8c467d3db3141b013cccd5b (diff)
downloadmitmproxy-075d452a6d4e9f21ffd7b3293ec9270ee961917a.tar.gz
mitmproxy-075d452a6d4e9f21ffd7b3293ec9270ee961917a.tar.bz2
mitmproxy-075d452a6d4e9f21ffd7b3293ec9270ee961917a.zip
cut: more flexible cut specification based on attribute paths
Also support certificate types, which are converted to ASCII-encoded PEM format.
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_cut.py27
-rw-r--r--test/mitmproxy/test_connections.py2
2 files changed, 25 insertions, 4 deletions
diff --git a/test/mitmproxy/addons/test_cut.py b/test/mitmproxy/addons/test_cut.py
index 3012803d..b4c0f66b 100644
--- a/test/mitmproxy/addons/test_cut.py
+++ b/test/mitmproxy/addons/test_cut.py
@@ -2,8 +2,10 @@
from mitmproxy.addons import cut
from mitmproxy.addons import view
from mitmproxy import exceptions
+from mitmproxy import certs
from mitmproxy.test import taddons
from mitmproxy.test import tflow
+from mitmproxy.test import tutils
import pytest
@@ -27,11 +29,30 @@ def test_extract():
["s.content", b"message"],
["s.raw_content", b"message"],
["s.header[header-response]", "svalue"],
+
+ ["cc.address.port", "22"],
+ ["cc.address.host", "address"],
+ ["cc.tls_version", "TLSv1.2"],
+ ["cc.sni", "address"],
+ ["cc.ssl_established", "false"],
+
+ ["sc.address.port", "22"],
+ ["sc.address.host", "address"],
+ ["sc.ip_address.host", "192.168.0.1"],
+ ["sc.tls_version", "TLSv1.2"],
+ ["sc.sni", "address"],
+ ["sc.ssl_established", "false"],
]
for t in tests:
ret = cut.extract(t[0], tf)
if ret != t[1]:
- raise AssertionError("Expected %s, got %s", t[1], ret)
+ raise AssertionError("%s: Expected %s, got %s" % (t[0], t[1], ret))
+
+ with open(tutils.test_data.path("mitmproxy/net/data/text_cert"), "rb") as f:
+ d = f.read()
+ c1 = certs.SSLCert.from_pem(d)
+ tf.server_conn.cert = c1
+ assert "CERTIFICATE" in cut.extract("sc.cert", tf)
def test_parse_cutspec():
@@ -123,9 +144,9 @@ def test_cut():
assert c.cut("s.reason|@all") == [["OK"]]
assert c.cut("s.content|@all") == [[b"message"]]
assert c.cut("s.header[header-response]|@all") == [["svalue"]]
-
+ assert c.cut("moo") == [[""]]
with pytest.raises(exceptions.CommandError):
- assert c.cut("moo") == [["svalue"]]
+ assert c.cut("__dict__") == [[""]]
v = view.View()
c = cut.Cut()
diff --git a/test/mitmproxy/test_connections.py b/test/mitmproxy/test_connections.py
index 67a6552f..e320885d 100644
--- a/test/mitmproxy/test_connections.py
+++ b/test/mitmproxy/test_connections.py
@@ -99,7 +99,7 @@ class TestServerConnection:
c.alpn_proto_negotiated = b'h2'
assert 'address:22' in repr(c)
assert 'ALPN' in repr(c)
- assert 'TLS: foobar' in repr(c)
+ assert 'TLSv1.2: foobar' in repr(c)
c.sni = None
c.tls_established = True