Exemplo n.º 1
0
 def test_no_modification_partial_URI_scheme_host_path_query(self):
     """Simple test with no modification, splitting a partially specified URI."""
     uriString = "https://www.seclab.nu/path/file?query=here"
     uriExpected = URI("https", "www.seclab.nu", None, "/path/file",
                       "query=here")
     assert URIParser(addScheme=False, addPort=False, decodeEscapedCharacters=False) \
         .parse(uriString) == uriExpected
Exemplo n.º 2
0
 def test_addScheme_addPort_defaultScheme_schemePortMappings_partial_URI_host_path(
         self):
     """Test if scheme and port are added properly to partially specified URI."""
     uriString = "www.seclab.nu/path/file"
     uriExpected = URI("test-scheme", "www.seclab.nu", 333, "/path/file")
     assert URIParser(addScheme=True, defaultScheme="test-scheme", addPort=True, schemePortMappings={"test-scheme": 333}, decodeEscapedCharacters=False) \
         .parse(uriString) == uriExpected
Exemplo n.º 3
0
 def test_stripUserPassword_userOnly_URI_IPv4(self):
     """Check if user:password part properly removed (with IPv4 address)."""
     uriString = "http://[email protected]:80/index.php"
     uriExpected = URI("http", "123.123.123.123", 80, "/index.php")
     actual = URIParser(decodeEscapedCharacters=False) \
         .parse(uriString)
     assert actual == uriExpected
Exemplo n.º 4
0
 def test_no_modification_partial_URI_host_path(self):
     """Simple test with no modification, splitting a partially specified URI."""
     uriString = "www.seclab.nu/path/file"
     uriExpected = URI(None, "www.seclab.nu", None, "/path/file")
     actual = URIParser(addScheme=False, addPort=False, decodeEscapedCharacters=False) \
         .parse(uriString)
     assert actual == uriExpected
Exemplo n.º 5
0
 def test_str_unicode(self):
     """Test URI serialisation with unicode characters."""
     url = u'http://handbook5.com/a/a-security-analysis-of-amazon%E2%80%99s-elastic-compute-cloud-service-w14847.html'
     unicodePath = u"/a/a-security-analysis-of-amazon’s-elastic-compute-cloud-service-w14847.html"
     parsed = URIParser(decodeEscapedCharacters=True).parse(url)
     assert parsed == URI("http", "handbook5.com", None, unicodePath)
     assert str(parsed) == url  # must use quoted version
Exemplo n.º 6
0
 def test_addPort_schemePortMappingsNone_partial_URI_scheme_host(self):
     """Simple test with "adding" a None port, splitting a partially specified URI."""
     uriString = "chrome-extension://mkfokfffehpeedafpekjeddnmnjhmcmk"
     uriExpected = URI("chrome-extension",
                       "mkfokfffehpeedafpekjeddnmnjhmcmk", None, None)
     assert URIParser(addScheme=True, addPort=True, defaultPort=123, schemePortMappings={'chrome-extension': None}, decodeEscapedCharacters=False) \
         .parse(uriString) == uriExpected
Exemplo n.º 7
0
 def test_no_modification_partial_URI_data(self):
     """Data URIs use only the scheme and the host for the data. The data should not be converted to
     lowercase."""
     uriString = "data:image/png;base64,iVBORw0KGgoAAAA"
     uriExpected = URI("data", "image/png;base64,iVBORw0KGgoAAAA", None,
                       None)
     assert URIParser().parse(uriString) == uriExpected
Exemplo n.º 8
0
 def test_stripUserPassword_userOnly_URI(self):
     """Check if user:password part properly removed."""
     uriString = "http://[email protected]:80/index.php"
     uriExpected = URI("http", "www.seclab.nu", 80, "/index.php")
     actual = URIParser(decodeEscapedCharacters=False) \
         .parse(uriString)
     assert actual == uriExpected
Exemplo n.º 9
0
 def test_no_modification_partial_URI_scheme_host(self):
     """Simple test with no modification, splitting a partially specified URI."""
     uriString = "chrome-extension://mkfokfffehpeedafpekjeddnmnjhmcmk"
     uriExpected = URI("chrome-extension",
                       "mkfokfffehpeedafpekjeddnmnjhmcmk", None, None)
     assert URIParser(addScheme=False, addPort=False, decodeEscapedCharacters=False) \
             .parse(uriString) == uriExpected
Exemplo n.º 10
0
 def test_stripAnchor_full_URI(self):
     """Check if anchor part properly removed."""
     uriString = "http://www.seclab.nu:80/index.php?parameter=value&more#anchor"
     uriExpected = URI("http", "www.seclab.nu", 80, "/index.php",
                       "parameter=value&more")
     actual = URIParser(decodeEscapedCharacters=False) \
         .parse(uriString)
     assert actual == uriExpected
Exemplo n.º 11
0
 def test_decodeEscapedCharacters_full_URI(self):
     """Check if escaped characters in the path are correctly decoded."""
     uriString = "http://www.seclab.nu:80/a%20path/index.py?math=3%3D%281%2B1%29%2A1.5"
     uriExpected = URI("http", "www.seclab.nu", 80, "/a path/index.py",
                       "math=3%3D%281%2B1%29%2A1.5")
     actual = URIParser(decodeEscapedCharacters=True) \
         .parse(uriString)
     assert actual == uriExpected
