aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2020-04-19 17:44:17 +0200
committerGitHub <noreply@github.com>2020-04-19 17:44:17 +0200
commit3c1a184c5d440e08726d758ba4693f4a51e50433 (patch)
treefa2297f519df360922760d7068ca0e0e15505980 /test
parent2774928319b706d8b6f85919f8811776342986c9 (diff)
parentca74ec3c774345bccc0e4e90fe6c231ce598663c (diff)
downloadmitmproxy-3c1a184c5d440e08726d758ba4693f4a51e50433.tar.gz
mitmproxy-3c1a184c5d440e08726d758ba4693f4a51e50433.tar.bz2
mitmproxy-3c1a184c5d440e08726d758ba4693f4a51e50433.zip
Merge pull request #3929 from sarthak212/colorizejson
colorize json
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/contentviews/test_json.py37
1 files changed, 32 insertions, 5 deletions
diff --git a/test/mitmproxy/contentviews/test_json.py b/test/mitmproxy/contentviews/test_json.py
index 5e87b570..2b5bf86a 100644
--- a/test/mitmproxy/contentviews/test_json.py
+++ b/test/mitmproxy/contentviews/test_json.py
@@ -1,16 +1,43 @@
+from hypothesis import given
+from hypothesis.strategies import binary
+
from mitmproxy.contentviews import json
from . import full_eval
-def test_pretty_json():
- assert json.pretty_json(b'{"foo": 1}')
- assert not json.pretty_json(b"moo")
- assert json.pretty_json(b'{"foo" : "\xe4\xb8\x96\xe7\x95\x8c"}') # utf8 with chinese characters
- assert not json.pretty_json(b'{"foo" : "\xFF"}')
+def test_parse_json():
+ assert json.parse_json(b'{"foo": 1}')
+ assert json.parse_json(b'null') is None
+ assert json.parse_json(b"moo") is json.PARSE_ERROR
+ assert json.parse_json(b'{"foo" : "\xe4\xb8\x96\xe7\x95\x8c"}') # utf8 with chinese characters
+ assert json.parse_json(b'{"foo" : "\xFF"}') is json.PARSE_ERROR
+
+
+def test_format_json():
+ assert list(json.format_json({
+ "data": [
+ "str",
+ 42,
+ True,
+ False,
+ None,
+ {},
+ []
+ ]
+ }))
def test_view_json():
v = full_eval(json.ViewJSON())
+ assert v(b"null")
assert v(b"{}")
assert not v(b"{")
assert v(b"[1, 2, 3, 4, 5]")
+ assert v(b'{"foo" : 3}')
+ assert v(b'{"foo": true, "nullvalue": null}')
+
+
+@given(binary())
+def test_view_json_doesnt_crash(data):
+ v = full_eval(json.ViewJSON())
+ v(data)