Exemplo n.º 1
0
 def test_with_basic_and_relative_uris(self, basic_uri, relative_uri):
     R = URIReference.from_string(relative_uri)
     B = URIReference.from_string(basic_uri)
     T = R.resolve_with(basic_uri)
     assert T.scheme == B.scheme
     assert T.host == R.host
     assert T.path == R.path
Exemplo n.º 2
0
 def test_with_basic_and_relative_uris(self, basic_uri, relative_uri):
     R = URIReference.from_string(relative_uri)
     B = URIReference.from_string(basic_uri)
     T = R.resolve_with(basic_uri)
     assert T.scheme == B.scheme
     assert T.host == R.host
     assert T.path == R.path
Exemplo n.º 3
0
 def test_with_basic_uri_and_relative_path(self, basic_uri):
     R = URIReference.from_string('foo/bar/bogus')
     B = URIReference.from_string(basic_uri).normalize()
     T = R.resolve_with(B)
     assert T.scheme == B.scheme
     assert T.host == B.host
     assert T.path == '/' + R.path
Exemplo n.º 4
0
 def test_with_basic_uri_and_relative_path(self, basic_uri):
     R = URIReference.from_string('foo/bar/bogus')
     B = URIReference.from_string(basic_uri).normalize()
     T = R.resolve_with(B)
     assert T.scheme == B.scheme
     assert T.host == B.host
     assert T.path == '/' + R.path
Exemplo n.º 5
0
 def test_with_basic_and_absolute_path_uris(self, basic_uri,
                                            absolute_path_uri):
     R = URIReference.from_string(absolute_path_uri)
     B = URIReference.from_string(basic_uri).normalize()
     T = R.resolve_with(B)
     assert T.scheme == B.scheme
     assert T.host == B.host
     assert T.path == R.path
Exemplo n.º 6
0
 def test_with_basic_and_absolute_path_uris(self, basic_uri,
                                            absolute_path_uri):
     R = URIReference.from_string(absolute_path_uri)
     B = URIReference.from_string(basic_uri).normalize()
     T = R.resolve_with(B)
     assert T.scheme == B.scheme
     assert T.host == B.host
     assert T.path == R.path
Exemplo n.º 7
0
    def test_basic_uri_with_path_and_relative_path(self, basic_uri_with_path):
        R = URIReference.from_string('foo/bar/bogus')
        B = URIReference.from_string(basic_uri_with_path).normalize()
        T = R.resolve_with(B)
        assert T.scheme == B.scheme
        assert T.host == B.host

        index = B.path.rfind('/')
        assert T.path == B.path[:index] + '/' + R.path
Exemplo n.º 8
0
    def test_basic_uri_with_path_and_relative_path(self, basic_uri_with_path):
        R = URIReference.from_string('foo/bar/bogus')
        B = URIReference.from_string(basic_uri_with_path).normalize()
        T = R.resolve_with(B)
        assert T.scheme == B.scheme
        assert T.host == B.host

        index = B.path.rfind('/')
        assert T.path == B.path[:index] + '/' + R.path
Exemplo n.º 9
0
 def test_handles_absolute_path_uri(self, absolute_path_uri):
     """Test that URIReference can handle a path-only URI."""
     uri = URIReference.from_string(absolute_path_uri)
     assert uri.path == absolute_path_uri
     assert uri.authority_info() == {
         'userinfo': None,
         'host': None,
         'port': None,
         }
Exemplo n.º 10
0
def test_merge_paths_with_base_authority_without_path():
    """Demonstrate merging with a base URI without an authority or path."""
    base = URIReference(scheme=None,
                        authority='authority',
                        path=None,
                        query=None,
                        fragment=None)
    expected = '/relative'
    assert merge_paths(base, 'relative') == expected
Exemplo n.º 11
0
def test_merge_paths_with_base_path_without_base_authority():
    """Demonstrate merging with a base URI without an authority."""
    base = URIReference(scheme=None,
                        authority=None,
                        path='/foo/bar/bogus',
                        query=None,
                        fragment=None)
    expected = '/foo/bar/relative'
    assert merge_paths(base, 'relative') == expected
Exemplo n.º 12
0
 def test_handles_absolute_path_uri(self, absolute_path_uri):
     """Test that URIReference can handle a path-only URI."""
     uri = URIReference.from_string(absolute_path_uri)
     assert uri.path == absolute_path_uri
     assert uri.authority_info() == {
         'userinfo': None,
         'host': None,
         'port': None,
         }
