From 6a4f1ae7c7ea4b5036937312b837184162edaed3 Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Fri, 4 Mar 2016 03:10:29 +0530 Subject: Test har_extractor.response --- test/mitmproxy/data/har_extractor.har | 78 +++++++++++++++++++++++++++++++++++ test/mitmproxy/test_har_extractor.py | 27 ++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 test/mitmproxy/data/har_extractor.har (limited to 'test') diff --git a/test/mitmproxy/data/har_extractor.har b/test/mitmproxy/data/har_extractor.har new file mode 100644 index 00000000..2f5099b3 --- /dev/null +++ b/test/mitmproxy/data/har_extractor.har @@ -0,0 +1,78 @@ +{ + "test_response": { + "log": { + "__page_count__": 1, + "version": "1.2", + "creator": { + "comment": "", + "version": "0.1", + "name": "MITMPROXY HARExtractor" + }, + "pages": [ + { + "startedDateTime": "1993-08-24T14:41:12", + "id": "autopage_1", + "title": "http://address:22/path" + } + ], + "entries": [ + { + "pageref": "autopage_1", + "startedDateTime": "1993-08-24T14:41:12", + "cache": {}, + "request": { + "cookies": [], + "url": "http://address:22/path", + "queryString": [], + "headers": [ + { + "name": "header", + "value": "qvalue" + }, + { + "name": "content-length", + "value": "7" + } + ], + "headersSize": 35, + "httpVersion": "HTTP/1.1", + "method": "GET", + "bodySize": 7 + }, + "timings": { + "receive": 0, + "ssl": 1000, + "connect": 1000, + "send": 0, + "wait": 0 + }, + "time": 2000, + "response": { + "status": 200, + "cookies": [], + "statusText": "OK", + "content": { + "mimeType": "", + "compression": 0, + "size": 7 + }, + "headers": [ + { + "name": "content-length", + "value": "7" + }, + { + "name": "header-response", + "value": "svalue" + } + ], + "headersSize": 44, + "redirectURL": "", + "httpVersion": "HTTP/1.1", + "bodySize": 7 + } + } + ] + } + } +} \ No newline at end of file diff --git a/test/mitmproxy/test_har_extractor.py b/test/mitmproxy/test_har_extractor.py index da68ac4d..26a092e6 100644 --- a/test/mitmproxy/test_har_extractor.py +++ b/test/mitmproxy/test_har_extractor.py @@ -1,10 +1,37 @@ +import json +import netlib.tutils from . import tutils from mitmproxy import script, flow from examples import har_extractor +trequest = netlib.tutils.treq( + timestamp_start=746203272, + timestamp_end=746203272, +) + +tresponse = netlib.tutils.tresp( + timestamp_start=746203272, + timestamp_end=746203272, +) + + def test_start(): fm = flow.FlowMaster(None, flow.State()) ctx = script.ScriptContext(fm) tutils.raises(ValueError, har_extractor.start, ctx, []) + + +def test_response(): + fm = flow.FlowMaster(None, flow.State()) + ctx = script.ScriptContext(fm) + ctx.HARLog = har_extractor._HARLog([]) + ctx.seen_server = set() + + fl = tutils.tflow(req=trequest, resp=tresponse) + har_extractor.response(ctx, fl) + + with open(tutils.test_data.path("data/har_extractor.har")) as fp: + test_data = json.load(fp) + assert json.loads(ctx.HARLog.json()) == test_data["test_response"] -- cgit v1.2.3