aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2019-11-15 18:10:42 +0100
committerMaximilian Hils <git@maximilianhils.com>2019-11-15 18:10:42 +0100
commit0873566ff05c02be063f3aa15adecb725342119c (patch)
treea6dcddf0f0c08c9ff9cdd89e1f95196af2ff5a6a /test
parentd852f292c9a45de7f45cc8537f2aef217259017e (diff)
parentfbbbbb678e77e3cff5ab35b1fd55e85e875ed3f5 (diff)
downloadmitmproxy-0873566ff05c02be063f3aa15adecb725342119c.tar.gz
mitmproxy-0873566ff05c02be063f3aa15adecb725342119c.tar.bz2
mitmproxy-0873566ff05c02be063f3aa15adecb725342119c.zip
Merge remote-tracking branch 'origin/master' into pr-3448
Diffstat (limited to 'test')
-rw-r--r--test/full_coverage_plugin.py12
-rwxr-xr-xtest/individual_coverage.py12
-rw-r--r--test/mitmproxy/addons/onboardingapp/__init__.py0
-rw-r--r--test/mitmproxy/addons/onboardingapp/test_app.py1
-rw-r--r--test/mitmproxy/addons/test_export.py24
-rw-r--r--test/mitmproxy/addons/test_view.py2
-rw-r--r--test/mitmproxy/data/pf016
-rw-r--r--test/mitmproxy/net/http/test_encoding.py1
-rw-r--r--test/mitmproxy/net/http/test_response.py2
-rw-r--r--test/mitmproxy/net/http/test_url.py16
-rw-r--r--test/mitmproxy/net/test_tls.py8
-rw-r--r--test/mitmproxy/platform/test_pf.py5
-rw-r--r--test/mitmproxy/proxy/test_config.py9
-rw-r--r--test/mitmproxy/proxy/test_server.py51
-rw-r--r--test/mitmproxy/script/test_concurrent.py26
-rw-r--r--test/mitmproxy/test_certs.py20
-rw-r--r--test/mitmproxy/test_flowfilter.py23
-rw-r--r--test/mitmproxy/test_proxy.py6
-rw-r--r--test/mitmproxy/utils/test_human.py1
19 files changed, 165 insertions, 60 deletions
diff --git a/test/full_coverage_plugin.py b/test/full_coverage_plugin.py
index ec30a9f9..ab1206ea 100644
--- a/test/full_coverage_plugin.py
+++ b/test/full_coverage_plugin.py
@@ -31,8 +31,8 @@ def pytest_configure(config):
global no_full_cov
enable_coverage = (
- len(config.getoption('file_or_dir')) == 0 and
- len(config.getoption('full_cov')) > 0 and
+ config.getoption('file_or_dir') and len(config.getoption('file_or_dir')) == 0 and
+ config.getoption('full_cov') and len(config.getoption('full_cov')) > 0 and
config.pluginmanager.getplugin("_cov") is not None and
config.pluginmanager.getplugin("_cov").cov_controller is not None and
config.pluginmanager.getplugin("_cov").cov_controller.cov is not None
@@ -55,7 +55,7 @@ def pytest_runtestloop(session):
yield
return
- cov = pytest.config.pluginmanager.getplugin("_cov").cov_controller.cov
+ cov = session.config.pluginmanager.getplugin("_cov").cov_controller.cov
if os.name == 'nt':
cov.exclude('pragma: windows no cover')
@@ -68,7 +68,7 @@ def pytest_runtestloop(session):
yield
- coverage_values = dict([(name, 0) for name in pytest.config.option.full_cov])
+ coverage_values = dict([(name, 0) for name in session.config.option.full_cov])
prefix = os.getcwd()
@@ -92,7 +92,7 @@ def pytest_runtestloop(session):
coverage_passed = False
-def pytest_terminal_summary(terminalreporter, exitstatus):
+def pytest_terminal_summary(terminalreporter, exitstatus, config):
global enable_coverage
global coverage_values
global coverage_passed
@@ -119,7 +119,7 @@ def pytest_terminal_summary(terminalreporter, exitstatus):
terminalreporter.write(msg, **markup)
else:
msg = 'SUCCESS: Full test coverage reached in modules and files:\n'
- msg += '{}\n\n'.format('\n'.join(pytest.config.option.full_cov))
+ msg += '{}\n\n'.format('\n'.join(config.option.full_cov))
terminalreporter.write(msg, green=True)
msg = '\nExcluded files:\n'
diff --git a/test/individual_coverage.py b/test/individual_coverage.py
index 097b290f..54180eac 100755
--- a/test/individual_coverage.py
+++ b/test/individual_coverage.py
@@ -19,29 +19,29 @@ def run_tests(src, test, fail):
e = pytest.main([
'-qq',
'--disable-pytest-warnings',
- '--no-faulthandler',
'--cov', src.replace('.py', '').replace('/', '.'),
'--cov-fail-under', '100',
'--cov-report', 'term-missing:skip-covered',
+ '-o', 'faulthandler_timeout=0',
test
])
if e == 0:
if fail:
- print("UNEXPECTED SUCCESS:", src, "Please remove this file from setup.cfg tool:individual_coverage/exclude.")
+ print("FAIL DUE TO UNEXPECTED SUCCESS:", src, "Please remove this file from setup.cfg tool:individual_coverage/exclude.")
e = 42
else:
- print("SUCCESS: ", src)
+ print("Success:", src)
else:
if fail:
- print("IGNORING FAIL: ", src)
+ print("Ignoring allowed fail:", src)
e = 0
else:
cov = [l for l in stdout.getvalue().split("\n") if (src in l) or ("was never imported" in l)]
if len(cov) == 1:
- print("FAIL: ", cov[0])
+ print("FAIL:", cov[0])
else:
- print("FAIL: ", src, test, stdout.getvalue(), stdout.getvalue())
+ print("FAIL:", src, test, stdout.getvalue(), stdout.getvalue())
print(stderr.getvalue())
print(stdout.getvalue())
diff --git a/test/mitmproxy/addons/onboardingapp/__init__.py b/test/mitmproxy/addons/onboardingapp/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/test/mitmproxy/addons/onboardingapp/__init__.py
+++ /dev/null
diff --git a/test/mitmproxy/addons/onboardingapp/test_app.py b/test/mitmproxy/addons/onboardingapp/test_app.py
deleted file mode 100644
index 777ab4dd..00000000
--- a/test/mitmproxy/addons/onboardingapp/test_app.py
+++ /dev/null
@@ -1 +0,0 @@
-# TODO: write tests
diff --git a/test/mitmproxy/addons/test_export.py b/test/mitmproxy/addons/test_export.py
index 67d0fc99..a4c10c1a 100644
--- a/test/mitmproxy/addons/test_export.py
+++ b/test/mitmproxy/addons/test_export.py
@@ -15,29 +15,23 @@ from unittest import mock
@pytest.fixture
def get_request():
return tflow.tflow(
- req=tutils.treq(
- method=b'GET',
- content=b'',
- path=b"/path?a=foo&a=bar&b=baz"
- )
- )
+ req=tutils.treq(method=b'GET', content=b'', path=b"/path?a=foo&a=bar&b=baz"))
@pytest.fixture
def post_request():
return tflow.tflow(
- req=tutils.treq(
- method=b'POST',
- headers=(),
- content=bytes(range(256))
- )
- )
+ req=tutils.treq(method=b'POST', headers=(), content=bytes(range(256))))
@pytest.fixture
def patch_request():
return tflow.tflow(
- req=tutils.treq(method=b'PATCH', path=b"/path?query=param")
+ req=tutils.treq(
+ method=b'PATCH',
+ content=b'content',
+ path=b"/path?query=param"
+ )
)
@@ -48,7 +42,7 @@ def tcp_flow():
class TestExportCurlCommand:
def test_get(self, get_request):
- result = """curl -H header:qvalue -H content-length:0 'http://address:22/path?a=foo&a=bar&b=baz'"""
+ result = """curl -H header:qvalue 'http://address:22/path?a=foo&a=bar&b=baz'"""
assert export.curl_command(get_request) == result
def test_post(self, post_request):
@@ -85,7 +79,7 @@ class TestExportCurlCommand:
class TestExportHttpieCommand:
def test_get(self, get_request):
- result = """http GET 'http://address:22/path?a=foo&a=bar&b=baz' header:qvalue content-length:0"""
+ result = """http GET 'http://address:22/path?a=foo&a=bar&b=baz' header:qvalue"""
assert export.httpie_command(get_request) == result
def test_post(self, post_request):
diff --git a/test/mitmproxy/addons/test_view.py b/test/mitmproxy/addons/test_view.py
index 976c14b7..f5088a68 100644
--- a/test/mitmproxy/addons/test_view.py
+++ b/test/mitmproxy/addons/test_view.py
@@ -471,7 +471,7 @@ def test_focus():
v = view.View()
v.add([tft()])
f = view.Focus(v)
- assert f.index is 0
+ assert f.index == 0
assert f.flow is v[0]
# Start empty
diff --git a/test/mitmproxy/data/pf01 b/test/mitmproxy/data/pf01
index 3139a289..019a6b76 100644
--- a/test/mitmproxy/data/pf01
+++ b/test/mitmproxy/data/pf01
@@ -1,4 +1,10 @@
No ALTQ support in kernel
ALTQ related functions disabled
+ALL tcp 192.168.1.111:40001 -> 5.5.5.6:80 FIN_WAIT_2:FIN_WAIT_2
ALL tcp 127.0.0.1:8080 <- 5.5.5.6:80 <- 192.168.1.111:40001 FIN_WAIT_2:FIN_WAIT_2
+ALL tcp 192.168.1.111:40000 -> 5.5.5.5:80 ESTABLISHED:ESTABLISHED
ALL tcp 127.0.0.1:8080 <- 5.5.5.5:80 <- 192.168.1.111:40000 ESTABLISHED:ESTABLISHED
+ALL tcp 2a01:e35:8bae:50f0:396f:e6c7:f4f1:f3db[40002] -> 2a03:2880:f21f:c5:face:b00c::167[443] ESTABLISHED:ESTABLISHED
+ALL tcp ::1[8080] <- 2a03:2880:f21f:c5:face:b00c::167[443] <- 2a01:e35:8bae:50f0:396f:e6c7:f4f1:f3db[40002] ESTABLISHED:ESTABLISHED
+ALL tcp 2a01:e35:8bae:50f0:396f:e6c7:f4f1:f3db[40003] -> 2a03:2880:f21f:c5:face:b00c::167[443] FIN_WAIT_2:FIN_WAIT_2
+ALL tcp ::1[6970] <- 2a03:2880:f21f:c5:face:b00c::167[443] <- 2a01:e35:8bae:50f0:396f:e6c7:f4f1:f3db[40003] FIN_WAIT_2:FIN_WAIT_2 \ No newline at end of file
diff --git a/test/mitmproxy/net/http/test_encoding.py b/test/mitmproxy/net/http/test_encoding.py
index 8dac12cb..7f768f39 100644
--- a/test/mitmproxy/net/http/test_encoding.py
+++ b/test/mitmproxy/net/http/test_encoding.py
@@ -19,6 +19,7 @@ def test_identity(encoder):
'gzip',
'br',
'deflate',
+ 'zstd',
])
def test_encoders(encoder):
"""
diff --git a/test/mitmproxy/net/http/test_response.py b/test/mitmproxy/net/http/test_response.py
index f3470384..27c16be6 100644
--- a/test/mitmproxy/net/http/test_response.py
+++ b/test/mitmproxy/net/http/test_response.py
@@ -148,7 +148,7 @@ class TestResponseUtils:
def test_refresh(self):
r = tresp()
n = time.time()
- r.headers["date"] = email.utils.formatdate(n)
+ r.headers["date"] = email.utils.formatdate(n, usegmt=True)
pre = r.headers["date"]
r.refresh(946681202)
assert pre == r.headers["date"]
diff --git a/test/mitmproxy/net/http/test_url.py b/test/mitmproxy/net/http/test_url.py
index ecf8e896..48277859 100644
--- a/test/mitmproxy/net/http/test_url.py
+++ b/test/mitmproxy/net/http/test_url.py
@@ -49,6 +49,17 @@ def test_parse():
url.parse('http://lo[calhost')
+def test_ascii_check():
+
+ test_url = "https://xyz.tax-edu.net?flag=selectCourse&lc_id=42825&lc_name=茅莽莽猫氓猫氓".encode()
+ scheme, host, port, full_path = url.parse(test_url)
+ assert scheme == b'https'
+ assert host == b'xyz.tax-edu.net'
+ assert port == 443
+ assert full_path == b'/?flag%3DselectCourse%26lc_id%3D42825%26lc_name%3D%E8%8C%85%E8%8E%BD%E8%8E' \
+ b'%BD%E7%8C%AB%E6%B0%93%E7%8C%AB%E6%B0%93'
+
+
@pytest.mark.skipif(sys.version_info < (3, 6), reason='requires Python 3.6 or higher')
def test_parse_port_range():
# Port out of range
@@ -61,6 +72,7 @@ def test_unparse():
assert url.unparse("http", "foo.com", 80, "/bar") == "http://foo.com/bar"
assert url.unparse("https", "foo.com", 80, "") == "https://foo.com:80"
assert url.unparse("https", "foo.com", 443, "") == "https://foo.com"
+ assert url.unparse("https", "foo.com", 443, "*") == "https://foo.com"
# We ignore the byte 126: '~' because of an incompatibility in Python 3.6 and 3.7
@@ -131,3 +143,7 @@ def test_unquote():
assert url.unquote("foo") == "foo"
assert url.unquote("foo%20bar") == "foo bar"
assert url.unquote(surrogates_quoted) == surrogates
+
+
+def test_hostport():
+ assert url.hostport(b"https", b"foo.com", 8080) == b"foo.com:8080"
diff --git a/test/mitmproxy/net/test_tls.py b/test/mitmproxy/net/test_tls.py
index 489bf89f..c4e76bc6 100644
--- a/test/mitmproxy/net/test_tls.py
+++ b/test/mitmproxy/net/test_tls.py
@@ -87,13 +87,13 @@ def test_get_client_hello():
rfile = io.BufferedReader(io.BytesIO(
FULL_CLIENT_HELLO_NO_EXTENSIONS[:30]
))
- with pytest.raises(exceptions.TlsProtocolException, message="Unexpected EOF"):
+ with pytest.raises(exceptions.TlsProtocolException, match="Unexpected EOF"):
tls.get_client_hello(rfile)
rfile = io.BufferedReader(io.BytesIO(
b"GET /"
))
- with pytest.raises(exceptions.TlsProtocolException, message="Expected TLS record"):
+ with pytest.raises(exceptions.TlsProtocolException, match="Expected TLS record"):
tls.get_client_hello(rfile)
@@ -116,7 +116,7 @@ class TestClientHello:
)
c = tls.ClientHello(data)
assert repr(c)
- assert c.sni == 'example.com'
+ assert c.sni == b'example.com'
assert c.cipher_suites == [
49195, 49199, 49196, 49200, 52393, 52392, 52244, 52243, 49161,
49171, 49162, 49172, 156, 157, 47, 53, 10
@@ -153,5 +153,5 @@ class TestClientHello:
b"\x01\x00\x00\x03" + # handshake header
b"foo"
))
- with pytest.raises(exceptions.TlsProtocolException, message='Cannot parse Client Hello'):
+ with pytest.raises(exceptions.TlsProtocolException, match='Cannot parse Client Hello'):
tls.ClientHello.from_file(rfile)
diff --git a/test/mitmproxy/platform/test_pf.py b/test/mitmproxy/platform/test_pf.py
index 9795a2db..4a7dfe75 100644
--- a/test/mitmproxy/platform/test_pf.py
+++ b/test/mitmproxy/platform/test_pf.py
@@ -19,3 +19,8 @@ class TestLookup:
pf.lookup("192.168.1.112", 40000, d)
with pytest.raises(Exception, match="Could not resolve original destination"):
pf.lookup("192.168.1.111", 40001, d)
+ assert pf.lookup("2a01:e35:8bae:50f0:396f:e6c7:f4f1:f3db", 40002, d) == ("2a03:2880:f21f:c5:face:b00c::167", 443)
+ with pytest.raises(Exception, match="Could not resolve original destination"):
+ pf.lookup("2a01:e35:8bae:50f0:396f:e6c7:f4f1:f3db", 40003, d)
+ with pytest.raises(Exception, match="Could not resolve original destination"):
+ pf.lookup("2a01:e35:face:face:face:face:face:face", 40003, d)
diff --git a/test/mitmproxy/proxy/test_config.py b/test/mitmproxy/proxy/test_config.py
index 1da031c6..1319d1a9 100644
--- a/test/mitmproxy/proxy/test_config.py
+++ b/test/mitmproxy/proxy/test_config.py
@@ -17,3 +17,12 @@ class TestProxyConfig:
opts.certs = [tdata.path("mitmproxy/data/dumpfile-011")]
with pytest.raises(exceptions.OptionsError, match="Invalid certificate format"):
ProxyConfig(opts)
+
+ def test_cannot_set_both_allow_and_filter_options(self):
+ opts = options.Options()
+ opts.ignore_hosts = ["foo"]
+ opts.allow_hosts = ["bar"]
+ with pytest.raises(exceptions.OptionsError, match="--ignore-hosts and --allow-hosts are "
+ "mutually exclusive; please choose "
+ "one."):
+ ProxyConfig(opts)
diff --git a/test/mitmproxy/proxy/test_server.py b/test/mitmproxy/proxy/test_server.py
index 01ab068d..b5852d60 100644
--- a/test/mitmproxy/proxy/test_server.py
+++ b/test/mitmproxy/proxy/test_server.py
@@ -78,6 +78,16 @@ class TcpMixin:
self.options.ignore_hosts = self._ignore_backup
del self._ignore_backup
+ def _allow_on(self):
+ assert not hasattr(self, "_allow_backup")
+ self._allow_backup = self.options.allow_hosts
+ self.options.allow_hosts = ["(127.0.0.1|None):\\d+"] + self.options.allow_hosts
+
+ def _allow_off(self):
+ assert hasattr(self, "_allow_backup")
+ self.options.allow_hosts = self._allow_backup
+ del self._allow_backup
+
def test_ignore(self):
n = self.pathod("304")
self._ignore_on()
@@ -111,6 +121,40 @@ class TcpMixin:
self._ignore_off()
+ def test_allow(self):
+ n = self.pathod("304")
+ self._allow_on()
+ i = self.pathod("305")
+ i2 = self.pathod("306")
+ self._allow_off()
+
+ assert n.status_code == 304
+ assert i.status_code == 305
+ assert i2.status_code == 306
+
+ assert any(f.response.status_code == 304 for f in self.master.state.flows)
+ assert any(f.response.status_code == 305 for f in self.master.state.flows)
+ assert any(f.response.status_code == 306 for f in self.master.state.flows)
+
+ # Test that we get the original SSL cert
+ if self.ssl:
+ i_cert = certs.Cert(i.sslinfo.certchain[0])
+ i2_cert = certs.Cert(i2.sslinfo.certchain[0])
+ n_cert = certs.Cert(n.sslinfo.certchain[0])
+
+ assert i_cert == i2_cert
+ assert i_cert != n_cert
+
+ # Test Non-HTTP traffic
+ spec = "200:i0,@100:d0" # this results in just 100 random bytes
+ # mitmproxy responds with bad gateway
+ assert self.pathod(spec).status_code == 502
+ self._allow_on()
+
+ self.pathod(spec) # pathoc parses answer as HTTP
+
+ self._allow_off()
+
def _tcpproxy_on(self):
assert not hasattr(self, "_tcpproxy_backup")
self._tcpproxy_backup = self.options.tcp_hosts
@@ -852,10 +896,12 @@ class TestUpstreamProxySSL(
def _host_pattern_on(self, attr):
"""
- Updates config.check_tcp or check_ignore, depending on attr.
+ Updates config.check_tcp or check_filter, depending on attr.
"""
assert not hasattr(self, "_ignore_%s_backup" % attr)
backup = []
+ handle = attr
+ attr = "filter" if attr in ["allow", "ignore"] else attr
for proxy in self.chain:
old_matcher = getattr(
proxy.tmaster.server.config,
@@ -865,12 +911,13 @@ class TestUpstreamProxySSL(
setattr(
proxy.tmaster.server.config,
"check_%s" % attr,
- HostMatcher([".+:%s" % self.server.port] + old_matcher.patterns)
+ HostMatcher(handle, [".+:%s" % self.server.port] + old_matcher.patterns)
)
setattr(self, "_ignore_%s_backup" % attr, backup)
def _host_pattern_off(self, attr):
+ attr = "filter" if attr in ["allow", "ignore"] else attr
backup = getattr(self, "_ignore_%s_backup" % attr)
for proxy in reversed(self.chain):
setattr(
diff --git a/test/mitmproxy/script/test_concurrent.py b/test/mitmproxy/script/test_concurrent.py
index 3ec58760..70d41511 100644
--- a/test/mitmproxy/script/test_concurrent.py
+++ b/test/mitmproxy/script/test_concurrent.py
@@ -43,17 +43,17 @@ class TestConcurrent(tservers.MasterTest):
assert await tctx.master.await_log("decorator not supported")
def test_concurrent_class(self, tdata):
- with taddons.context() as tctx:
- sc = tctx.script(
- tdata.path(
- "mitmproxy/data/addonscripts/concurrent_decorator_class.py"
- )
+ with taddons.context() as tctx:
+ sc = tctx.script(
+ tdata.path(
+ "mitmproxy/data/addonscripts/concurrent_decorator_class.py"
)
- f1, f2 = tflow.tflow(), tflow.tflow()
- tctx.cycle(sc, f1)
- tctx.cycle(sc, f2)
- start = time.time()
- while time.time() - start < 5:
- if f1.reply.state == f2.reply.state == "committed":
- return
- raise ValueError("Script never acked")
+ )
+ f1, f2 = tflow.tflow(), tflow.tflow()
+ tctx.cycle(sc, f1)
+ tctx.cycle(sc, f2)
+ start = time.time()
+ while time.time() - start < 5:
+ if f1.reply.state == f2.reply.state == "committed":
+ return
+ raise ValueError("Script never acked")
diff --git a/test/mitmproxy/test_certs.py b/test/mitmproxy/test_certs.py
index b8ad1d36..37604f54 100644
--- a/test/mitmproxy/test_certs.py
+++ b/test/mitmproxy/test_certs.py
@@ -35,20 +35,20 @@ from ..conftest import skip_windows
class TestCertStore:
def test_create_explicit(self, tmpdir):
- ca = certs.CertStore.from_store(str(tmpdir), "test")
+ ca = certs.CertStore.from_store(str(tmpdir), "test", 2048)
assert ca.get_cert(b"foo", [])
- ca2 = certs.CertStore.from_store(str(tmpdir), "test")
+ ca2 = certs.CertStore.from_store(str(tmpdir), "test", 2048)
assert ca2.get_cert(b"foo", [])
assert ca.default_ca.get_serial_number() == ca2.default_ca.get_serial_number()
def test_create_no_common_name(self, tmpdir):
- ca = certs.CertStore.from_store(str(tmpdir), "test")
+ ca = certs.CertStore.from_store(str(tmpdir), "test", 2048)
assert ca.get_cert(None, [])[0].cn is None
def test_create_tmp(self, tmpdir):
- ca = certs.CertStore.from_store(str(tmpdir), "test")
+ ca = certs.CertStore.from_store(str(tmpdir), "test", 2048)
assert ca.get_cert(b"foo.com", [])
assert ca.get_cert(b"foo.com", [])
assert ca.get_cert(b"*.foo.com", [])
@@ -57,7 +57,7 @@ class TestCertStore:
assert r[1] == ca.default_privatekey
def test_sans(self, tmpdir):
- ca = certs.CertStore.from_store(str(tmpdir), "test")
+ ca = certs.CertStore.from_store(str(tmpdir), "test", 2048)
c1 = ca.get_cert(b"foo.com", [b"*.bar.com"])
ca.get_cert(b"foo.bar.com", [])
# assert c1 == c2
@@ -65,13 +65,13 @@ class TestCertStore:
assert not c1 == c3
def test_sans_change(self, tmpdir):
- ca = certs.CertStore.from_store(str(tmpdir), "test")
+ ca = certs.CertStore.from_store(str(tmpdir), "test", 2048)
ca.get_cert(b"foo.com", [b"*.bar.com"])
cert, key, chain_file = ca.get_cert(b"foo.bar.com", [b"*.baz.com"])
assert b"*.baz.com" in cert.altnames
def test_expire(self, tmpdir):
- ca = certs.CertStore.from_store(str(tmpdir), "test")
+ ca = certs.CertStore.from_store(str(tmpdir), "test", 2048)
ca.STORE_CAP = 3
ca.get_cert(b"one.com", [])
ca.get_cert(b"two.com", [])
@@ -95,8 +95,8 @@ class TestCertStore:
assert (b"four.com", ()) in ca.certs
def test_overrides(self, tmpdir):
- ca1 = certs.CertStore.from_store(str(tmpdir.join("ca1")), "test")
- ca2 = certs.CertStore.from_store(str(tmpdir.join("ca2")), "test")
+ ca1 = certs.CertStore.from_store(str(tmpdir.join("ca1")), "test", 2048)
+ ca2 = certs.CertStore.from_store(str(tmpdir.join("ca2")), "test", 2048)
assert not ca1.default_ca.get_serial_number() == ca2.default_ca.get_serial_number()
dc = ca2.get_cert(b"foo.com", [b"sans.example.com"])
@@ -124,7 +124,7 @@ class TestCertStore:
class TestDummyCert:
def test_with_ca(self, tmpdir):
- ca = certs.CertStore.from_store(str(tmpdir), "test")
+ ca = certs.CertStore.from_store(str(tmpdir), "test", 2048)
r = certs.dummy_cert(
ca.default_privatekey,
ca.default_ca,
diff --git a/test/mitmproxy/test_flowfilter.py b/test/mitmproxy/test_flowfilter.py
index 4eb37d81..d53cec7d 100644
--- a/test/mitmproxy/test_flowfilter.py
+++ b/test/mitmproxy/test_flowfilter.py
@@ -28,6 +28,9 @@ class TestParsing:
self._dump(p)
assert len(p.lst) == 2
+ def test_non_ascii(self):
+ assert flowfilter.parse("~s шгн")
+
def test_naked_url(self):
a = flowfilter.parse("foobar ~h rex")
assert a.lst[0].expr == "foobar"
@@ -173,10 +176,30 @@ class TestMatchingHTTPFlow:
assert not self.q("~bq message", q)
assert not self.q("~bq message", s)
+ s.response.text = 'яч' # Cyrillic
+ assert self.q("~bs яч", s)
+ s.response.text = '测试' # Chinese
+ assert self.q('~bs 测试', s)
+ s.response.text = 'ॐ' # Hindi
+ assert self.q('~bs ॐ', s)
+ s.response.text = 'لله' # Arabic
+ assert self.q('~bs لله', s)
+ s.response.text = 'θεός' # Greek
+ assert self.q('~bs θεός', s)
+ s.response.text = 'לוהים' # Hebrew
+ assert self.q('~bs לוהים', s)
+ s.response.text = '神' # Japanese
+ assert self.q('~bs 神', s)
+ s.response.text = '하나님' # Korean
+ assert self.q('~bs 하나님', s)
+ s.response.text = 'Äÿ' # Latin
+ assert self.q('~bs Äÿ', s)
+
assert not self.q("~bs nomatch", s)
assert not self.q("~bs content", q)
assert not self.q("~bs content", s)
assert not self.q("~bs message", q)
+ s.response.text = 'message'
assert self.q("~bs message", s)
def test_body(self):
diff --git a/test/mitmproxy/test_proxy.py b/test/mitmproxy/test_proxy.py
index 00086c4b..c8cf6c33 100644
--- a/test/mitmproxy/test_proxy.py
+++ b/test/mitmproxy/test_proxy.py
@@ -1,4 +1,5 @@
import argparse
+import platform
from unittest import mock
import pytest
@@ -52,8 +53,11 @@ class TestProcessProxyOptions:
class TestProxyServer:
@skip_windows
+ @pytest.mark.skipif(platform.mac_ver()[0].split('.')[:2] == ['10', '14'],
+ reason='Skipping due to macOS Mojave')
def test_err(self):
- # binding to 0.0.0.0:1 works without special permissions on Windows
+ # binding to 0.0.0.0:1 works without special permissions on Windows and
+ # macOS Mojave
conf = ProxyConfig(options.Options(listen_port=1))
with pytest.raises(Exception, match="Error starting proxy server"):
ProxyServer(conf)
diff --git a/test/mitmproxy/utils/test_human.py b/test/mitmproxy/utils/test_human.py
index faf35f72..6f8bf732 100644
--- a/test/mitmproxy/utils/test_human.py
+++ b/test/mitmproxy/utils/test_human.py
@@ -47,6 +47,7 @@ def test_pretty_duration():
assert human.pretty_duration(10000) == "10000s"
assert human.pretty_duration(1.123) == "1.12s"
assert human.pretty_duration(0.123) == "123ms"
+ assert human.pretty_duration(None) == ""
def test_format_address():