aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorShadab Zafar <dufferzafar0@gmail.com>2016-03-04 03:10:29 +0530
committerShadab Zafar <dufferzafar0@gmail.com>2016-03-04 03:10:29 +0530
commit6a4f1ae7c7ea4b5036937312b837184162edaed3 (patch)
tree8a31d9cc856c952387857e46e222934ffe81b24d /test
parent7108d727055324d08ba82cbce5c91173ee599201 (diff)
downloadmitmproxy-6a4f1ae7c7ea4b5036937312b837184162edaed3.tar.gz
mitmproxy-6a4f1ae7c7ea4b5036937312b837184162edaed3.tar.bz2
mitmproxy-6a4f1ae7c7ea4b5036937312b837184162edaed3.zip
Test har_extractor.response
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/data/har_extractor.har78
-rw-r--r--test/mitmproxy/test_har_extractor.py27
2 files changed, 105 insertions, 0 deletions
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"]