fix tests

This commit is contained in:
Maximilian Hils 2021-08-19 10:53:46 +02:00
parent b320c6aa14
commit 0585e690c4
11 changed files with 43 additions and 41 deletions

View File

@ -13,7 +13,7 @@ import tornado.web
import tornado.websocket
import mitmproxy.flow
import mitmproxy.tools.web.master # noqa
import mitmproxy.tools.web.master
from mitmproxy import certs, command, contentviews
from mitmproxy import flowfilter
from mitmproxy import http
@ -21,7 +21,6 @@ from mitmproxy import io
from mitmproxy import log
from mitmproxy import optmanager
from mitmproxy import version
from mitmproxy.addons import export
from mitmproxy.http import HTTPFlow
from mitmproxy.tcp import TCPFlow, TCPMessage
from mitmproxy.tools.console.common import SYMBOL_MARK, render_marker
@ -533,7 +532,7 @@ class ExecuteCommand(RequestHandler):
result = self.master.commands.call_strings(cmd, args)
self.write({
"value": result,
"type": command.typename(type(result)) if result is not None else "none"
# "type": command.typename(type(result)) if result is not None else "none"
})
@ -621,7 +620,8 @@ class Application(tornado.web.Application):
(r"/flows/(?P<flow_id>[0-9a-f\-]+)/revert", RevertFlow),
(r"/flows/(?P<flow_id>[0-9a-f\-]+)/(?P<message>request|response|messages)/content.data", FlowContent),
(
r"/flows/(?P<flow_id>[0-9a-f\-]+)/(?P<message>request|response|messages)/content/(?P<content_view>[0-9a-zA-Z\-\_%]+)(?:\.json)?",
r"/flows/(?P<flow_id>[0-9a-f\-]+)/(?P<message>request|response|messages)/"
r"content/(?P<content_view>[0-9a-zA-Z\-\_%]+)(?:\.json)?",
FlowContentView),
(r"/clear", ClearAll),
(r"/options(?:\.json)?", Options),

View File

@ -41,5 +41,5 @@ def test_simple():
def test_render_priority():
v = css.ViewCSS()
assert v.render_priority(b"", content_type="text/css")
assert not v.render_priority(b"", content_type="text/plain")
assert v.render_priority(b"data", content_type="text/css")
assert not v.render_priority(b"data", content_type="text/plain")

View File

@ -31,7 +31,7 @@ def test_format_xml(filename, tdata):
def test_render_priority():
v = javascript.ViewJavaScript()
assert v.render_priority(b"", content_type="application/x-javascript")
assert v.render_priority(b"", content_type="application/javascript")
assert v.render_priority(b"", content_type="text/javascript")
assert not v.render_priority(b"", content_type="text/plain")
assert v.render_priority(b"data", content_type="application/x-javascript")
assert v.render_priority(b"data", content_type="application/javascript")
assert v.render_priority(b"data", content_type="text/javascript")
assert not v.render_priority(b"data", content_type="text/plain")

View File

@ -45,8 +45,8 @@ def test_view_json_doesnt_crash(data):
def test_render_priority():
v = json.ViewJSON()
assert v.render_priority(b"", content_type="application/json")
assert v.render_priority(b"", content_type="application/json-rpc")
assert v.render_priority(b"", content_type="application/vnd.api+json")
assert v.render_priority(b"", content_type="application/acme+json")
assert not v.render_priority(b"", content_type="text/plain")
assert v.render_priority(b"data", content_type="application/json")
assert v.render_priority(b"data", content_type="application/json-rpc")
assert v.render_priority(b"data", content_type="application/vnd.api+json")
assert v.render_priority(b"data", content_type="application/acme+json")
assert not v.render_priority(b"data", content_type="text/plain")

View File

@ -48,6 +48,6 @@ def test_view_msgpack_doesnt_crash(data):
def test_render_priority():
v = msgpack.ViewMsgPack()
assert v.render_priority(b"", content_type="application/msgpack")
assert v.render_priority(b"", content_type="application/x-msgpack")
assert not v.render_priority(b"", content_type="text/plain")
assert v.render_priority(b"data", content_type="application/msgpack")
assert v.render_priority(b"data", content_type="application/x-msgpack")
assert not v.render_priority(b"data", content_type="text/plain")

