[230] | 1 | # -*- coding: utf-8 -*-
|
---|
| 2 | import itertools
|
---|
| 3 | import sys
|
---|
| 4 |
|
---|
| 5 | import pytest
|
---|
| 6 |
|
---|
| 7 | SNOWMAN = b"\xe2\x98\x83"
|
---|
| 8 |
|
---|
| 9 | valid_hosts = [
|
---|
| 10 | "[21DA:00D3:0000:2F3B:02AA:00FF:FE28:9C5A]",
|
---|
| 11 | "[::1]",
|
---|
| 12 | "[::1%25lo]", # With ZoneID
|
---|
| 13 | "[FF02:0:0:0:0:0:0:2%25en01]", # With ZoneID
|
---|
| 14 | "[FF02:30:0:0:0:0:0:5%25en1]", # With ZoneID
|
---|
| 15 | "[FF02:30:0:0:0:0:0:5%25%26]", # With ZoneID
|
---|
| 16 | "[FF02:30:0:0:0:0:0:5%2525]", # With ZoneID
|
---|
| 17 | "[21DA:D3:0:2F3B:2AA:FF:FE28:9C5A]",
|
---|
| 18 | "[FE80::2AA:FF:FE9A:4CA2]",
|
---|
| 19 | "[FF02::2]",
|
---|
| 20 | "[FFFF::]",
|
---|
| 21 | "[FF02:3::5]",
|
---|
| 22 | "[FF02:0:0:0:0:0:0:2]",
|
---|
| 23 | "[FF02:30:0:0:0:0:0:5]",
|
---|
| 24 | "127.0.0.1",
|
---|
| 25 | "www.example.com",
|
---|
| 26 | "localhost",
|
---|
| 27 | "http-bin.org",
|
---|
| 28 | "%2Fvar%2Frun%2Fsocket",
|
---|
| 29 | "6g9m8V6", # Issue #48
|
---|
| 30 | ]
|
---|
| 31 |
|
---|
| 32 | invalid_hosts = [
|
---|
| 33 | "[FF02::3::5]", # IPv6 can only have one ::
|
---|
| 34 | "[FADF:01]", # Not properly compacted (missing a :)
|
---|
| 35 | "[FADF:01%en0]", # Not properly compacted (missing a :), Invalid ZoneID
|
---|
| 36 | "[FADF::01%]", # Empty Zone ID
|
---|
| 37 | "localhost:80:80:80", # Too many ports
|
---|
| 38 | "256.256.256.256", # Invalid IPv4 Address
|
---|
| 39 | SNOWMAN.decode("utf-8"),
|
---|
| 40 | ]
|
---|
| 41 |
|
---|
| 42 | equivalent_hostnames = [
|
---|
| 43 | "example.com",
|
---|
| 44 | "eXample.com",
|
---|
| 45 | "example.COM",
|
---|
| 46 | "EXAMPLE.com",
|
---|
| 47 | "ExAMPLE.com",
|
---|
| 48 | "eXample.COM",
|
---|
| 49 | "example.COM",
|
---|
| 50 | "EXAMPLE.COM",
|
---|
| 51 | "ExAMPLE.COM",
|
---|
| 52 | ]
|
---|
| 53 | equivalent_schemes = [
|
---|
| 54 | "https",
|
---|
| 55 | "HTTPS",
|
---|
| 56 | "HttPs",
|
---|
| 57 | "hTTpS",
|
---|
| 58 | "HtTpS",
|
---|
| 59 | ]
|
---|
| 60 | equivalent_schemes_and_hostnames = list(
|
---|
| 61 | itertools.product(
|
---|
| 62 | equivalent_schemes,
|
---|
| 63 | equivalent_hostnames,
|
---|
| 64 | )
|
---|
| 65 | )
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | @pytest.fixture(params=valid_hosts)
|
---|
| 69 | def basic_uri(request):
|
---|
| 70 | return "http://%s" % request.param
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 | @pytest.fixture(params=equivalent_schemes_and_hostnames)
|
---|
| 74 | def uri_to_normalize(request):
|
---|
| 75 | return "%s://%s" % request.param
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | @pytest.fixture(params=valid_hosts)
|
---|
| 79 | def basic_uri_with_port(request):
|
---|
| 80 | return "ftp://%s:21" % request.param
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | @pytest.fixture(params=valid_hosts)
|
---|
| 84 | def uri_with_port_and_userinfo(request):
|
---|
| 85 | return "ssh://user:pass@%s:22" % request.param
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 | @pytest.fixture(params=valid_hosts)
|
---|
| 89 | def uri_with_port_and_tricky_userinfo(request):
|
---|
| 90 | return "ssh://%s@%s:22" % ("user%20!=:pass", request.param)
|
---|
| 91 |
|
---|
| 92 |
|
---|
| 93 | @pytest.fixture(params=valid_hosts)
|
---|
| 94 | def basic_uri_with_path(request):
|
---|
| 95 | return "http://%s/path/to/resource" % request.param
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 | @pytest.fixture(params=valid_hosts)
|
---|
| 99 | def uri_with_path_and_query(request):
|
---|
| 100 | return "http://%s/path/to/resource?key=value" % request.param
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 | @pytest.fixture(params=valid_hosts)
|
---|
| 104 | def uri_with_everything(request):
|
---|
| 105 | return "https://user:pass@%s:443/path/to/resource?key=value#fragment" % (
|
---|
| 106 | request.param
|
---|
| 107 | )
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | @pytest.fixture(params=valid_hosts)
|
---|
| 111 | def relative_uri(request):
|
---|
| 112 | return "//%s" % request.param
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 | @pytest.fixture
|
---|
| 116 | def absolute_path_uri():
|
---|
| 117 | return "/path/to/file"
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 | @pytest.fixture(params=invalid_hosts)
|
---|
| 121 | def invalid_uri(request):
|
---|
| 122 | return "https://%s" % request.param
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | @pytest.fixture(params=valid_hosts)
|
---|
| 126 | def uri_path_with_percent(request):
|
---|
| 127 | return "https://%s/%% " % request.param
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | @pytest.fixture(params=valid_hosts)
|
---|
| 131 | def uri_query_with_percent(request):
|
---|
| 132 | return "https://%s?a=%%" % request.param
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | @pytest.fixture(params=valid_hosts)
|
---|
| 136 | def uri_fragment_with_percent(request):
|
---|
| 137 | return "https://%s#perc%%ent" % request.param
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 | sys.path.insert(0, ".")
|
---|