code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def hexdump(s):
"""
Returns:
A generator of (offset, hex, str) tuples
"""
for i in range(0, len(s), 16):
offset = f"{i:0=10x}"
part = s[i : i + 16]
x = " ".join(f"{i:0=2x}" for i in part)
x = x.ljust(47) # 16*2 + 15
part_repr = always_str(
esc... |
Returns:
A generator of (offset, hex, str) tuples
| hexdump | python | mitmproxy/mitmproxy | mitmproxy/utils/strutils.py | https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/utils/strutils.py | MIT |
def split_special_areas(
data: str,
area_delimiter: Iterable[str],
):
"""
Split a string of code into a [code, special area, code, special area, ..., code] list.
For example,
>>> split_special_areas(
>>> "test /* don't modify me */ foo",
>>> [r"/\\*[\\s\\S]*?\\*/"]) # (regex m... |
Split a string of code into a [code, special area, code, special area, ..., code] list.
For example,
>>> split_special_areas(
>>> "test /* don't modify me */ foo",
>>> [r"/\*[\s\S]*?\*/"]) # (regex matching comments)
["test ", "/* don't modify me */", " foo"]
"".join(split_speci... | split_special_areas | python | mitmproxy/mitmproxy | mitmproxy/utils/strutils.py | https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/utils/strutils.py | MIT |
def check_option_type(name: str, value: typing.Any, typeinfo: Type) -> None:
"""
Check if the provided value is an instance of typeinfo and raises a
TypeError otherwise. This function supports only those types required for
options.
"""
e = TypeError(f"Expected {typeinfo} for {name}, but got {typ... |
Check if the provided value is an instance of typeinfo and raises a
TypeError otherwise. This function supports only those types required for
options.
| check_option_type | python | mitmproxy/mitmproxy | mitmproxy/utils/typecheck.py | https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/utils/typecheck.py | MIT |
def standalone_binaries():
"""Windows and Linux: Build the standalone binaries generated with PyInstaller"""
with archive(DIST_DIR / f"mitmproxy-{version()}-{operating_system()}") as f:
_pyinstaller("standalone.spec")
_test_binaries(TEMP_DIR / "pyinstaller/out")
for tool in ["mitmproxy... | Windows and Linux: Build the standalone binaries generated with PyInstaller | standalone_binaries | python | mitmproxy/mitmproxy | release/build.py | https://github.com/mitmproxy/mitmproxy/blob/master/release/build.py | MIT |
def msix_installer():
"""Windows: Build the MSIX installer for the Windows Store."""
_ensure_pyinstaller_onedir()
shutil.copytree(
TEMP_DIR / "pyinstaller/out/onedir",
TEMP_DIR / "msix",
dirs_exist_ok=True,
)
shutil.copytree(here / "windows-installer", TEMP_DIR / "msix", dir... | Windows: Build the MSIX installer for the Windows Store. | msix_installer | python | mitmproxy/mitmproxy | release/build.py | https://github.com/mitmproxy/mitmproxy/blob/master/release/build.py | MIT |
def run_async(coro):
"""
Run the given async function in a new event loop.
This allows async functions to be called synchronously.
"""
loop = asyncio.new_event_loop()
try:
return loop.run_until_complete(coro)
finally:
loop.close() |
Run the given async function in a new event loop.
This allows async functions to be called synchronously.
| run_async | python | mitmproxy/mitmproxy | test/helper_tools/dumperview.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/helper_tools/dumperview.py | MIT |
async def test_collect_commands(caplog):
"""
This tests for errors thrown by getattr() or __getattr__ implementations
that return an object for .command_name.
"""
with taddons.context() as tctx:
c = command.CommandManager(tctx.master)
a = TCmds()
c.collect_commands(a)
... |
This tests for errors thrown by getattr() or __getattr__ implementations
that return an object for .command_name.
| test_collect_commands | python | mitmproxy/mitmproxy | test/mitmproxy/test_command.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/test_command.py | MIT |
def test_copy(self):
"""
_backup may be shared across instances. That should not raise errors.
"""
f = tflow.tflow()
f.backup()
f.request.path = "/foo"
f2 = f.copy()
f2.revert()
f.revert() |
_backup may be shared across instances. That should not raise errors.
| test_copy | python | mitmproxy/mitmproxy | test/mitmproxy/test_flow.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/test_flow.py | MIT |
async def test_ignore_local_mode():
"""At least on macOS, local mode peername may be the client's public IP."""
ar = block.Block()
with taddons.context(ar) as tctx:
tctx.configure(ar, block_private=True)
client = connection.Client(
peername=("192.168.1.1", 0),
socknam... | At least on macOS, local mode peername may be the client's public IP. | test_ignore_local_mode | python | mitmproxy/mitmproxy | test/mitmproxy/addons/test_block.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/addons/test_block.py | MIT |
def test_already_handled(self):
"""Test that we don't interfere if another addon already killed this request."""
bl = blocklist.BlockList()
with taddons.context(bl) as tctx:
tctx.configure(bl, block_list=["/.*/404"])
f = tflow.tflow()
f.kill() # done by anoth... | Test that we don't interfere if another addon already killed this request. | test_already_handled | python | mitmproxy/mitmproxy | test/mitmproxy/addons/test_blocklist.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/addons/test_blocklist.py | MIT |
async def tcp_server(handle_conn, **server_args) -> Address:
"""TCP server context manager that...
1. Exits only after all handlers have returned.
2. Ensures that all handlers are closed properly. If we don't do that,
we get ghost errors in others tests from StreamWriter.__del__.
Spawning a TCP... | TCP server context manager that...
1. Exits only after all handlers have returned.
2. Ensures that all handlers are closed properly. If we don't do that,
we get ghost errors in others tests from StreamWriter.__del__.
Spawning a TCP server is relatively slow. Consider using in-memory networking for ... | tcp_server | python | mitmproxy/mitmproxy | test/mitmproxy/addons/test_clientplayback.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/addons/test_clientplayback.py | MIT |
def test_errorcheck(tdata, capsys, run_main):
"""Integration test: Make sure that we catch errors on startup an exit."""
with pytest.raises(SystemExit):
run_main(
[
"-n",
"-s",
tdata.path("mitmproxy/data/addonscripts/load_error.py"),
... | Integration test: Make sure that we catch errors on startup an exit. | test_errorcheck | python | mitmproxy/mitmproxy | test/mitmproxy/addons/test_errorcheck.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/addons/test_errorcheck.py | MIT |
async def test_warn_no_nextlayer(caplog):
"""
Test that we log an error if the proxy server is started without NextLayer addon.
That is a mean trap to fall into when writing end-to-end tests.
"""
ps = Proxyserver()
with taddons.context(ps) as tctx:
tctx.configure(ps, listen_host="127.0.0... |
Test that we log an error if the proxy server is started without NextLayer addon.
That is a mean trap to fall into when writing end-to-end tests.
| test_warn_no_nextlayer | python | mitmproxy/mitmproxy | test/mitmproxy/addons/test_proxyserver.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/addons/test_proxyserver.py | MIT |
def test_load_fullname(tdata):
"""
Test that loading two scripts at locations a/foo.py and b/foo.py works.
This only succeeds if they get assigned different basenames.
"""
ns = script.load_script(tdata.path("mitmproxy/data/addonscripts/addon.py"))
assert ns.addons
ns2 = script.load_script(
... |
Test that loading two scripts at locations a/foo.py and b/foo.py works.
This only succeeds if they get assigned different basenames.
| test_load_fullname | python | mitmproxy/mitmproxy | test/mitmproxy/addons/test_script.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/addons/test_script.py | MIT |
def test_order(tdata, capsys):
"""Integration test: Make sure that the runtime hooks are triggered on startup in the correct order."""
main.mitmdump(
[
"-n",
"-s",
tdata.path("mitmproxy/data/addonscripts/recorder/recorder.py"),
"-s",
tdata.path... | Integration test: Make sure that the runtime hooks are triggered on startup in the correct order. | test_order | python | mitmproxy/mitmproxy | test/mitmproxy/addons/test_script.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/addons/test_script.py | MIT |
def test_server_playback_response_deleted():
"""
The server playback addon holds references to flows that can be modified by the user in the meantime.
One thing that can happen is that users remove the response object. This happens for example when doing a client
replay at the same time.
"""
sp ... |
The server playback addon holds references to flows that can be modified by the user in the meantime.
One thing that can happen is that users remove the response object. This happens for example when doing a client
replay at the same time.
| test_server_playback_response_deleted | python | mitmproxy/mitmproxy | test/mitmproxy/addons/test_serverplayback.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/addons/test_serverplayback.py | MIT |
def test_encoders(encoder):
"""
This test is for testing byte->byte encoding/decoding
"""
assert encoding.decode(None, encoder) is None
assert encoding.encode(None, encoder) is None
assert b"" == encoding.decode(b"", encoder)
assert b"string" == encoding.decode(encoding.encode(b"string", e... |
This test is for testing byte->byte encoding/decoding
| test_encoders | python | mitmproxy/mitmproxy | test/mitmproxy/net/test_encoding.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/net/test_encoding.py | MIT |
def test_encoders_strings(encoder):
"""
This test is for testing byte->str decoding
and str->byte encoding
"""
assert "" == encoding.decode(b"", encoder)
assert "string" == encoding.decode(encoding.encode("string", encoder), encoder)
with pytest.raises(TypeError):
encoding.encode(b... |
This test is for testing byte->str decoding
and str->byte encoding
| test_encoders_strings | python | mitmproxy/mitmproxy | test/mitmproxy/net/test_encoding.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/net/test_encoding.py | MIT |
def test_empty_key_trailing_equal_sign():
"""
Some HTTP clients don't send trailing equal signs for parameters without assigned value, e.g. they send
foo=bar&baz&qux=quux
instead of
foo=bar&baz=&qux=quux
The respective behavior of encode() should be driven by a reference string given in ... |
Some HTTP clients don't send trailing equal signs for parameters without assigned value, e.g. they send
foo=bar&baz&qux=quux
instead of
foo=bar&baz=&qux=quux
The respective behavior of encode() should be driven by a reference string given in similar_to parameter
| test_empty_key_trailing_equal_sign | python | mitmproxy/mitmproxy | test/mitmproxy/net/http/test_url.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/net/http/test_url.py | MIT |
def test_late_hook_reply(self, tctx: Context):
"""
Properly handle case where we receive an additional event while we are waiting for
a reply from the proxy core.
"""
nl = layer.NextLayer(tctx)
playbook = tutils.Playbook(nl)
assert (
playbook
... |
Properly handle case where we receive an additional event while we are waiting for
a reply from the proxy core.
| test_late_hook_reply | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/test_layer.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/test_layer.py | MIT |
def test_receive_close(self, tctx: Context, layer_found: bool):
"""Test that we abort a client connection which has disconnected without any layer being found."""
nl = layer.NextLayer(tctx)
playbook = tutils.Playbook(nl)
assert (
playbook
>> events.DataReceived(tc... | Test that we abort a client connection which has disconnected without any layer being found. | test_receive_close | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/test_layer.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/test_layer.py | MIT |
async def test_dual_stack(ip_version, protocol, caplog_async):
"""Test that a server bound to "" binds on both IPv4 and IPv6 for both TCP and UDP."""
if ip_version == "v6" and no_ipv6:
pytest.skip("Skipped because IPv6 is unavailable.")
if ip_version == "v4":
addr = "127.0.0.1"
else:
... | Test that a server bound to "" binds on both IPv4 and IPv6 for both TCP and UDP. | test_dual_stack | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/test_mode_servers.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/test_mode_servers.py | MIT |
def test_tunnel_default_impls(tctx: Context):
"""
Some tunnels don't need certain features, so the default behaviour
should be to be transparent.
"""
server = Server(address=None)
server.state = ConnectionState.OPEN
tl = tunnel.TunnelLayer(tctx, server, tctx.server)
tl.child_layer = TChi... |
Some tunnels don't need certain features, so the default behaviour
should be to be transparent.
| test_tunnel_default_impls | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/test_tunnel.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/test_tunnel.py | MIT |
def test_partial_assert(tplaybook):
"""Developers can assert parts of a playbook and the continue later on."""
tplaybook >> TEvent()
tplaybook << TCommand()
assert tplaybook
tplaybook >> TEvent()
tplaybook << TCommand()
assert tplaybook
assert len(tplaybook.actual) == len(tplaybook.exp... | Developers can assert parts of a playbook and the continue later on. | test_partial_assert | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/test_tutils.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/test_tutils.py | MIT |
def test_placeholder(tplaybook, typed):
"""Developers can specify placeholders for yet unknown attributes."""
if typed:
f = tutils.Placeholder(int)
else:
f = tutils.Placeholder()
tplaybook >> TEvent([42])
tplaybook << TCommand(f)
assert tplaybook
assert f() == 42 | Developers can specify placeholders for yet unknown attributes. | test_placeholder | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/test_tutils.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/test_tutils.py | MIT |
def test_unfinished(tplaybook):
"""We show a warning when playbooks aren't asserted."""
tplaybook >> TEvent()
with pytest.raises(RuntimeError, match="Unfinished playbook"):
tplaybook.__del__()
tplaybook._errored = True
tplaybook.__del__() | We show a warning when playbooks aren't asserted. | test_unfinished | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/test_tutils.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/test_tutils.py | MIT |
def test_command_reply(tplaybook):
"""CommandReplies can use relative offsets to point to the matching command."""
tplaybook >> TEvent()
tplaybook << TCommand()
tplaybook >> tutils.reply()
assert tplaybook
assert tplaybook.actual[1] == tplaybook.actual[2].command
tplaybook >> TEvent((42,))
... | CommandReplies can use relative offsets to point to the matching command. | test_command_reply | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/test_tutils.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/test_tutils.py | MIT |
def test_eq_blocking():
"""_eq should not consider differences in .blocking"""
a = TCommand()
a.blocking = True
b = TCommand()
b.blocking = False
assert tutils._eq(a, b) | _eq should not consider differences in .blocking | test_eq_blocking | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/test_tutils.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/test_tutils.py | MIT |
def _eq(a: PlaybookEntry, b: PlaybookEntry) -> bool:
"""Compare two commands/events, and possibly update placeholders."""
if type(a) is not type(b):
return False
a_dict = a.__dict__
b_dict = b.__dict__
# we can assume a.keys() == b.keys()
for k in a_dict:
if k == "blocking":
... | Compare two commands/events, and possibly update placeholders. | _eq | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/tutils.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/tutils.py | MIT |
def eq(
a: PlaybookEntry | Iterable[PlaybookEntry],
b: PlaybookEntry | Iterable[PlaybookEntry],
):
"""
Compare an indiviual event/command or a list of events/commands.
"""
if isinstance(a, collections.abc.Iterable) and isinstance(
b, collections.abc.Iterable
):
return all(_eq... |
Compare an indiviual event/command or a list of events/commands.
| eq | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/tutils.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/tutils.py | MIT |
def __init__(
self,
*args,
to: commands.Command | type[commands.Command] | int = -1,
side_effect: Callable[[Any], None] = lambda x: None,
):
"""Utility method to reply to the latest hook in playbooks."""
assert not args or not isinstance(args[0], commands.Command)
... | Utility method to reply to the latest hook in playbooks. | __init__ | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/tutils.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/tutils.py | MIT |
def reply_next_layer(
child_layer: type[Layer] | Callable[[context.Context], Layer], *args, **kwargs
) -> reply:
"""Helper function to simplify the syntax for next_layer events to this:
<< NextLayerHook(nl)
>> reply_next_layer(tutils.EchoLayer)
"""
def set_layer(next_layer: layer.NextLayer) -> ... | Helper function to simplify the syntax for next_layer events to this:
<< NextLayerHook(nl)
>> reply_next_layer(tutils.EchoLayer)
| reply_next_layer | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/tutils.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/tutils.py | MIT |
def test_transparent_eager_connect_failure(tctx: Context):
"""Test that we recover from a transparent mode connect error."""
tctx.options.connection_strategy = "eager"
tctx.server.address = ("address", 22)
assert (
Playbook(modes.TransparentProxy(tctx), logs=True)
<< OpenConnection(tctx... | Test that we recover from a transparent mode connect error. | test_transparent_eager_connect_failure | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_modes.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_modes.py | MIT |
def test_open_connection(tctx):
"""
If there is no server connection yet, establish one,
because the server may send data first.
"""
assert Playbook(tcp.TCPLayer(tctx, True)) << OpenConnection(tctx.server)
tctx.server.timestamp_start = 1624544785
assert Playbook(tcp.TCPLayer(tctx, True)) <<... |
If there is no server connection yet, establish one,
because the server may send data first.
| test_open_connection | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_tcp.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_tcp.py | MIT |
def test_simple(tctx):
"""open connection, receive data, send it to peer"""
f = Placeholder(TCPFlow)
assert (
Playbook(tcp.TCPLayer(tctx))
<< tcp.TcpStartHook(f)
>> reply()
<< OpenConnection(tctx.server)
>> reply(None)
>> DataReceived(tctx.client, b"hello!")
... | open connection, receive data, send it to peer | test_simple | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_tcp.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_tcp.py | MIT |
def test_receive_data_before_server_connected(tctx):
"""
assert that data received before a server connection is established
will still be forwarded.
"""
assert (
Playbook(tcp.TCPLayer(tctx), hooks=False)
<< OpenConnection(tctx.server)
>> DataReceived(tctx.client, b"hello!")
... |
assert that data received before a server connection is established
will still be forwarded.
| test_receive_data_before_server_connected | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_tcp.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_tcp.py | MIT |
def test_receive_data_after_half_close(tctx):
"""
data received after the other connection has been half-closed should still be forwarded.
"""
assert (
Playbook(tcp.TCPLayer(tctx), hooks=False)
<< OpenConnection(tctx.server)
>> reply(None)
>> DataReceived(tctx.client, b"e... |
data received after the other connection has been half-closed should still be forwarded.
| test_receive_data_after_half_close | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_tcp.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_tcp.py | MIT |
def test_ignore(tctx, ignore):
"""
no flow hooks when we set ignore.
"""
def no_flow_hooks():
assert (
Playbook(tcp.TCPLayer(tctx, ignore=ignore), hooks=True)
<< OpenConnection(tctx.server)
>> reply(None)
>> DataReceived(tctx.client, b"hello!")
... |
no flow hooks when we set ignore.
| test_ignore | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_tcp.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_tcp.py | MIT |
def test_inject(tctx):
"""inject data into an open connection."""
f = Placeholder(TCPFlow)
assert (
Playbook(tcp.TCPLayer(tctx))
<< tcp.TcpStartHook(f)
>> TcpMessageInjected(f, TCPMessage(True, b"hello!"))
>> reply(to=-2)
<< OpenConnection(tctx.server)
>> rep... | inject data into an open connection. | test_inject | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_tcp.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_tcp.py | MIT |
def reply_tls_start_client(alpn: bytes | None = None, *args, **kwargs) -> tutils.reply:
"""
Helper function to simplify the syntax for tls_start_client hooks.
"""
def make_client_conn(tls_start: TlsData) -> None:
# ssl_context = SSL.Context(Method.TLS_METHOD)
# ssl_context.set_min_proto... |
Helper function to simplify the syntax for tls_start_client hooks.
| reply_tls_start_client | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_tls.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_tls.py | MIT |
def reply_tls_start_server(
alpn: bytes | None = None, client_cert: bool = False, *args, **kwargs
) -> tutils.reply:
"""
Helper function to simplify the syntax for tls_start_server hooks.
"""
def make_server_conn(tls_start: TlsData) -> None:
# ssl_context = SSL.Context(Method.TLS_METHOD)
... |
Helper function to simplify the syntax for tls_start_server hooks.
| reply_tls_start_server | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_tls.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_tls.py | MIT |
def test_not_connected(self, tctx: context.Context):
"""Test that we don't do anything if no server connection exists."""
layer = tls.ServerTLSLayer(tctx)
layer.child_layer = TlsEchoLayer(tctx)
assert (
tutils.Playbook(layer)
>> events.DataReceived(tctx.client, b... | Test that we don't do anything if no server connection exists. | test_not_connected | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_tls.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_tls.py | MIT |
def test_untrusted_cert(self, tctx):
"""If the certificate is not trusted, we should fail."""
playbook = tutils.Playbook(tls.ServerTLSLayer(tctx))
tctx.server.address = ("wrong.host.mitmproxy.org", 443)
tctx.server.sni = "wrong.host.mitmproxy.org"
tssl = SSLTest(server_side=True... | If the certificate is not trusted, we should fail. | test_untrusted_cert | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_tls.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_tls.py | MIT |
def test_unsupported_protocol(self, tctx: context.Context):
"""Test the scenario where the server only supports an outdated TLS version by default."""
playbook = tutils.Playbook(tls.ServerTLSLayer(tctx))
tctx.server.address = ("example.mitmproxy.org", 443)
tctx.server.state = ConnectionS... | Test the scenario where the server only supports an outdated TLS version by default. | test_unsupported_protocol | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_tls.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_tls.py | MIT |
def test_server_required(self, tctx, server_state):
"""
Test the scenario where a server connection is required (for example, because of an unknown ALPN)
to establish TLS with the client.
"""
if server_state == "open":
tctx.server.state = ConnectionState.OPEN
... |
Test the scenario where a server connection is required (for example, because of an unknown ALPN)
to establish TLS with the client.
| test_server_required | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_tls.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_tls.py | MIT |
def test_passthrough_from_clienthello(self, tctx, server_state):
"""
Test the scenario where the connection is moved to passthrough mode in the tls_clienthello hook.
"""
if server_state == "open":
tctx.server.timestamp_start = time.time()
tctx.server.state = Conne... |
Test the scenario where the connection is moved to passthrough mode in the tls_clienthello hook.
| test_passthrough_from_clienthello | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_tls.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_tls.py | MIT |
def test_cannot_parse_clienthello(self, tctx: context.Context):
"""Test the scenario where we cannot parse the ClientHello"""
playbook, client_layer, tssl_client = make_client_tls_layer(tctx)
tls_hook_data = tutils.Placeholder(TlsData)
invalid = b"\x16\x03\x01\x00\x00"
assert (... | Test the scenario where we cannot parse the ClientHello | test_cannot_parse_clienthello | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_tls.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_tls.py | MIT |
def test_immediate_disconnect(self, tctx: context.Context, close_at):
"""Test the scenario where the client is disconnecting during the handshake.
This may happen because they are not interested in the connection anymore, or because they do not like
the proxy certificate."""
playbook, cl... | Test the scenario where the client is disconnecting during the handshake.
This may happen because they are not interested in the connection anymore, or because they do not like
the proxy certificate. | test_immediate_disconnect | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_tls.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_tls.py | MIT |
def test_unsupported_protocol(self, tctx: context.Context):
"""Test the scenario where the client only supports an outdated TLS version by default."""
playbook, client_layer, tssl_client = make_client_tls_layer(
tctx, max_ver=ssl.TLSVersion.TLSv1_2
)
playbook.logs = True
... | Test the scenario where the client only supports an outdated TLS version by default. | test_unsupported_protocol | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_tls.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_tls.py | MIT |
def test_upgrade_streamed(tctx):
"""
Test that streaming the response does not change behavior.
"""
tctx.server.address = ("example.com", 80)
tctx.server.state = ConnectionState.OPEN
flow = Placeholder(HTTPFlow)
def enable_streaming(flow: HTTPFlow):
flow.response.stream = True
... |
Test that streaming the response does not change behavior.
| test_upgrade_streamed | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/test_websocket.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/test_websocket.py | MIT |
def test_https_proxy(strategy, http_connect_send_host_header, tctx):
"""Test a CONNECT request, followed by a HTTP GET /"""
server = Placeholder(Server)
flow = Placeholder(HTTPFlow)
playbook = Playbook(http.HttpLayer(tctx, HTTPMode.regular))
tctx.options.connection_strategy = strategy
tctx.optio... | Test a CONNECT request, followed by a HTTP GET / | test_https_proxy | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_redirect(strategy, https_server, https_client, tctx, monkeypatch):
"""Test redirects between http:// and https:// in regular proxy mode."""
server = Placeholder(Server)
flow = Placeholder(HTTPFlow)
tctx.options.connection_strategy = strategy
p = Playbook(http.HttpLayer(tctx, HTTPMode.regula... | Test redirects between http:// and https:// in regular proxy mode. | test_redirect | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_multiple_server_connections(tctx):
"""Test multiple requests being rewritten to different targets."""
server1 = Placeholder(Server)
server2 = Placeholder(Server)
playbook = Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
def redirect(to: str):
def side_effect(flow: HT... | Test multiple requests being rewritten to different targets. | test_multiple_server_connections | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_pipelining(tctx, transfer_encoding):
"""Test that multiple requests can be processed over the same connection"""
tctx.server.address = ("example.com", 80)
tctx.server.state = ConnectionState.OPEN
req = b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"
if transfer_encoding == "identity":
... | Test that multiple requests can be processed over the same connection | test_pipelining | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_response_until_eof(tctx):
"""Test scenario where the server response body is terminated by EOF."""
server = Placeholder(Server)
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
>> DataReceived(
tctx.client,
b"GET http://example.com/ HTTP... | Test scenario where the server response body is terminated by EOF. | test_response_until_eof | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_disconnect_while_intercept(tctx):
"""Test a server disconnect while a request is intercepted."""
tctx.options.connection_strategy = "eager"
server1 = Placeholder(Server)
server2 = Placeholder(Server)
flow = Placeholder(HTTPFlow)
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.... | Test a server disconnect while a request is intercepted. | test_disconnect_while_intercept | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_request_streaming(tctx, why, transfer_encoding, response):
"""
Test HTTP request streaming
This is a bit more contrived as we may receive server data while we are still sending the request.
"""
server = Placeholder(Server)
flow = Placeholder(HTTPFlow)
playbook = Playbook(http.HttpL... |
Test HTTP request streaming
This is a bit more contrived as we may receive server data while we are still sending the request.
| test_request_streaming | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_server_unreachable(tctx, connect):
"""Test the scenario where the target server is unreachable."""
tctx.options.connection_strategy = "eager"
server = Placeholder(Server)
flow = Placeholder(HTTPFlow)
playbook = Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
if connect:
... | Test the scenario where the target server is unreachable. | test_server_unreachable | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_server_aborts(tctx, data):
"""Test the scenario where the server doesn't serve a response"""
server = Placeholder(Server)
flow = Placeholder(HTTPFlow)
playbook = Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
assert (
playbook
>> DataReceived(
tctx... | Test the scenario where the server doesn't serve a response | test_server_aborts | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_upstream_proxy(tctx, redirect, domain, scheme):
"""Test that an upstream HTTP proxy is used."""
server = Placeholder(Server)
server2 = Placeholder(Server)
flow = Placeholder(HTTPFlow)
tctx.client.proxy_mode = ProxyMode.parse("upstream:http://proxy:8080")
playbook = Playbook(http.HttpLay... | Test that an upstream HTTP proxy is used. | test_upstream_proxy | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_no_headers(tctx):
"""Test that we can correctly reassemble requests/responses with no headers."""
server = Placeholder(Server)
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
>> DataReceived(tctx.client, b"GET http://example.com/ HTTP/1.1\r\n\r\n")
<< ... | Test that we can correctly reassemble requests/responses with no headers. | test_no_headers | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_http_proxy_without_empty_chunk_in_head_request(tctx):
"""Test handling of an empty, "chunked" head response."""
server = Placeholder(Server)
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
>> DataReceived(tctx.client, b"HEAD http://example.com/ HTTP/1.1\r\n\r\... | Test handling of an empty, "chunked" head response. | test_http_proxy_without_empty_chunk_in_head_request | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_http_proxy_relative_request(tctx):
"""Test handling of a relative-form "GET /" in regular proxy mode."""
server = Placeholder(Server)
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
>> DataReceived(tctx.client, b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
... | Test handling of a relative-form "GET /" in regular proxy mode. | test_http_proxy_relative_request | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_http_proxy_relative_request_no_host_header(tctx):
"""Test handling of a relative-form "GET /" in regular proxy mode, but without a host header."""
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
>> DataReceived(tctx.client, b"GET / HTTP/1.1\r\n\r\n")
<< Se... | Test handling of a relative-form "GET /" in regular proxy mode, but without a host header. | test_http_proxy_relative_request_no_host_header | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_http_expect(tctx):
"""Test handling of a 'Expect: 100-continue' header."""
server = Placeholder(Server)
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
>> DataReceived(
tctx.client,
b"PUT http://example.com/large-file HTTP/1.1\r\n"
... | Test handling of a 'Expect: 100-continue' header. | test_http_expect | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_http_client_aborts(tctx, stream):
"""Test handling of the case where a client aborts during request transmission."""
server = Placeholder(Server)
flow = Placeholder(HTTPFlow)
playbook = Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=True)
def enable_streaming(flow: HTTPFlow):
... | Test handling of the case where a client aborts during request transmission. | test_http_client_aborts | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_http_server_aborts(tctx, stream):
"""Test handling of the case where a server aborts during response transmission."""
server = Placeholder(Server)
flow = Placeholder(HTTPFlow)
playbook = Playbook(http.HttpLayer(tctx, HTTPMode.regular))
def enable_streaming(flow: HTTPFlow):
flow.res... | Test handling of the case where a server aborts during response transmission. | test_http_server_aborts | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_kill_flow(tctx, when):
"""Test that we properly kill flows if instructed to do so"""
tctx.options.connection_strategy = "lazy"
server = Placeholder(Server)
connect_flow = Placeholder(HTTPFlow)
flow = Placeholder(HTTPFlow)
def kill(flow: HTTPFlow):
flow.kill()
def assert_ki... | Test that we properly kill flows if instructed to do so | test_kill_flow | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_connection_close_header(tctx, client_close, server_close):
"""Test that we correctly close connections if we have a `Connection: close` header."""
if not client_close and not server_close:
return
server = Placeholder(Server)
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.regula... | Test that we correctly close connections if we have a `Connection: close` header. | test_connection_close_header | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_upgrade(tctx, proto):
"""Test a HTTP -> WebSocket upgrade with different protocols enabled"""
if proto != "websocket":
tctx.options.websocket = False
if proto != "tcp":
tctx.options.rawtcp = False
tctx.server.address = ("example.com", 80)
tctx.server.state = ConnectionState... | Test a HTTP -> WebSocket upgrade with different protocols enabled | test_upgrade | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_dont_reuse_closed(tctx):
"""Test that a closed connection is not reused."""
server = Placeholder(Server)
server2 = Placeholder(Server)
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
>> DataReceived(
tctx.client,
b"GET http://exampl... | Test that a closed connection is not reused. | test_dont_reuse_closed | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_reuse_error(tctx):
"""Test that an errored connection is reused."""
tctx.server.address = ("example.com", 443)
tctx.server.error = "tls verify failed"
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.transparent), hooks=False)
>> DataReceived(tctx.client, b"GET / HTTP/1.1\r\n\r\n... | Test that an errored connection is reused. | test_reuse_error | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_transparent_sni(tctx):
"""Test that we keep the SNI in lazy transparent mode."""
tctx.client.sni = "example.com"
tctx.server.address = ("192.0.2.42", 443)
tctx.server.tls = True
flow = Placeholder(HTTPFlow)
server = Placeholder(Server)
assert (
Playbook(http.HttpLayer(tctx... | Test that we keep the SNI in lazy transparent mode. | test_transparent_sni | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_reverse_sni(tctx):
"""Test that we use the destination address as SNI in reverse mode."""
tctx.client.sni = "localhost"
tctx.server.address = ("192.0.2.42", 443)
tctx.server.tls = True
tctx.server.sni = "example.local"
flow = Placeholder(HTTPFlow)
server = Placeholder(Server)
... | Test that we use the destination address as SNI in reverse mode. | test_reverse_sni | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_original_server_disconnects(tctx):
"""Test that we correctly handle the case where the initial server conn is just closed."""
tctx.server.state = ConnectionState.OPEN
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.transparent))
>> ConnectionClosed(tctx.server)
<< CloseConne... | Test that we correctly handle the case where the initial server conn is just closed. | test_original_server_disconnects | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_request_smuggling(tctx):
"""Test that we reject request smuggling"""
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
>> DataReceived(
tctx.client,
b"GET http://example.com/ HTTP/1.1\r\n"
b"Host: example.com\r\n"
b"Co... | Test that we reject request smuggling | test_request_smuggling | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_request_smuggling_whitespace(tctx):
"""Test that we reject header names with whitespace"""
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
>> DataReceived(
tctx.client,
b"GET http://example.com/ HTTP/1.1\r\n"
b"Host: example.com... | Test that we reject header names with whitespace | test_request_smuggling_whitespace | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_request_smuggling_response(tctx):
"""Test that we reject response smuggling"""
server = Placeholder(Server)
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
>> DataReceived(
tctx.client,
b"GET http://example.com/ HTTP/1.1\r\nHost: exampl... | Test that we reject response smuggling | test_request_smuggling_response | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_request_smuggling_validation_disabled(tctx):
"""Test that we don't reject request smuggling when validation is disabled."""
tctx.options.validate_inbound_headers = False
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
>> DataReceived(
tctx.client,
... | Test that we don't reject request smuggling when validation is disabled. | test_request_smuggling_validation_disabled | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_invalid_content_length(tctx, cl):
"""Test that we still trigger flow hooks for requests with semantic errors"""
flow = Placeholder(HTTPFlow)
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.regular))
>> DataReceived(
tctx.client,
(
b"GET http:/... | Test that we still trigger flow hooks for requests with semantic errors | test_invalid_content_length | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_chunked_and_content_length_set_by_addon(tctx):
"""Test that we don't crash when an addon sets a transfer-encoding header
We reject a request with both transfer-encoding and content-length header to
thwart request smuggling, but if a user explicitly sets it we should not crash.
"""
server =... | Test that we don't crash when an addon sets a transfer-encoding header
We reject a request with both transfer-encoding and content-length header to
thwart request smuggling, but if a user explicitly sets it we should not crash.
| test_chunked_and_content_length_set_by_addon | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_memory_usage_completed_flows(tctx):
"""Make sure that flows are not kept in memory after they are completed."""
gc.collect()
flow_count = flows_tracked()
server = Placeholder(Server)
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
>> DataReceived(
... | Make sure that flows are not kept in memory after they are completed. | test_memory_usage_completed_flows | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_memory_usage_errored_flows(tctx):
"""Make sure that flows are not kept in memory after they errored."""
gc.collect()
flow_count = flows_tracked()
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.regular), hooks=False)
>> DataReceived(
tctx.client,
b"GET h... | Make sure that flows are not kept in memory after they errored. | test_memory_usage_errored_flows | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_drop_stream_with_paused_events(tctx):
"""Make sure that we don't crash if we still have paused events for streams that error."""
tctx.options.stream_large_bodies = "1"
server = Placeholder(Server)
flow = Placeholder(HTTPFlow)
assert (
Playbook(http.HttpLayer(tctx, HTTPMode.regular))... | Make sure that we don't crash if we still have paused events for streams that error. | test_drop_stream_with_paused_events | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http.py | MIT |
def test_http2_client_aborts(tctx, stream, when, how):
"""
Test handling of the case where a client aborts during request or response transmission.
If the client aborts the request transmission, we must trigger an error hook,
if the client disconnects during response transmission, no error hook is trig... |
Test handling of the case where a client aborts during request or response transmission.
If the client aborts the request transmission, we must trigger an error hook,
if the client disconnects during response transmission, no error hook is triggered.
| test_http2_client_aborts | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http2.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http2.py | MIT |
def test_no_normalization(tctx, normalize):
"""Test that we don't normalize headers when we just pass them through."""
tctx.options.normalize_outbound_headers = normalize
tctx.options.validate_inbound_headers = False
server = Placeholder(Server)
flow = Placeholder(HTTPFlow)
playbook, cff = star... | Test that we don't normalize headers when we just pass them through. | test_no_normalization | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http2.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http2.py | MIT |
def test_rst_then_close(tctx):
"""
Test that we properly handle the case of a client that first causes protocol errors and then disconnects.
Adapted from h2spec http2/5.1/5.
"""
playbook, cff = start_h2_client(tctx)
flow = Placeholder(HTTPFlow)
server = Placeholder(Server)
assert (
... |
Test that we properly handle the case of a client that first causes protocol errors and then disconnects.
Adapted from h2spec http2/5.1/5.
| test_rst_then_close | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http2.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http2.py | MIT |
def test_cancel_then_server_disconnect(tctx):
"""
Test that we properly handle the case of the following event sequence:
- client cancels a stream
- we start an error hook
- server disconnects
- error hook completes.
"""
playbook, cff = start_h2_client(tctx)
flow = Pl... |
Test that we properly handle the case of the following event sequence:
- client cancels a stream
- we start an error hook
- server disconnects
- error hook completes.
| test_cancel_then_server_disconnect | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http2.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http2.py | MIT |
def test_cancel_during_response_hook(tctx):
"""
Test that we properly handle the case of the following event sequence:
- we receive a server response
- we trigger the response hook
- the client cancels the stream
- the response hook completes
Given that we have already trigg... |
Test that we properly handle the case of the following event sequence:
- we receive a server response
- we trigger the response hook
- the client cancels the stream
- the response hook completes
Given that we have already triggered the response hook, we don't want to trigger th... | test_cancel_during_response_hook | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http2.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http2.py | MIT |
def test_http_1_1_required(tctx):
"""
Test that we properly forward an HTTP_1_1_REQUIRED stream error.
"""
playbook, cff = start_h2_client(tctx)
flow = Placeholder(HTTPFlow)
server = Placeholder(Server)
sff = FrameFactory()
forwarded_request_frames = Placeholder(bytes)
assert (
... |
Test that we properly forward an HTTP_1_1_REQUIRED stream error.
| test_http_1_1_required | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http2.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http2.py | MIT |
def test_stream_concurrency(tctx):
"""Test that we can send an intercepted request with a lower stream id than one that has already been sent."""
playbook, cff = start_h2_client(tctx)
flow1 = Placeholder(HTTPFlow)
flow2 = Placeholder(HTTPFlow)
reqheadershook1 = http.HttpRequestHeadersHook(flow1)
... | Test that we can send an intercepted request with a lower stream id than one that has already been sent. | test_stream_concurrency | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http2.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http2.py | MIT |
def test_stream_concurrent_get_connection(tctx):
"""Test that an immediate second request for the same domain does not trigger a second connection attempt."""
playbook, cff = start_h2_client(tctx)
playbook.hooks = False
server = Placeholder(Server)
data = Placeholder(bytes)
assert (
pl... | Test that an immediate second request for the same domain does not trigger a second connection attempt. | test_stream_concurrent_get_connection | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http2.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http2.py | MIT |
def test_kill_stream(tctx):
"""Test that we can kill individual streams."""
playbook, cff = start_h2_client(tctx)
flow1 = Placeholder(HTTPFlow)
flow2 = Placeholder(HTTPFlow)
req_headers_hook_1 = http.HttpRequestHeadersHook(flow1)
def kill(flow: HTTPFlow):
# Can't use flow.kill() here b... | Test that we can kill individual streams. | test_kill_stream | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http2.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http2.py | MIT |
def test_rst_then_close(tctx):
"""
Test that we properly handle the case of a client that first causes protocol errors and then disconnects.
This is slightly different to H2, as QUIC will close the connection immediately.
"""
playbook, cff = start_h3_proxy(tctx)
flow = tutils.Placeholder(HTTPFl... |
Test that we properly handle the case of a client that first causes protocol errors and then disconnects.
This is slightly different to H2, as QUIC will close the connection immediately.
| test_rst_then_close | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http3.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http3.py | MIT |
def test_cancel_examples(example):
"""
We can't specify examples in test_fuzz_cancel (because we use data, see
https://hypothesis.readthedocs.io/en/latest/data.html#interactive-draw),
so we have this here for explicit examples.
"""
stream_req, stream_resp, draws = example
def draw(lst):
... |
We can't specify examples in test_fuzz_cancel (because we use data, see
https://hypothesis.readthedocs.io/en/latest/data.html#interactive-draw),
so we have this here for explicit examples.
| test_cancel_examples | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http_fuzz.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http_fuzz.py | MIT |
def _test_cancel(stream_req, stream_resp, draw):
"""
Test that we don't raise an exception if someone disconnects.
"""
tctx = _tctx()
playbook, cff = start_h2_client(tctx)
flow = Placeholder(HTTPFlow)
server = Placeholder(Server)
def maybe_stream(flow: HTTPFlow):
if stream_req:
... |
Test that we don't raise an exception if someone disconnects.
| _test_cancel | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/http/test_http_fuzz.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/http/test_http_fuzz.py | MIT |
def reply_tls_start_client(alpn: str | None = None, *args, **kwargs) -> tutils.reply:
"""
Helper function to simplify the syntax for quic_start_client hooks.
"""
def make_client_conn(tls_start: QuicTlsData) -> None:
config = QuicConfiguration()
config.load_cert_chain(
tdata.... |
Helper function to simplify the syntax for quic_start_client hooks.
| reply_tls_start_client | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/quic/test__stream_layers.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/quic/test__stream_layers.py | MIT |
def reply_tls_start_server(alpn: str | None = None, *args, **kwargs) -> tutils.reply:
"""
Helper function to simplify the syntax for quic_start_server hooks.
"""
def make_server_conn(tls_start: QuicTlsData) -> None:
tls_start.settings = QuicTlsSettings(
ca_file=tdata.path("mitmproxy... |
Helper function to simplify the syntax for quic_start_server hooks.
| reply_tls_start_server | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/quic/test__stream_layers.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/quic/test__stream_layers.py | MIT |
def test_http3_disabled(self, tctx: context.Context):
"""Test that we swallow QUIC packets if QUIC and HTTP/3 are disabled."""
tctx.options.http3 = False
assert (
tutils.Playbook(ClientQuicLayer(tctx, time=time.time), logs=True)
>> events.DataReceived(tctx.client, client_... | Test that we swallow QUIC packets if QUIC and HTTP/3 are disabled. | test_http3_disabled | python | mitmproxy/mitmproxy | test/mitmproxy/proxy/layers/quic/test__stream_layers.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/proxy/layers/quic/test__stream_layers.py | MIT |
def test_xsrf_hardening_app(self):
"""Ensure that xsrf token is not provided for JS requests."""
resp = self.fetch("/", headers={"Sec-Fetch-Mode": "same-origin"})
assert resp.code == 412
assert b"xsrf" not in resp.body
assert b"xsrf" in self.fetch("/", headers={"Sec-Fetch-Mode": ... | Ensure that xsrf token is not provided for JS requests. | test_xsrf_hardening_app | python | mitmproxy/mitmproxy | test/mitmproxy/tools/web/test_app.py | https://github.com/mitmproxy/mitmproxy/blob/master/test/mitmproxy/tools/web/test_app.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.