View File

@ -22,5 +22,5 @@ Larry
def test_render_priority():
v = multipart.ViewMultipart()
assert v.render_priority(b"", content_type="multipart/form-data")
assert not v.render_priority(b"", content_type="text/plain")
assert v.render_priority(b"data", content_type="multipart/form-data")
assert not v.render_priority(b"data", content_type="text/plain")

View File

@ -32,6 +32,6 @@ def test_format_pbuf(filename, tdata):
def test_render_priority():
v = protobuf.ViewProtobuf()
assert v.render_priority(b"", content_type="application/x-protobuf")
assert v.render_priority(b"", content_type="application/x-protobuffer")
assert not v.render_priority(b"", content_type="text/plain")
assert v.render_priority(b"data", content_type="application/x-protobuf")
assert v.render_priority(b"data", content_type="application/x-protobuffer")
assert not v.render_priority(b"data", content_type="text/plain")

View File

@ -17,5 +17,5 @@ def test_view_urlencoded():
def test_render_priority():
v = urlencoded.ViewURLEncoded()
assert v.render_priority(b"", content_type="application/x-www-form-urlencoded")
assert not v.render_priority(b"", content_type="text/plain")
assert v.render_priority(b"data", content_type="application/x-www-form-urlencoded")
assert not v.render_priority(b"data", content_type="text/plain")

View File

@ -22,6 +22,6 @@ def test_wbxml(tdata):
def test_render_priority():
v = wbxml.ViewWBXML()
assert v.render_priority(b"", content_type="application/vnd.wap.wbxml")
assert v.render_priority(b"", content_type="application/vnd.ms-sync.wbxml")
assert not v.render_priority(b"", content_type="text/plain")
assert v.render_priority(b"data", content_type="application/vnd.wap.wbxml")
assert v.render_priority(b"data", content_type="application/vnd.ms-sync.wbxml")
assert not v.render_priority(b"data", content_type="text/plain")

View File

@ -38,8 +38,8 @@ def test_format_xml(filename, tdata):
def test_render_priority():
v = xml_html.ViewXmlHtml()
assert v.render_priority(b"", content_type="text/xml")
assert v.render_priority(b"", content_type="text/xml")
assert v.render_priority(b"", content_type="text/html")
assert not v.render_priority(b"", content_type="text/plain")
assert v.render_priority(b"data", content_type="text/xml")
assert v.render_priority(b"data", content_type="text/xml")
assert v.render_priority(b"data", content_type="text/html")
assert not v.render_priority(b"data", content_type="text/plain")
assert v.render_priority(b"<html/>")

View File

@ -14,14 +14,14 @@ import pytest
from mitmproxy.http import Headers
import tornado.testing # noqa
from tornado import httpclient # noqa
from tornado import websocket # noqa
import tornado.testing
from tornado import httpclient
from tornado import websocket
from mitmproxy import options, optmanager # noqa
from mitmproxy.test import tflow # noqa
from mitmproxy.tools.web import app # noqa
from mitmproxy.tools.web import master as webmaster # noqa
from mitmproxy import options, optmanager
from mitmproxy.test import tflow
from mitmproxy.tools.web import app
from mitmproxy.tools.web import master as webmaster
@pytest.fixture(scope="module")
@ -216,7 +216,9 @@ class TestApp(tornado.testing.AsyncHTTPTestCase):
).headers["Content-Disposition"] == 'attachment; filename=bar.jpg'
f.response.content = b""
assert self.fetch("/flows/42/response/content.data").code == 400
r = self.fetch("/flows/42/response/content.data")
assert r.code == 200
assert r.body == b""
f.revert()
@ -268,7 +270,7 @@ class TestApp(tornado.testing.AsyncHTTPTestCase):
assert resp.code == 500
resp = self.fetch("/commands/commands.history.get", method="POST")
assert resp.code == 200
assert get_json(resp) == ["unknown", "commands.history.get"]
assert get_json(resp) == {"value": []}
def test_events(self):
resp = self.fetch("/events")