| 1 |
import pytest |
| 2 |
from support.network import get_host, http_request |
| 3 |
|
| 4 |
|
| 5 |
@pytest.mark.parametrize( |
| 6 |
"hostname, port_type, status", |
| 7 |
[ |
| 8 |
# Valid hosts |
| 9 |
("localhost", "server_port", 200), |
| 10 |
("127.0.0.1", "server_port", 200), |
| 11 |
("[::1]", "server_port", 200), |
| 12 |
("192.168.8.1", "server_port", 200), |
| 13 |
("[fdf8:f535:82e4::53]", "server_port", 200), |
| 14 |
# Invalid hosts |
| 15 |
("localhost", "default_port", 500), |
| 16 |
("127.0.0.1", "default_port", 500), |
| 17 |
("[::1]", "default_port", 500), |
| 18 |
("192.168.8.1", "default_port", 500), |
| 19 |
("[fdf8:f535:82e4::53]", "default_port", 500), |
| 20 |
("example.org", "server_port", 500), |
| 21 |
("example.org", "wrong_port", 500), |
| 22 |
("example.org", "default_port", 500), |
| 23 |
("localhost", "wrong_port", 500), |
| 24 |
("127.0.0.1", "wrong_port", 500), |
| 25 |
("[::1]", "wrong_port", 500), |
| 26 |
("192.168.8.1", "wrong_port", 500), |
| 27 |
("[fdf8:f535:82e4::53]", "wrong_port", 500), |
| 28 |
], |
| 29 |
ids=[ |
| 30 |
# Valid hosts |
| 31 |
"localhost with same port as server", |
| 32 |
"127.0.0.1 (loopback) with same port as server", |
| 33 |
"[::1] (ipv6 loopback) with same port as server", |
| 34 |
"ipv4 address with same port as server", |
| 35 |
"ipv6 address with same port as server", |
| 36 |
# Invalid hosts |
| 37 |
"localhost with default port", |
| 38 |
"127.0.0.1 (loopback) with default port", |
| 39 |
"[::1] (ipv6 loopback) with default port", |
| 40 |
"ipv4 address with default port", |
| 41 |
"ipv6 address with default port", |
| 42 |
"random hostname with the same port as server", |
| 43 |
"random hostname with a different port than server", |
| 44 |
"random hostname with default port", |
| 45 |
"localhost with a different port than server", |
| 46 |
"127.0.0.1 (loopback) with a different port than server", |
| 47 |
"[::1] (ipv6 loopback) with a different port than server", |
| 48 |
"ipv4 address with a different port than server", |
| 49 |
"ipv6 address with a different port than server", |
| 50 |
], |
| 51 |
) |
| 52 |
def test_host_header(configuration, hostname, port_type, status): |
| 53 |
host = get_host(port_type, hostname, configuration["port"]) |
| 54 |
response = http_request(configuration["host"], configuration["port"], host=host) |
| 55 |
|
| 56 |
assert response.status == status |
| 57 |
|
| 58 |
|
| 59 |
@pytest.mark.parametrize( |
| 60 |
"origin, add_port, status", |
| 61 |
[ |
| 62 |
(None, False, 200), |
| 63 |
("", False, 500), |
| 64 |
("sometext", False, 500), |
| 65 |
("http://localhost", True, 500), |
| 66 |
], |
| 67 |
) |
| 68 |
def test_origin_header(configuration, origin, add_port, status): |
| 69 |
if add_port: |
| 70 |
origin = f"{origin}:{configuration['port']}" |
| 71 |
response = http_request(configuration["host"], configuration["port"], origin=origin) |
| 72 |
assert response.status == status |