diff options
Diffstat (limited to 'testing/web-platform/mozilla/tests/webdriver/protocol')
5 files changed, 222 insertions, 0 deletions
diff --git a/testing/web-platform/mozilla/tests/webdriver/protocol/__init__.py b/testing/web-platform/mozilla/tests/webdriver/protocol/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/testing/web-platform/mozilla/tests/webdriver/protocol/__init__.py diff --git a/testing/web-platform/mozilla/tests/webdriver/protocol/allow_hosts.py b/testing/web-platform/mozilla/tests/webdriver/protocol/allow_hosts.py new file mode 100644 index 0000000000..17ae2c2c68 --- /dev/null +++ b/testing/web-platform/mozilla/tests/webdriver/protocol/allow_hosts.py @@ -0,0 +1,53 @@ +from copy import deepcopy + +import pytest +from support.network import get_host, http_request, websocket_request + + +@pytest.mark.parametrize( + "allow_hosts, hostname, port_type, status", + [ + # Valid hosts + (["localhost.localdomain", "localhost"], "localhost", "server_port", 200), + (["localhost.localdomain", "localhost"], "127.0.0.1", "server_port", 200), + # Invalid hosts + (["localhost.localdomain"], "localhost", "server_port", 500), + (["localhost"], "localhost", "wrong_port", 500), + (["www.localhost"], "localhost", "server_port", 500), + ], +) +def test_allow_hosts(geckodriver, allow_hosts, hostname, port_type, status): + extra_args = ["--allow-hosts"] + allow_hosts + + driver = geckodriver(hostname=hostname, extra_args=extra_args) + host = get_host(port_type, hostname, driver.port) + response = http_request(driver.hostname, driver.port, host=host) + + assert response.status == status + + +@pytest.mark.parametrize( + "allow_hosts, hostname, status", + [ + (["mozilla.org", "testhost"], "testhost", 101), + (["mozilla.org"], "testhost", 400), + ], + ids=["allowed", "not allowed"], +) +def test_allow_hosts_passed_to_remote_agent( + configuration, geckodriver, allow_hosts, hostname, status +): + config = deepcopy(configuration) + config["capabilities"]["webSocketUrl"] = True + + extra_args = ["--allow-hosts"] + allow_hosts + + driver = geckodriver(config=config, extra_args=extra_args) + + driver.new_session() + + host = get_host("default_port", hostname, driver.remote_agent_port) + response = websocket_request("127.0.0.1", driver.remote_agent_port, host=host) + assert response.status == status + + driver.delete_session() diff --git a/testing/web-platform/mozilla/tests/webdriver/protocol/allow_origins.py b/testing/web-platform/mozilla/tests/webdriver/protocol/allow_origins.py new file mode 100644 index 0000000000..72b6fba482 --- /dev/null +++ b/testing/web-platform/mozilla/tests/webdriver/protocol/allow_origins.py @@ -0,0 +1,56 @@ +from copy import deepcopy + +import pytest +from support.network import http_request, websocket_request + + +@pytest.mark.parametrize( + "allow_origins, origin, status", + [ + # Valid origins + (["http://web-platform.test"], "http://web-platform.test", 200), + (["http://web-platform.test"], "http://web-platform.test:80", 200), + (["https://web-platform.test"], "https://web-platform.test:443", 200), + # Invalid origins + (["https://web-platform.test"], "http://web-platform.test", 500), + (["http://web-platform.test:8000"], "http://web-platform.test", 500), + (["http://web-platform.test"], "http://www.web-platform.test", 500), + ], +) +def test_allow_hosts(configuration, geckodriver, allow_origins, origin, status): + extra_args = ["--allow-origins"] + allow_origins + + driver = geckodriver(extra_args=extra_args) + response = http_request(driver.hostname, driver.port, origin=origin) + + assert response.status == status + + +@pytest.mark.parametrize( + "allow_origins, origin, status", + [ + ( + ["https://web-platform.test", "http://web-platform.test"], + "http://web-platform.test", + 101, + ), + (["https://web-platform.test"], "http://web-platform.test", 400), + ], + ids=["allowed", "not allowed"], +) +def test_allow_origins_passed_to_remote_agent( + configuration, geckodriver, allow_origins, origin, status +): + config = deepcopy(configuration) + config["capabilities"]["webSocketUrl"] = True + + extra_args = ["--allow-origins"] + allow_origins + + driver = geckodriver(config=config, extra_args=extra_args) + + driver.new_session() + + response = websocket_request("127.0.0.1", driver.remote_agent_port, origin=origin) + assert response.status == status + + driver.delete_session() diff --git a/testing/web-platform/mozilla/tests/webdriver/protocol/marionette_port.py b/testing/web-platform/mozilla/tests/webdriver/protocol/marionette_port.py new file mode 100644 index 0000000000..09951abc43 --- /dev/null +++ b/testing/web-platform/mozilla/tests/webdriver/protocol/marionette_port.py @@ -0,0 +1,41 @@ +import os +from copy import deepcopy + +import pytest + + +@pytest.mark.parametrize("port", ["0", "2828"], ids=["system allocated", "fixed"]) +def test_marionette_port(geckodriver, port): + extra_args = ["--marionette-port", port] + + driver = geckodriver(extra_args=extra_args) + driver.new_session() + driver.delete_session() + + +def test_marionette_port_outdated_active_port_file( + configuration, geckodriver, custom_profile +): + config = deepcopy(configuration) + extra_args = ["--marionette-port", "0"] + + # Prepare a Marionette active port file that contains a port which will + # never be used when requesting a system allocated port. + active_port_file = os.path.join(custom_profile.profile, "MarionetteActivePort") + with open(active_port_file, "wb") as f: + f.write(b"53") + + config["capabilities"]["moz:firefoxOptions"]["args"] = [ + "--profile", + custom_profile.profile, + ] + + driver = geckodriver(config=config, extra_args=extra_args) + + driver.new_session() + with open(active_port_file, "rb") as f: + assert f.readline() != b"53" + + driver.delete_session() + with pytest.raises(FileNotFoundError): + open(active_port_file, "rb") diff --git a/testing/web-platform/mozilla/tests/webdriver/protocol/request.py b/testing/web-platform/mozilla/tests/webdriver/protocol/request.py new file mode 100644 index 0000000000..ad99d6964d --- /dev/null +++ b/testing/web-platform/mozilla/tests/webdriver/protocol/request.py @@ -0,0 +1,72 @@ +import pytest +from support.network import get_host, http_request + + +@pytest.mark.parametrize( + "hostname, port_type, status", + [ + # Valid hosts + ("localhost", "server_port", 200), + ("127.0.0.1", "server_port", 200), + ("[::1]", "server_port", 200), + ("192.168.8.1", "server_port", 200), + ("[fdf8:f535:82e4::53]", "server_port", 200), + # Invalid hosts + ("localhost", "default_port", 500), + ("127.0.0.1", "default_port", 500), + ("[::1]", "default_port", 500), + ("192.168.8.1", "default_port", 500), + ("[fdf8:f535:82e4::53]", "default_port", 500), + ("example.org", "server_port", 500), + ("example.org", "wrong_port", 500), + ("example.org", "default_port", 500), + ("localhost", "wrong_port", 500), + ("127.0.0.1", "wrong_port", 500), + ("[::1]", "wrong_port", 500), + ("192.168.8.1", "wrong_port", 500), + ("[fdf8:f535:82e4::53]", "wrong_port", 500), + ], + ids=[ + # Valid hosts + "localhost with same port as server", + "127.0.0.1 (loopback) with same port as server", + "[::1] (ipv6 loopback) with same port as server", + "ipv4 address with same port as server", + "ipv6 address with same port as server", + # Invalid hosts + "localhost with default port", + "127.0.0.1 (loopback) with default port", + "[::1] (ipv6 loopback) with default port", + "ipv4 address with default port", + "ipv6 address with default port", + "random hostname with the same port as server", + "random hostname with a different port than server", + "random hostname with default port", + "localhost with a different port than server", + "127.0.0.1 (loopback) with a different port than server", + "[::1] (ipv6 loopback) with a different port than server", + "ipv4 address with a different port than server", + "ipv6 address with a different port than server", + ], +) +def test_host_header(configuration, hostname, port_type, status): + host = get_host(port_type, hostname, configuration["port"]) + response = http_request(configuration["host"], configuration["port"], host=host) + + assert response.status == status + + +@pytest.mark.parametrize( + "origin, add_port, status", + [ + (None, False, 200), + ("", False, 500), + ("sometext", False, 500), + ("http://localhost", True, 500), + ], +) +def test_origin_header(configuration, origin, add_port, status): + if add_port: + origin = f"{origin}:{configuration['port']}" + response = http_request(configuration["host"], configuration["port"], origin=origin) + assert response.status == status |