aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2013-01-18 14:50:31 +1300
committerAldo Cortesi <aldo@nullcube.com>2013-01-18 14:50:31 +1300
commit7a79eeb143e380c44bdfb1dd3fc5056c91c0c3d4 (patch)
tree405cef98fcce003c93bf1df2553d2c245ceaa155 /test
parentd0ee4d60d09c607a208ae1b190e619a4f106538e (diff)
parent8c6f1dd36b955c5fa2e60e8f7f63568269fbab96 (diff)
downloadmitmproxy-7a79eeb143e380c44bdfb1dd3fc5056c91c0c3d4.tar.gz
mitmproxy-7a79eeb143e380c44bdfb1dd3fc5056c91c0c3d4.tar.bz2
mitmproxy-7a79eeb143e380c44bdfb1dd3fc5056c91c0c3d4.zip
Merge branch 'master' of ssh.github.com:cortesi/mitmproxy
Conflicts: test/test_server.py
Diffstat (limited to 'test')
-rw-r--r--test/test_server.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/test_server.py b/test/test_server.py
index ba263e96..3686a6a8 100644
--- a/test/test_server.py
+++ b/test/test_server.py
@@ -1,3 +1,4 @@
+import socket, time
from netlib import tcp
from libpathod import pathoc
import tutils
@@ -80,3 +81,53 @@ class TestTransparent(tutils.TransparentProxTest, SanityMixin):
transparent = True
+class TestProxy(tutils.HTTPProxTest):
+ def test_http(self):
+ f = self.pathod("304")
+ assert f.status_code == 304
+
+ l = self.master.state.view[0]
+ assert l.request.client_conn.address
+ assert "host" in l.request.headers
+ assert l.response.code == 304
+
+ def test_response_timestamps(self):
+ # test that we notice at least 2 sec delay between timestamps
+ # in response object
+ f = self.pathod("304:b@1k:p50,2")
+ assert f.status_code == 304
+
+ response = self.master.state.view[0].response
+ assert 2 <= response.timestamp_end - response.timestamp_start <= 2.2
+
+ def test_request_timestamps(self):
+ # test that we notice at least 2 sec delay between timestamps
+ # in request object
+ connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ connection.connect(("127.0.0.1", self.proxy.port))
+
+ # call pathod server, wait a second to complete the request
+ connection.send("GET http://localhost:%d/p/304:b@1k HTTP/1.1\r\n"%self.server.port)
+ time.sleep(2.1)
+ connection.send("\r\n");
+ connection.recv(50000)
+ connection.close()
+
+ request, response = self.master.state.view[0].request, self.master.state.view[0].response
+ assert response.code == 304 # sanity test for our low level request
+ assert 2 <= request.timestamp_end - request.timestamp_start <= 2.2
+
+ def test_request_timestamps_not_affected_by_client_time(self):
+ # test that don't include user wait time in request's timestamps
+
+ f = self.pathod("304:b@10k")
+ assert f.status_code == 304
+ time.sleep(1)
+ f = self.pathod("304:b@10k")
+ assert f.status_code == 304
+
+ request = self.master.state.view[0].request
+ assert request.timestamp_end - request.timestamp_start <= 0.1
+
+ request = self.master.state.view[1].request
+ assert request.timestamp_end - request.timestamp_start <= 0.1