Exemplo n.º 13
0
 def test_handles_scheme_and_path_uri(self, scheme_and_path_uri):
     """Test that URIReference can handle a `scheme:path` URI."""
     uri = URIReference.from_string(scheme_and_path_uri)
     assert uri.path == '*****@*****.**'
     assert uri.scheme == 'mailto'
     assert uri.query is None
     assert uri.host is None
     assert uri.port is None
     assert uri.userinfo is None
     assert uri.authority is None
Exemplo n.º 14
0
def test_wide_domain_bypass_check():
    """Verify we properly parse/handle the authority.

    See also:
    https://bugs.xdavidhu.me/google/2020/03/08/the-unexpected-google-wide-domain-check-bypass/
    """
    url = "https://*****:*****@xdavidhu.me\\test.corp.google.com:8080/path/to/something?param=value#hash"
    ref = URIReference.from_string(url)
    assert ref.scheme == "https"
    assert ref.host == "xdavidhu.me"
Exemplo n.º 15
0
def test_merge_paths_with_base_authority_and_path():
    """Demonstrate merging with a base URI with an authority and path."""
    base = URIReference(
        scheme=None,
        authority="authority",
        path="/foo/bar/bogus",
        query=None,
        fragment=None,
    )
    expected = "/foo/bar/relative"
    assert merge_paths(base, "relative") == expected
Exemplo n.º 16
0
 def test_handles_uri_with_everything(self, uri_with_everything):
     """
     Test that URIReference can handle and with everything in it.
     """
     uri = URIReference.from_string(uri_with_everything)
     assert uri.scheme == 'https'
     assert uri.path == '/path/to/resource'
     assert uri.query == 'key=value'
     assert uri.fragment == 'fragment'
     assert uri.userinfo == 'user:pass'
     assert uri.port == '443'
Exemplo n.º 17
0
 def test_handles_basic_uri(self, basic_uri):
     """Test that URIReference can handle a simple URI."""
     uri = URIReference.from_string(basic_uri)
     assert uri.scheme == 'http'
     assert uri.authority == basic_uri[7:]  # len('http://')
     assert uri.host == uri.authority
     assert uri.path is None
     assert uri.query is None
     assert uri.fragment is None
     assert uri.port is None
     assert uri.userinfo is None
Exemplo n.º 18
0
 def test_handles_basic_uri_with_port(self, basic_uri_with_port):
     """Test that URIReference can handle a simple URI with a port."""
     uri = URIReference.from_string(basic_uri_with_port)
     assert uri.scheme == 'ftp'
     assert uri.authority == basic_uri_with_port[6:]  # len('ftp://')
     assert uri.host != uri.authority
     assert uri.port == '21'
     assert uri.path is None
     assert uri.query is None
     assert uri.fragment is None
     assert uri.userinfo is None
Exemplo n.º 19
0
 def test_handles_uri_with_path_and_query(self, uri_with_path_and_query):
     """
     Test that URIReference can handle a URI with a path and query.
     """
     uri = URIReference.from_string(uri_with_path_and_query)
     assert uri.scheme == 'http'
     assert uri.host == uri.authority
     assert uri.path == '/path/to/resource'
     assert uri.query == 'key=value'
     assert uri.fragment is None
     assert uri.userinfo is None
     assert uri.port is None
Exemplo n.º 20
0
 def test_handles_basic_uri_with_path(self, basic_uri_with_path):
     """Test that URIReference can handle a URI with a path."""
     uri = URIReference.from_string(basic_uri_with_path)
     assert uri.scheme == 'http'
     assert basic_uri_with_path == (uri.scheme + '://' + uri.authority
                                    + uri.path)
     assert uri.host == uri.authority
     assert uri.path == '/path/to/resource'
     assert uri.query is None
     assert uri.fragment is None
     assert uri.userinfo is None
     assert uri.port is None
Exemplo n.º 21
0
 def test_handles_uri_with_port_and_userinfo(
         self, uri_with_port_and_userinfo):
     """
     Test that URIReference can handle a URI with a port and userinfo.
     """
     uri = URIReference.from_string(uri_with_port_and_userinfo)
     assert uri.scheme == 'ssh'
     # 6 == len('ftp://')
     assert uri.authority == uri_with_port_and_userinfo[6:]
     assert uri.host != uri.authority
     assert uri.port == '22'
     assert uri.path is None
     assert uri.query is None
     assert uri.fragment is None
     assert uri.userinfo == 'user:pass'
