From cc33f40f29dcd250e2dc3df77412fdec91f2d4eb Mon Sep 17 00:00:00 2001 From: Chih-Hsuan Yen Date: Sat, 29 Dec 2018 21:24:46 +0800 Subject: Fix a failing test on macOS Mojave --- test/mitmproxy/test_proxy.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test') 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) -- cgit v1.2.3 From cec8c67465206caa5b4040c5f34050c9ef06b687 Mon Sep 17 00:00:00 2001 From: rjt-gupta Date: Sun, 3 Feb 2019 00:49:53 +0530 Subject: non ascii fix and tests --- test/mitmproxy/net/http/test_url.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') 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" -- cgit v1.2.3 From 6e153b2c017be294a23e78469367346d0f9250e2 Mon Sep 17 00:00:00 2001 From: rjt-gupta Date: Sun, 24 Feb 2019 01:45:45 +0530 Subject: filter unicode fix --- test/mitmproxy/test_flowfilter.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test') 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): -- cgit v1.2.3 From a8489466c1b10af6a7510759362b9b930e6852f0 Mon Sep 17 00:00:00 2001 From: Anthony Biondo Date: Tue, 16 Apr 2019 22:11:27 -0400 Subject: update formatdate for cookies and tests to use GMT formatting --- test/mitmproxy/net/http/test_response.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') 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"] -- cgit v1.2.3 From 8d0c800d15039ff0a880051f4271acf668904e12 Mon Sep 17 00:00:00 2001 From: Pierre Gordon Date: Fri, 19 Apr 2019 12:39:53 -0500 Subject: Add --allow_hosts option Closes #3295 --- test/mitmproxy/proxy/test_server.py | 51 +++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'test') 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( -- cgit v1.2.3 From 1b3f86e70938d43b5d1f702ef6ca18ecfa32c636 Mon Sep 17 00:00:00 2001 From: Pierre Gordon Date: Fri, 19 Apr 2019 13:10:39 -0500 Subject: Verify ignore_hosts & allow_hosts are mutually exclusive --- test/mitmproxy/proxy/test_config.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test') 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) -- cgit v1.2.3 From dd3589ce345bcabe51563e1e1ac83797353baf8c Mon Sep 17 00:00:00 2001 From: Tero Saaristo Date: Thu, 5 Sep 2019 17:52:04 +0300 Subject: encoding: add support for zstd (zstandard) Handles zstandard-compressed bodies labeled as zstd. --- test/mitmproxy/net/http/test_encoding.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test') 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): """ -- cgit v1.2.3 From e77f375186403cee05dc66c069ed1155059b2d63 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 5 Sep 2019 22:08:18 +0200 Subject: lint --- test/mitmproxy/addons/test_view.py | 2 +- test/mitmproxy/script/test_concurrent.py | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'test') 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/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") -- cgit v1.2.3 From 53cb5bf40f40cef2c5b4e05e7be42949146a3f58 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sat, 28 Sep 2019 16:53:24 +0200 Subject: bump deps --- test/full_coverage_plugin.py | 8 ++++---- test/mitmproxy/net/test_tls.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/full_coverage_plugin.py b/test/full_coverage_plugin.py index ec30a9f9..f99dc7ab 100644 --- a/test/full_coverage_plugin.py +++ b/test/full_coverage_plugin.py @@ -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/mitmproxy/net/test_tls.py b/test/mitmproxy/net/test_tls.py index 489bf89f..68e67dbe 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) @@ -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) -- cgit v1.2.3 From ace79afefc7b9d8055a043a3a80d4cb8cee8a59e Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sat, 28 Sep 2019 19:52:18 +0200 Subject: bump more deps --- test/full_coverage_plugin.py | 4 ++-- test/individual_coverage.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/full_coverage_plugin.py b/test/full_coverage_plugin.py index f99dc7ab..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 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()) -- cgit v1.2.3 From 93f9e30728300cc5379fd90171818f642d8f24aa Mon Sep 17 00:00:00 2001 From: vin01 <30344579+vin01@users.noreply.github.com> Date: Mon, 30 Sep 2019 17:19:52 +0000 Subject: Add key_size option to define rsa key size (#3657) --- test/mitmproxy/test_certs.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'test') 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, -- cgit v1.2.3 From 902ef59d01f45613ce33520159e157697bcc6f9f Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 6 Oct 2019 14:41:46 +0200 Subject: Move onboardingapp from tornado to flask (#3661) --- test/mitmproxy/addons/onboardingapp/__init__.py | 0 test/mitmproxy/addons/onboardingapp/test_app.py | 1 - 2 files changed, 1 deletion(-) delete mode 100644 test/mitmproxy/addons/onboardingapp/__init__.py delete mode 100644 test/mitmproxy/addons/onboardingapp/test_app.py (limited to 'test') diff --git a/test/mitmproxy/addons/onboardingapp/__init__.py b/test/mitmproxy/addons/onboardingapp/__init__.py deleted file mode 100644 index e69de29b..00000000 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 -- cgit v1.2.3 From 33707403614642ae63d7ed24f36c80a3f58ce7ac Mon Sep 17 00:00:00 2001 From: Yoann L Date: Mon, 28 Oct 2019 17:51:59 +0100 Subject: several fixes on command exports has several problems: #3676 * authority can usually rely on actual URL. as `:authority` headers will break curl command. (advise if it's better to change them to Host, or if it should be reported on curl side) * `content-length`: 0 is added for each request. if it's found in the curl argument list, it'll try to fetch an empty body (and crash). also trying to guess on accept-encoding header to add the `--compress` option when fetching potentially compressed content. * ditto for httpie --- test/mitmproxy/addons/test_export.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/addons/test_export.py b/test/mitmproxy/addons/test_export.py index f4bb0f64..c86e0c7d 100644 --- a/test/mitmproxy/addons/test_export.py +++ b/test/mitmproxy/addons/test_export.py @@ -14,29 +14,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" + ) ) @@ -47,7 +41,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): @@ -67,7 +61,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): -- cgit v1.2.3 From ff628e783e8560da50b4dbfac33906572c66f3ad Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 31 Oct 2019 19:33:13 +0100 Subject: pfctl state output always have 2 lines for each socket. Adding outgoing lines in data which matches lines before incoming ones. Also adding IPv6 data and tests --- test/mitmproxy/data/pf01 | 6 ++++++ test/mitmproxy/platform/test_pf.py | 5 +++++ 2 files changed, 11 insertions(+) (limited to 'test') 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/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) -- cgit v1.2.3 From 80963966b267a4c3723e4773774b854602247bca Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 7 Nov 2019 18:19:50 +0100 Subject: make duration formatting more forgiving --- test/mitmproxy/utils/test_human.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test') 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(): -- cgit v1.2.3 From f97996126f7a7606f8601f0318f0a70a4e818c6c Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 11 Nov 2019 18:35:06 +0100 Subject: minor improvements and sans-io adjustments --- test/mitmproxy/net/test_tls.py | 2 +- test/mitmproxy/test_connections.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/net/test_tls.py b/test/mitmproxy/net/test_tls.py index 68e67dbe..c4e76bc6 100644 --- a/test/mitmproxy/net/test_tls.py +++ b/test/mitmproxy/net/test_tls.py @@ -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 diff --git a/test/mitmproxy/test_connections.py b/test/mitmproxy/test_connections.py index 7c371c1e..c744e621 100644 --- a/test/mitmproxy/test_connections.py +++ b/test/mitmproxy/test_connections.py @@ -95,7 +95,7 @@ class TestServerConnection: def test_repr(self): c = tflow.tserver_conn() - c.sni = 'foobar' + c.sni = b'foobar' c.tls_established = True c.alpn_proto_negotiated = b'h2' assert 'address:22' in repr(c) -- cgit v1.2.3 From bdc15cbe0c0cd5175af1b58078d65d400cca71d1 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 12 Nov 2019 02:59:01 +0100 Subject: update mypy --- test/mitmproxy/test_connections.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/mitmproxy/test_connections.py b/test/mitmproxy/test_connections.py index c744e621..7c371c1e 100644 --- a/test/mitmproxy/test_connections.py +++ b/test/mitmproxy/test_connections.py @@ -95,7 +95,7 @@ class TestServerConnection: def test_repr(self): c = tflow.tserver_conn() - c.sni = b'foobar' + c.sni = 'foobar' c.tls_established = True c.alpn_proto_negotiated = b'h2' assert 'address:22' in repr(c) -- cgit v1.2.3