Skip to content

Commit

Permalink
py: Don't expose 0.0.0.0 as destination IP for tests (#14324)
Browse files Browse the repository at this point in the history
Webkit recently[1] started blocking 0.0.0.0 as destination addresses,
and Chrome is also in the process of enabling such change[2].

This commit falls back to use the default localhost IP instead of 0.0.0.0
if we don't want to use the real IP. And if the server is actually using
0.0.0.0, fallback to localhost when generating the URL for the tests.

[1] WebKit/WebKit@e59cd4a
[2] https://chromestatus.com/feature/5106143060033536

Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
  • Loading branch information
lauromoura and diemol authored Aug 1, 2024
1 parent c9f60ef commit 0b2bb9a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion py/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def wait_for_server(url, timeout):

@pytest.fixture(autouse=True, scope="session")
def webserver(request):
host = get_lan_ip() if request.config.getoption("use_lan_ip") else "0.0.0.0"
host = get_lan_ip() if request.config.getoption("use_lan_ip") else None

webserver = SimpleWebServer(host=host)
webserver.start()
Expand Down
5 changes: 3 additions & 2 deletions py/test/selenium/webdriver/common/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class SimpleWebServer:

def __init__(self, host=DEFAULT_HOST_IP, port=DEFAULT_PORT):
self.stop_serving = False
host = host
host = host if host else DEFAULT_HOST_IP
port = port
while True:
try:
Expand Down Expand Up @@ -171,7 +171,8 @@ def stop(self):

def where_is(self, path, localhost=False) -> str:
# True force serve the page from localhost
if localhost:
# 0.0.0.0 shouldn't be used as a destination address, so fallback to localhost
if localhost or self.host == "0.0.0.0":
return f"http://{DEFAULT_HOST}:{self.port}/{path}"
return f"http://{self.host}:{self.port}/{path}"

Expand Down

0 comments on commit 0b2bb9a

Please sign in to comment.