allow_hosts.py (1779B)
1 from copy import deepcopy 2 3 import pytest 4 from support.network import get_host, http_request, websocket_request 5 6 pytestmark = pytest.mark.asyncio 7 8 9 @pytest.mark.parametrize( 10 "allow_hosts, hostname, port_type, status", 11 [ 12 # Valid hosts 13 (["localhost.localdomain", "localhost"], "localhost", "server_port", 200), 14 (["localhost.localdomain", "localhost"], "127.0.0.1", "server_port", 200), 15 # Invalid hosts 16 (["localhost.localdomain"], "localhost", "server_port", 500), 17 (["localhost"], "localhost", "wrong_port", 500), 18 (["www.localhost"], "localhost", "server_port", 500), 19 ], 20 ) 21 def test_allow_hosts(geckodriver, allow_hosts, hostname, port_type, status): 22 extra_args = ["--allow-hosts"] + allow_hosts 23 24 driver = geckodriver(hostname=hostname, extra_args=extra_args) 25 host = get_host(port_type, hostname, driver.port) 26 response = http_request(driver.hostname, driver.port, host=host) 27 28 assert response.status == status 29 30 31 @pytest.mark.parametrize( 32 "allow_hosts, hostname, status", 33 [ 34 (["mozilla.org", "testhost"], "testhost", 101), 35 (["mozilla.org"], "testhost", 400), 36 ], 37 ids=["allowed", "not allowed"], 38 ) 39 async def test_allow_hosts_passed_to_remote_agent( 40 configuration, geckodriver, allow_hosts, hostname, status 41 ): 42 config = deepcopy(configuration) 43 config["capabilities"]["webSocketUrl"] = True 44 45 extra_args = ["--allow-hosts"] + allow_hosts 46 47 driver = geckodriver(config=config, extra_args=extra_args) 48 49 driver.new_session() 50 51 host = get_host("default_port", hostname, driver.remote_agent_port) 52 response = websocket_request("127.0.0.1", driver.remote_agent_port, host=host) 53 assert response.status == status 54 55 await driver.delete_session()