From 1b09002edc984d4ead3cce118ed583c3ceca0b99 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 31 Jul 2017 00:04:46 +0200 Subject: remove OptManager._processed Instead of having the core addon do postprocessing on body_size_limit, we add a cache to the parsing function. First, this avoids any potential issues with options and _processed getting out of sync. As anecdotal evidence, the previous implementation did not clear _processed when body_size_limit was reset to None. Second, it achieves the same end result without introducing a new concept of a "_processed" scratch space. Third, it works even if addons aren't present, and does not require workarounds as previously present in test_http2.py. refs https://github.com/mitmproxy/mitmproxy/pull/2484#pullrequestreview-53101507 --- test/mitmproxy/addons/test_core_option_validation.py | 1 - test/mitmproxy/proxy/protocol/test_http2.py | 3 --- test/mitmproxy/utils/test_human.py | 1 + 3 files changed, 1 insertion(+), 4 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/addons/test_core_option_validation.py b/test/mitmproxy/addons/test_core_option_validation.py index 6d6d5ba4..cd5d4dfa 100644 --- a/test/mitmproxy/addons/test_core_option_validation.py +++ b/test/mitmproxy/addons/test_core_option_validation.py @@ -11,7 +11,6 @@ def test_simple(): with pytest.raises(exceptions.OptionsError): tctx.configure(sa, body_size_limit = "invalid") tctx.configure(sa, body_size_limit = "1m") - assert tctx.master.options._processed["body_size_limit"] with pytest.raises(exceptions.OptionsError, match="mutually exclusive"): tctx.configure( diff --git a/test/mitmproxy/proxy/protocol/test_http2.py b/test/mitmproxy/proxy/protocol/test_http2.py index 5e6fa701..4f161ef5 100644 --- a/test/mitmproxy/proxy/protocol/test_http2.py +++ b/test/mitmproxy/proxy/protocol/test_http2.py @@ -507,9 +507,6 @@ class TestBodySizeLimit(_Http2Test): def test_body_size_limit(self): self.options.body_size_limit = "20" - # FIXME: This should not be required? - self.options._processed["body_size_limit"] = 20 - h2_conn = self.setup_connection() self._send_request( diff --git a/test/mitmproxy/utils/test_human.py b/test/mitmproxy/utils/test_human.py index 76dc2f88..e8ffaad4 100644 --- a/test/mitmproxy/utils/test_human.py +++ b/test/mitmproxy/utils/test_human.py @@ -22,6 +22,7 @@ def test_parse_size(): human.parse_size("1f") with pytest.raises(ValueError): human.parse_size("ak") + assert human.parse_size(None) is None def test_pretty_size(): -- cgit v1.2.3