Exemplo n.º 1
0
 def test_URISourceExpression_str_unicode(self):
     """Test URISourceExpression 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 = SourceExpressionParser().parse(url)
     assert parsed == URISourceExpression("http", "handbook5.com", None,
                                          unicodePath)
     assert str(parsed) == url  # must use quoted version
Exemplo n.º 2
0
 def test_parse_uri_full(self):
     exprStr = "http://seclab.nu:80/path"
     srcExpr = SourceExpressionParser().parse(exprStr)
     assert srcExpr == URISourceExpression("http", "seclab.nu", 80, "/path")
     assert srcExpr.getType() == "uri"
     assert srcExpr.getScheme() == "http"
     assert srcExpr.getHost() == "seclab.nu"
     assert srcExpr.getPort() == 80
     assert srcExpr.getPath() == "/path"
     assert str(srcExpr) == exprStr
Exemplo n.º 3
0
 def test_parse_uri_scheme(self):
     exprStr = "chrome-extension:"
     srcExpr = SourceExpressionParser().parse(exprStr)
     assert srcExpr == URISourceExpression("chrome-extension", None, None,
                                           None)
     assert srcExpr.getType() == "uri"
     assert srcExpr.getScheme() == "chrome-extension"
     assert srcExpr.getHost() == None
     assert srcExpr.getPort() == None
     assert srcExpr.getPath() == None
     assert str(srcExpr) == exprStr
Exemplo n.º 4
0
 def test_parse_uri_scheme(self):
     exprStr = "chrome-extension:"
     srcExpr = SourceExpressionParser().parse(exprStr)
     assert srcExpr == URISourceExpression("chrome-extension", None, None, None)
     assert srcExpr.getType() == "uri"
     assert srcExpr.getScheme() == "chrome-extension"
     assert srcExpr.getHost() == None
     assert srcExpr.getPort() == None
     assert srcExpr.getPath() == None
     assert str(srcExpr) == exprStr
Exemplo n.º 5
0
 def test_parse_uri_full(self):
     exprStr = "http://seclab.nu:80/path"
     srcExpr = SourceExpressionParser().parse(exprStr)
     assert srcExpr == URISourceExpression("http", "seclab.nu", 80, "/path")
     assert srcExpr.getType() == "uri"
     assert srcExpr.getScheme() == "http"
     assert srcExpr.getHost() == "seclab.nu"
     assert srcExpr.getPort() == 80
     assert srcExpr.getPath() == "/path"
     assert str(srcExpr) == exprStr
Exemplo n.º 6
0
 def test_parse_self(self):
     srcExpr = SourceExpressionParser().parse("'self'")
     assert srcExpr == SelfSourceExpression.SELF()
     assert srcExpr.getType() == "self"
     assert srcExpr == SourceExpressionParser().parse("'SELF'")
Exemplo n.º 7
0
 def test_parse_inline(self):
     srcExpr = SourceExpressionParser().parse("'unsafe-inline'")
     assert srcExpr == SourceExpression.UNSAFE_INLINE()
     assert srcExpr.getType() == "unsafe-inline"
     assert srcExpr == SourceExpressionParser().parse("'UNSAFE-INLINE'")
Exemplo n.º 8
0
 def test_parse_eval(self):
     srcExpr = SourceExpressionParser().parse("'unsafe-eval'")
     assert srcExpr == SourceExpression.UNSAFE_EVAL()
     assert srcExpr.getType() == "unsafe-eval"
     assert srcExpr == SourceExpressionParser().parse("'UNSAFE-EVAL'")
Exemplo n.º 9
0
 def test_parse_unsupported_scheme_fails(self):
     exprStr = "my-scheme://domain/path"
     srcExpr = SourceExpressionParser(knownSchemes=('http',
                                                    'https')).parse(exprStr)
     assert srcExpr == SourceExpression.INVALID()
Exemplo n.º 10
0
 def test_parse_uri_decoding(self):
     exprStr = "http://domain/path%20space"
     srcExpr = SourceExpressionParser().parse(exprStr)
     assert srcExpr == URISourceExpression("http", "domain", None,
                                           "/path space")
Exemplo n.º 11
0
 def test_parse_uri_scheme_starport(self):
     exprStr = "http://host:*/path"
     srcExpr = SourceExpressionParser().parse(exprStr)
     assert srcExpr == URISourceExpression("http", "host", "*", "/path")
Exemplo n.º 12
0
 def test_parse_inline(self):
     srcExpr = SourceExpressionParser().parse("'unsafe-inline'")
     assert srcExpr == SourceExpression.UNSAFE_INLINE()
     assert srcExpr.getType() == "unsafe-inline"
     assert srcExpr == SourceExpressionParser().parse("'UNSAFE-INLINE'")
Exemplo n.º 13
0
 def test_parse_uri_noport(self):
     exprStr = "https://seclab.nu/"
     srcExpr = SourceExpressionParser().parse(exprStr)
     assert srcExpr == URISourceExpression("https", "seclab.nu", None, "/")
Exemplo n.º 14
0
 def test_parse_eval(self):
     srcExpr = SourceExpressionParser().parse("'unsafe-eval'")
     assert srcExpr == SourceExpression.UNSAFE_EVAL()
     assert srcExpr.getType() == "unsafe-eval"
     assert srcExpr == SourceExpressionParser().parse("'UNSAFE-EVAL'")
Exemplo n.º 15
0
 def test_parse_uri_starsubdomain(self):
     exprStr = "http://*.seclab.nu"
     srcExpr = SourceExpressionParser().parse(exprStr)
     assert srcExpr == URISourceExpression("http", "*.seclab.nu", None,
                                           None)
Exemplo n.º 16
0
 def test_parse_uri_noscheme_port_path(self):
     exprStr = "seclab.nu:443/blah"
     srcExpr = SourceExpressionParser().parse(exprStr)
     assert srcExpr == URISourceExpression(None, "seclab.nu", 443, "/blah")
Exemplo n.º 17
0
 def test_parse_uri_noscheme(self):
     exprStr = "seclab.nu"
     srcExpr = SourceExpressionParser().parse(exprStr)
     assert srcExpr == URISourceExpression(None, "seclab.nu", None, None)
Exemplo n.º 18
0
 def test_parse_uri_star(self):
     exprStr = "*"
     srcExpr = SourceExpressionParser().parse(exprStr)
     assert srcExpr == URISourceExpression(None, "*", None, None)
Exemplo n.º 19
0
 def test_parse_uri_scheme_star_port_path(self):
     exprStr = "http://*:80/path"
     srcExpr = SourceExpressionParser(knownSchemes=('blubb',
                                                    'http')).parse(exprStr)
     assert srcExpr == URISourceExpression("http", "*", 80, "/path")
Exemplo n.º 20
0
 def test_parse_uri_nopath(self):
     exprStr = "http://localhost:8080"
     srcExpr = SourceExpressionParser().parse(exprStr)
     assert srcExpr == URISourceExpression("http", "localhost", 8080, None)
Exemplo n.º 21
0
 def test_parse_self(self):
     srcExpr = SourceExpressionParser().parse("'self'")
     assert srcExpr == SelfSourceExpression.SELF()
     assert srcExpr.getType() == "self"
     assert srcExpr == SourceExpressionParser().parse("'SELF'")