summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/mozilla/tests/webdriver/classic/protocol/allow_hosts.py
blob: 17ae2c2c688e66883ee8f402e275939b70ef9940 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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()