Exemplo n.º 1
0
    def test_parse_url_bytes_to_str_python_2(self):
        url = parse_url(b"https://www.google.com/")
        assert url == Url("https", host="www.google.com", path="/")

        assert isinstance(url.scheme, str)
        assert isinstance(url.host, str)
        assert isinstance(url.path, str)
Exemplo n.º 2
0
    def test_parse_url_unicode_python_2(self):
        url = parse_url(u"https://www.google.com/")
        assert url == Url(u"https", host=u"www.google.com", path=u"/")

        assert isinstance(url.scheme, six.text_type)
        assert isinstance(url.host, six.text_type)
        assert isinstance(url.path, six.text_type)
Exemplo n.º 3
0
    def test_control_characters_are_percent_encoded(self, char):
        percent_char = "%" + (hex(ord(char))[2:].zfill(2).upper())
        url = parse_url(
            "http://user{0}@example.com/path{0}?query{0}#fragment{0}".format(char)
        )

        assert url == Url(
            "http",
            auth="user" + percent_char,
            host="example.com",
            path="/path" + percent_char,
            query="query" + percent_char,
            fragment="fragment" + percent_char,
        )
Exemplo n.º 4
0
 def test_invalid_url(self, url):
     with pytest.raises(LocationParseError):
         parse_url(url)
Exemplo n.º 5
0
 def test_invalid_host(self, location):
     with pytest.raises(LocationParseError):
         parse_url(location)
Exemplo n.º 6
0
 def test_parse_url_bytes_type_error_python_3(self):
     with pytest.raises(TypeError):
         parse_url(b"https://www.google.com/")
Exemplo n.º 7
0
 def test_url_vulnerabilities(self, url, expected_url):
     if expected_url is False:
         with pytest.raises(LocationParseError):
             parse_url(url)
     else:
         assert parse_url(url) == expected_url
Exemplo n.º 8
0
 def test_netloc(self, url, expected_netloc):
     assert parse_url(url).netloc == expected_netloc
Exemplo n.º 9
0
 def test_request_uri(self, url, expected_request_uri):
     returned_url = parse_url(url)
     assert returned_url.request_uri == expected_request_uri
Exemplo n.º 10
0
 def test_parse_url_negative_port(self):
     with pytest.raises(LocationParseError):
         parse_url("https://www.google.com:-80/")
Exemplo n.º 11
0
 def test_parse_url_invalid_IPv6(self):
     with pytest.raises(LocationParseError):
         parse_url("[::1")
Exemplo n.º 12
0
 def test_parse_and_normalize_url_paths(self, url, expected_url):
     actual_url = parse_url(url)
     assert actual_url == expected_url
     assert actual_url.url == expected_url.url
Exemplo n.º 13
0
 def test_parse_url(self, url, expected_url):
     returned_url = parse_url(url)
     assert returned_url == expected_url
Exemplo n.º 14
0
 def test_parse_url_normalization(self, url, expected_normalized_url):
     """Assert parse_url normalizes the scheme/host, and only the scheme/host"""
     actual_normalized_url = parse_url(url).url
     assert actual_normalized_url == expected_normalized_url