Skip to content

Commit

Permalink
Stop binding to all network interfaces in tests (#7761)
Browse files Browse the repository at this point in the history
Fixes 4 codeql issues
  • Loading branch information
Dreamsorcerer authored Oct 29, 2023
1 parent c70e804 commit 7a19191
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tests/test_run_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def test_run_app_preexisting_inet_socket(patched_loop: Any, mocker: Any) -> None

sock = socket.socket()
with contextlib.closing(sock):
sock.bind(("0.0.0.0", 0))
sock.bind(("127.0.0.1", 0))
_, port = sock.getsockname()

printer = mock.Mock(wraps=stopper(patched_loop))
Expand All @@ -572,7 +572,7 @@ def test_run_app_preexisting_inet_socket(patched_loop: Any, mocker: Any) -> None
patched_loop.create_server.assert_called_with(
mock.ANY, sock=sock, backlog=128, ssl=None
)
assert f"http://0.0.0.0:{port}" in printer.call_args[0][0]
assert f"http://127.0.0.1:{port}" in printer.call_args[0][0]


@pytest.mark.skipif(not HAS_IPV6, reason="IPv6 is not available")
Expand All @@ -581,7 +581,7 @@ def test_run_app_preexisting_inet6_socket(patched_loop: Any) -> None:

sock = socket.socket(socket.AF_INET6)
with contextlib.closing(sock):
sock.bind(("::", 0))
sock.bind(("::1", 0))
port = sock.getsockname()[1]

printer = mock.Mock(wraps=stopper(patched_loop))
Expand All @@ -590,7 +590,7 @@ def test_run_app_preexisting_inet6_socket(patched_loop: Any) -> None:
patched_loop.create_server.assert_called_with(
mock.ANY, sock=sock, backlog=128, ssl=None
)
assert f"http://[::]:{port}" in printer.call_args[0][0]
assert f"http://[::1]:{port}" in printer.call_args[0][0]


@skip_if_no_unix_socks
Expand Down Expand Up @@ -618,9 +618,9 @@ def test_run_app_multiple_preexisting_sockets(patched_loop: Any) -> None:
sock1 = socket.socket()
sock2 = socket.socket()
with contextlib.closing(sock1), contextlib.closing(sock2):
sock1.bind(("0.0.0.0", 0))
sock1.bind(("localhost", 0))
_, port1 = sock1.getsockname()
sock2.bind(("0.0.0.0", 0))
sock2.bind(("localhost", 0))
_, port2 = sock2.getsockname()

printer = mock.Mock(wraps=stopper(patched_loop))
Expand All @@ -632,8 +632,8 @@ def test_run_app_multiple_preexisting_sockets(patched_loop: Any) -> None:
mock.call(mock.ANY, sock=sock2, backlog=128, ssl=None),
]
)
assert f"http://0.0.0.0:{port1}" in printer.call_args[0][0]
assert f"http://0.0.0.0:{port2}" in printer.call_args[0][0]
assert f"http://127.0.0.1:{port1}" in printer.call_args[0][0]
assert f"http://127.0.0.1:{port2}" in printer.call_args[0][0]


_script_test_signal = """
Expand Down

0 comments on commit 7a19191

Please sign in to comment.