1import pytest
2
3from . import Geckodriver, get_host, request
4
5
6@pytest.mark.parametrize(
7    "allow_hosts, hostname, port_type, status",
8    [
9        # Valid hosts
10        (["localhost.localdomain", "localhost"], "localhost", "server_port", 200),
11        (["localhost.localdomain", "localhost"], "127.0.0.1", "server_port", 200),
12        # Invalid hosts
13        (["localhost.localdomain"], "localhost", "server_port", 500),
14        (["localhost"], "localhost", "wrong_port", 500),
15        (["www.localhost"], "localhost", "server_port", 500),
16    ],
17)
18def test_allow_hosts(configuration, allow_hosts, hostname, port_type, status):
19    extra_args = ["--allow-hosts"] + allow_hosts
20
21    with Geckodriver(configuration, hostname, extra_args) as geckodriver:
22        host = get_host(port_type, hostname, geckodriver.port)
23        response = request(geckodriver.hostname, geckodriver.port, host=host)
24
25    assert response.status == status
26