summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/mozilla/tests/webdriver/classic/protocol/request.py
blob: ad99d6964db6fd099d17d0008f0ffc2667774534 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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