Exemplo n.º 22
0
 def test_resolve_pathless_fragment(self, basic_uri):
     R = URIReference.from_string('#fragment')
     B = URIReference.from_string(basic_uri)
     T = R.resolve_with(B)
     assert T.path is None
     assert T.fragment == 'fragment'
Exemplo n.º 23
0
 def test_basic_uri_requiring_scheme(self, basic_uri):
     uri = URIReference.from_string(basic_uri)
     assert uri.is_valid(require_scheme=True) is True
Exemplo n.º 24
0
 def test_uri_with_everything_raises_exception(self, uri_with_everything):
     R = URIReference.from_string('foo/bar/bogus')
     B = URIReference.from_string(uri_with_everything)
     with pytest.raises(ResolutionError):
         R.resolve_with(B)
Exemplo n.º 25
0
 def test_attributes_catch_InvalidAuthority(self, invalid_uri):
     """Test that an invalid IPv6 is caught by authority_info()."""
     uri = URIReference.from_string(invalid_uri)
     assert uri.host is None
     assert uri.userinfo is None
     assert uri.port is None
Exemplo n.º 26
0
 def test_resolve_pathless_fragment(self, basic_uri):
     R = URIReference.from_string('#fragment')
     B = URIReference.from_string(basic_uri)
     T = R.resolve_with(B)
     assert T.path is None
     assert T.fragment == 'fragment'
Exemplo n.º 27
0
 def test_different_basic_uris(self, basic_uri, basic_uri_with_port):
     uri = URIReference.from_string(basic_uri)
     assert (uri == URIReference.from_string(basic_uri_with_port)) is False
Exemplo n.º 28
0
 def test_basic_uri_with_port_is_valid(self, basic_uri_with_port):
     uri = URIReference.from_string(basic_uri_with_port)
     assert uri.is_valid() is True
Exemplo n.º 29
0
def uris(request):
    to_norm, normalized = request.param
    return (
        URIReference(None, None, to_norm, None, None),
        URIReference(None, None, normalized, None, None),
    )
Exemplo n.º 30
0
 def test_basic_uri_requiring_authority(self, basic_uri):
     uri = URIReference.from_string(basic_uri)
     assert uri.is_valid(require_authority=True) is True
Exemplo n.º 31
0
 def test_uri_with_everything_requiring_fragment(self,
                                                 uri_with_everything):
     uri = URIReference.from_string(uri_with_everything)
     assert uri.is_valid(require_fragment=True) is True
Exemplo n.º 32
0
 def test_basic_uri_requiring_scheme(self, basic_uri):
     uri = URIReference.from_string(basic_uri)
     assert uri.is_valid(require_scheme=True) is True
Exemplo n.º 33
0
def test_empty_querystrings_persist():
    url = 'https://httpbin.org/get?'
    ref = URIReference.from_string(url)
    assert ref.query == ''
    assert ref.unsplit() == url
Exemplo n.º 34
0
 def test_resolve_pathless_query(self, basic_uri):
     R = URIReference.from_string('?query')
     B = URIReference.from_string(basic_uri)
     T = R.resolve_with(B)
     assert T.path is None
     assert T.query == 'query'
Exemplo n.º 35
0
 def test_uri_with_everything_requiring_fragment(self,
                                                 uri_with_everything):
     uri = URIReference.from_string(uri_with_everything)
     assert uri.is_valid(require_fragment=True) is True
Exemplo n.º 36
0
 def test_uri_with_port_and_userinfo_is_valid(self,
                                              uri_with_port_and_userinfo):
     uri = URIReference.from_string(uri_with_port_and_userinfo)
     assert uri.is_valid() is True
Exemplo n.º 37
0
 def test_basic_uri_with_path_is_valid(self, basic_uri_with_path):
     uri = URIReference.from_string(basic_uri_with_path)
     assert uri.is_valid() is True
Exemplo n.º 38
0
 def test_basic_uri_resolves_itself(self, basic_uri):
     R = URIReference.from_string(basic_uri)
     B = URIReference.from_string(basic_uri)
     T = R.resolve_with(B)
     assert T == B
Exemplo n.º 39
0
def test_authority_normalization(authority, expected_authority):
    uri = URIReference(None, authority, None, None, None).normalize()
    assert uri.authority == expected_authority
Exemplo n.º 40
0
 def test_uri_with_everything_raises_exception(self, uri_with_everything):
     R = URIReference.from_string('foo/bar/bogus')
     B = URIReference.from_string(uri_with_everything)
     with pytest.raises(ResolutionError):
         R.resolve_with(B)
