aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorUjjwal Verma <ujjwalverma1111@gmail.com>2017-05-31 04:05:10 +0530
committerUjjwal Verma <ujjwalverma1111@gmail.com>2017-05-31 04:05:10 +0530
commit33f735ef5028497ed6b8c6fc0fac2cf915379fcf (patch)
treefbf8d0c41f7f0fa25477415599b9f07fbb1ee37c /test
parentec7d7c995c0d8e93332b43699ad372f9555c9b75 (diff)
downloadmitmproxy-33f735ef5028497ed6b8c6fc0fac2cf915379fcf.tar.gz
mitmproxy-33f735ef5028497ed6b8c6fc0fac2cf915379fcf.tar.bz2
mitmproxy-33f735ef5028497ed6b8c6fc0fac2cf915379fcf.zip
Increase test coverage
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/test_flow.py16
-rw-r--r--test/mitmproxy/test_http.py17
2 files changed, 28 insertions, 5 deletions
diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py
index 19f0e7d9..9f6ed585 100644
--- a/test/mitmproxy/test_flow.py
+++ b/test/mitmproxy/test_flow.py
@@ -7,7 +7,7 @@ from mitmproxy import flowfilter
from mitmproxy import options
from mitmproxy.proxy import config
from mitmproxy.io import tnetstring
-from mitmproxy.exceptions import FlowReadException
+from mitmproxy.exceptions import FlowReadException, ReplayException, ControlException
from mitmproxy import flow
from mitmproxy import http
from mitmproxy.proxy.server import DummyServer
@@ -102,15 +102,19 @@ class TestFlowMaster:
fm = master.Master(None, DummyServer())
f = tflow.tflow(resp=True)
f.request.content = None
- with pytest.raises(Exception, match="missing"):
+ with pytest.raises(ReplayException, match="missing"):
+ fm.replay_request(f)
+
+ f.request = None
+ with pytest.raises(ReplayException, match="request"):
fm.replay_request(f)
f.intercepted = True
- with pytest.raises(Exception, match="intercepted"):
+ with pytest.raises(ReplayException, match="intercepted"):
fm.replay_request(f)
f.live = True
- with pytest.raises(Exception, match="live"):
+ with pytest.raises(ReplayException, match="live"):
fm.replay_request(f)
def test_all(self):
@@ -132,6 +136,10 @@ class TestFlowMaster:
f.error = flow.Error("msg")
fm.addons.handle_lifecycle("error", f)
+ fm.tell("foo", f)
+ with pytest.raises(ControlException):
+ fm.tick(timeout=1)
+
fm.shutdown()
diff --git a/test/mitmproxy/test_http.py b/test/mitmproxy/test_http.py
index aa283530..4463961a 100644
--- a/test/mitmproxy/test_http.py
+++ b/test/mitmproxy/test_http.py
@@ -4,7 +4,7 @@ from mitmproxy.test import tflow
from mitmproxy.net.http import Headers
import mitmproxy.io
from mitmproxy import flowfilter
-from mitmproxy.exceptions import Kill
+from mitmproxy.exceptions import Kill, ControlException
from mitmproxy import flow
from mitmproxy import http
@@ -170,17 +170,32 @@ class TestHTTPFlow:
assert not f == f2
f2.error = flow.Error("e2")
assert not f == f2
+ f2.backup()
+ f2.intercept() # to change the state
f.set_state(f2.get_state())
assert f.get_state() == f2.get_state()
def test_kill(self):
f = tflow.tflow()
+ with pytest.raises(ControlException):
+ f.intercept()
+ f.resume()
+ f.kill()
+
+ f = tflow.tflow()
f.intercept()
assert f.killable
f.kill()
assert not f.killable
assert f.reply.value == Kill
+ def test_intercept(self):
+ f = tflow.tflow()
+ f.intercept()
+ assert f.reply.state == "taken"
+ f.intercept()
+ assert f.reply.state == "taken"
+
def test_resume(self):
f = tflow.tflow()
f.intercept()