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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
import itertools
import sys
import pytest
SNOWMAN = b"\xe2\x98\x83"
valid_hosts = [
"[21DA:00D3:0000:2F3B:02AA:00FF:FE28:9C5A]",
"[::1]",
"[::1%25lo]", # With ZoneID
"[FF02:0:0:0:0:0:0:2%25en01]", # With ZoneID
"[FF02:30:0:0:0:0:0:5%25en1]", # With ZoneID
"[FF02:30:0:0:0:0:0:5%25%26]", # With ZoneID
"[FF02:30:0:0:0:0:0:5%2525]", # With ZoneID
"[21DA:D3:0:2F3B:2AA:FF:FE28:9C5A]",
"[FE80::2AA:FF:FE9A:4CA2]",
"[FF02::2]",
"[FFFF::]",
"[FF02:3::5]",
"[FF02:0:0:0:0:0:0:2]",
"[FF02:30:0:0:0:0:0:5]",
"127.0.0.1",
"www.example.com",
"localhost",
"http-bin.org",
"%2Fvar%2Frun%2Fsocket",
"6g9m8V6", # Issue #48
]
invalid_hosts = [
"[FF02::3::5]", # IPv6 can only have one ::
"[FADF:01]", # Not properly compacted (missing a :)
"[FADF:01%en0]", # Not properly compacted (missing a :), Invalid ZoneID
"[FADF::01%]", # Empty Zone ID
"localhost:80:80:80", # Too many ports
"256.256.256.256", # Invalid IPv4 Address
SNOWMAN.decode("utf-8"),
]
equivalent_hostnames = [
"example.com",
"eXample.com",
"example.COM",
"EXAMPLE.com",
"ExAMPLE.com",
"eXample.COM",
"example.COM",
"EXAMPLE.COM",
"ExAMPLE.COM",
]
equivalent_schemes = [
"https",
"HTTPS",
"HttPs",
"hTTpS",
"HtTpS",
]
equivalent_schemes_and_hostnames = list(
itertools.product(
equivalent_schemes,
equivalent_hostnames,
)
)
@pytest.fixture(params=valid_hosts)
def basic_uri(request):
return "http://%s" % request.param
@pytest.fixture(params=equivalent_schemes_and_hostnames)
def uri_to_normalize(request):
return "%s://%s" % request.param
@pytest.fixture(params=valid_hosts)
def basic_uri_with_port(request):
return "ftp://%s:21" % request.param
@pytest.fixture(params=valid_hosts)
def uri_with_port_and_userinfo(request):
return "ssh://user:pass@%s:22" % request.param
@pytest.fixture(params=valid_hosts)
def uri_with_port_and_tricky_userinfo(request):
return "ssh://{}@{}:22".format("user%20!=:pass", request.param)
@pytest.fixture(params=valid_hosts)
def basic_uri_with_path(request):
return "http://%s/path/to/resource" % request.param
@pytest.fixture(params=valid_hosts)
def uri_with_path_and_query(request):
return "http://%s/path/to/resource?key=value" % request.param
@pytest.fixture(params=valid_hosts)
def uri_with_everything(request):
return "https://user:pass@%s:443/path/to/resource?key=value#fragment" % (
request.param
)
@pytest.fixture(params=valid_hosts)
def relative_uri(request):
return "//%s" % request.param
@pytest.fixture
def absolute_path_uri():
return "/path/to/file"
@pytest.fixture(params=invalid_hosts)
def invalid_uri(request):
return "https://%s" % request.param
@pytest.fixture(params=valid_hosts)
def uri_path_with_percent(request):
return "https://%s/%% " % request.param
@pytest.fixture(params=valid_hosts)
def uri_query_with_percent(request):
return "https://%s?a=%%" % request.param
@pytest.fixture(params=valid_hosts)
def uri_fragment_with_percent(request):
return "https://%s#perc%%ent" % request.param
@pytest.fixture(params=equivalent_schemes)
def scheme_only(request):
return "%s:" % request.param
sys.path.insert(0, ".")
|