Exemplo n.º 41
0
 def test_basic_uris_with_paths_are_absolute(self, basic_uri_with_path):
     uri = URIReference.from_string(basic_uri_with_path)
     assert uri.is_absolute() is True
Exemplo n.º 42
0
 def test_absolute_paths_are_not_absolute_uris(self, absolute_path_uri):
     uri = URIReference.from_string(absolute_path_uri)
     assert uri.is_absolute() is False
Exemplo n.º 43
0
 def test_same_basic_uri(self, basic_uri):
     uri = URIReference.from_string(basic_uri)
     assert uri == uri
Exemplo n.º 44
0
def test_uri_comparison_raises_TypeError(basic_uri):
    uri = URIReference.from_string(basic_uri)
    with pytest.raises(TypeError):
        uri == 1
Exemplo n.º 45
0
 def test_basic_uri_resolves_itself(self, basic_uri):
     R = URIReference.from_string(basic_uri)
     B = URIReference.from_string(basic_uri)
     T = R.resolve_with(B)
     assert T == B
Exemplo n.º 46
0
 def test_same_basic_uri(self, basic_uri):
     uri = URIReference.from_string(basic_uri)
     assert uri == uri
Exemplo n.º 47
0
 def test_differing_schemes(self, basic_uri):
     R = URIReference.from_string('https://example.com/path')
     B = URIReference.from_string(basic_uri)
     T = R.resolve_with(B)
     assert T.scheme == R.scheme
Exemplo n.º 48
0
 def test_different_basic_uris(self, basic_uri, basic_uri_with_port):
     uri = URIReference.from_string(basic_uri)
     assert (uri == URIReference.from_string(basic_uri_with_port)) is False
Exemplo n.º 49
0
 def test_resolve_pathless_query(self, basic_uri):
     R = URIReference.from_string('?query')
     B = URIReference.from_string(basic_uri)
     T = R.resolve_with(B)
     assert T.path is None
     assert T.query == 'query'
Exemplo n.º 50
0
 def test_attributes_catch_InvalidAuthority(self, invalid_uri):
     """Test that an invalid IPv6 is caught by authority_info()."""
     uri = URIReference.from_string(invalid_uri)
     assert uri.host is None
     assert uri.userinfo is None
     assert uri.port is None
Exemplo n.º 51
0
 def test_basic_uri_requiring_authority(self, basic_uri):
     uri = URIReference.from_string(basic_uri)
     assert uri.is_valid(require_authority=True) is True
Exemplo n.º 52
0
 def test_basic_uris_with_paths_are_absolute(self, basic_uri_with_path):
     uri = URIReference.from_string(basic_uri_with_path)
     assert uri.is_absolute() is True
Exemplo n.º 53
0
 def test_uri_with_port_and_userinfo_is_valid(self,
                                              uri_with_port_and_userinfo):
     uri = URIReference.from_string(uri_with_port_and_userinfo)
     assert uri.is_valid() is True
Exemplo n.º 54
0
 def test_uri_with_everything_are_not_absolute(self, uri_with_everything):
     uri = URIReference.from_string(uri_with_everything)
     assert uri.is_absolute() is False
Exemplo n.º 55
0
 def test_uri_with_path_and_query_is_valid(self, uri_with_path_and_query):
     uri = URIReference.from_string(uri_with_path_and_query)
     assert uri.is_valid() is True
Exemplo n.º 56
0
 def test_absolute_paths_are_not_absolute_uris(self, absolute_path_uri):
     uri = URIReference.from_string(absolute_path_uri)
     assert uri.is_absolute() is False
Exemplo n.º 57
0
def test_hostname_normalization():
    assert URIReference(None, "EXAMPLE.COM", None, None,
                        None) == URIReference(None, "example.com", None, None,
                                              None)
Exemplo n.º 58
0
 def test_uri_with_everything_are_not_absolute(self, uri_with_everything):
     uri = URIReference.from_string(uri_with_everything)
     assert uri.is_absolute() is False
Exemplo n.º 59
0
def test_fragment_normalization():
    uri = URIReference(None, "example.com", None, None, "fiz%DF").normalize()
    assert uri.fragment == "fiz%DF"
Exemplo n.º 60
0
 def test_differing_schemes(self, basic_uri):
     R = URIReference.from_string('https://example.com/path')
     B = URIReference.from_string(basic_uri)
     T = R.resolve_with(B)
     assert T.scheme == R.scheme