Exemplo n.º 12
0
 def test_no_modification_partial_URI_host(self):
     """Simple test with no modification and only host in URI."""
     uriString = "www.seclab.nu"
     uriExpected = URI(None, "www.seclab.nu", None, None)
     assert URIParser(addScheme=False,
                      addPort=False).parse(uriString) == uriExpected
Exemplo n.º 13
0
 def test_no_modification_partial_URI_viewSource(self):
     """view-source: URIs are similar to data URIs."""
     uriString = "view-source:http://www.seclab.nu/page/"
     uriExpected = URI("view-source", "http://www.seclab.nu/page/", None,
                       None)
     assert URIParser().parse(uriString) == uriExpected
Exemplo n.º 14
0
 def test_underscore(self):
     """Checks that underscores in subdomains are parsed correctly."""
     uriString = "https://i_simwebjs_info.tlscdn.com/sweb/javascript.js"
     uriExpected = URI("https", "i_simwebjs_info.tlscdn.com", None,
                       "/sweb/javascript.js")
     assert URIParser(addPort=False).parse(uriString) == uriExpected
Exemplo n.º 15
0
 def test_invalid_URI(self):
     """Ensure that URI.INVALID is returned when an invalid URI is parsed."""
     uriString = "http://blah:blubb:baeh?"
     uriExpected = URI.INVALID()
     actual = URIParser().parse(uriString)
     assert actual == uriExpected
Exemplo n.º 16
0
 def test_no_modification_partial_URI_data_scheme_colon_slash_slash(self):
     """Ensure that an URI with only 'data' is parsed as the scheme with empty host name, not as host name."""
     uriString = "data://"
     uriExpected = URI("data", "", None, None)
     assert URIParser().parse(uriString) == uriExpected
Exemplo n.º 17
0
 def test_no_modification_partial_URI_about(self):
     """about: URIs are similar to data URIs."""
     uriString = "about:blank"
     uriExpected = URI("about", "blank", None, None)
     assert URIParser().parse(uriString) == uriExpected
Exemplo n.º 18
0
 def test_addScheme_portSchemeMappings_partial_URI_host_port_path(self):
     """Simple test with inferring the scheme from the port and port->scheme mapping, splitting a partially specified URI."""
     uriString = "www.seclab.nu:8080/path/file"
     uriExpected = URI("http", "www.seclab.nu", 8080, "/path/file")
     assert URIParser(addScheme=True, defaultScheme="https", portSchemeMappings={80: 'http', 8080: 'http'}, addPort=True, decodeEscapedCharacters=False) \
             .parse(uriString) == uriExpected
Exemplo n.º 19
0
 def test_no_modification_partial_URI_host_port_query(self):
     """Simple test with no modification and only host and port and query in URI."""
     uriString = "www.seclab.nu:80?query"
     uriExpected = URI(None, "www.seclab.nu", 80, None, "query")
     assert URIParser(addScheme=False,
                      addPort=False).parse(uriString) == uriExpected
Exemplo n.º 20
0
 def test_no_modification_partial_URI_data_scheme(self):
     """Ensure that an URI with only 'data' is parsed as the scheme with empty host name, not as host name."""
     uriString = "data"
     uriExpected = URI("data", "", None, None)
     assert URIParser(addScheme=False,
                      addPort=False).parse(uriString) == uriExpected
Exemplo n.º 21
0
 def test_addScheme_partial_URI_host_path(self):
     """Test if scheme is added properly to partially specified URI."""
     uriString = "www.seclab.nu/path/file"
     uriExpected = URI("test-scheme", "www.seclab.nu", None, "/path/file")
     assert URIParser(addScheme=True, defaultScheme="test-scheme", addPort=False, decodeEscapedCharacters=False) \
         .parse(uriString) == uriExpected
Exemplo n.º 22
0
 def test_empty_URI(self):
     """Ensure that URI.EMPTY is returned when a string with only whitespace is parsed."""
     uriString = " "
     uriExpected = URI.EMPTY()
     assert URIParser().parse(uriString) == uriExpected
Exemplo n.º 23
0
 def test_lowercase(self):
     """Checks that the scheme and host name are converted to lower case when parsing."""
     uriString = "Http://www.SecLab.nu/"
     uriExpected = URI("http", "www.seclab.nu", 80, "/")
     assert URIParser(addPort=True, schemePortMappings={'http': 80}) \
             .parse(uriString) == uriExpected
Exemplo n.º 24
0
 def test_default_full_URI(self):
     """Simple test with default parameters, splitting a fully specified URI."""
     uriString = "http://www.seclab.nu:80/path/a?param=true"
     uriExpected = URI("http", "www.seclab.nu", 80, "/path/a", "param=true")
     assert URIParser().parse(uriString) == uriExpected
Exemplo n.º 25
0
 def test_addPort_defaultPort_partial_URI_scheme_host_path(self):
     """Simple test with adding the default port, splitting a partially specified URI."""
     uriString = "https://www.seclab.nu/path/file"
     uriExpected = URI("https", "www.seclab.nu", 123, "/path/file")
     assert URIParser(addScheme=False, addPort=True, defaultPort=123, schemePortMappings={'http': 456}, decodeEscapedCharacters=False) \
         .parse(uriString) == uriExpected