Esempio 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
Esempio 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
Esempio 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
Esempio 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
Esempio 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
Esempio 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
Esempio 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
Esempio 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
Esempio 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,
         }
Esempio 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
Esempio 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
Esempio 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,
         }
Esempio 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
Esempio 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"
Esempio 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
Esempio 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'
Esempio 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
Esempio 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
Esempio 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
Esempio 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
Esempio 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'
Esempio 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'
Esempio 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
Esempio 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)
Esempio 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
Esempio 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'
Esempio 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
Esempio 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
Esempio 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),
    )
Esempio 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
Esempio 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
Esempio 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
Esempio 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
Esempio 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'
Esempio 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
Esempio 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
Esempio 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
Esempio 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
Esempio n. 39
0
def test_authority_normalization(authority, expected_authority):
    uri = URIReference(None, authority, None, None, None).normalize()
    assert uri.authority == expected_authority
Esempio 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)
Esempio 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
Esempio 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
Esempio n. 43
0
 def test_same_basic_uri(self, basic_uri):
     uri = URIReference.from_string(basic_uri)
     assert uri == uri
Esempio n. 44
0
def test_uri_comparison_raises_TypeError(basic_uri):
    uri = URIReference.from_string(basic_uri)
    with pytest.raises(TypeError):
        uri == 1
Esempio 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
Esempio n. 46
0
 def test_same_basic_uri(self, basic_uri):
     uri = URIReference.from_string(basic_uri)
     assert uri == uri
Esempio 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
Esempio 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
Esempio 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'
Esempio 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
Esempio 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
Esempio 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
Esempio 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
Esempio 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
Esempio 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
Esempio 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
Esempio n. 57
0
def test_hostname_normalization():
    assert URIReference(None, "EXAMPLE.COM", None, None,
                        None) == URIReference(None, "example.com", None, None,
                                              None)
Esempio 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
Esempio n. 59
0
def test_fragment_normalization():
    uri = URIReference(None, "example.com", None, None, "fiz%DF").normalize()
    assert uri.fragment == "fiz%DF"
Esempio 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