diff options
author | Rouli <rouli.net@gmail.com> | 2013-01-17 17:33:29 +0200 |
---|---|---|
committer | Rouli <rouli.net@gmail.com> | 2013-01-17 17:33:29 +0200 |
commit | 446f9f0a0fc12159ba663d3b8bdc8f1206a197c7 (patch) | |
tree | 9cb474c3154fb4146cce41e40e25b4a8e3e57d46 /test | |
parent | 20fa6a30839500207d7d509fe3b8697dbd22a33e (diff) | |
parent | 280dd94198931bcd819848a70d68f6f5d9f3270b (diff) | |
download | mitmproxy-446f9f0a0fc12159ba663d3b8bdc8f1206a197c7.tar.gz mitmproxy-446f9f0a0fc12159ba663d3b8bdc8f1206a197c7.tar.bz2 mitmproxy-446f9f0a0fc12159ba663d3b8bdc8f1206a197c7.zip |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'test')
-rw-r--r-- | test/data/pf01 | 4 | ||||
-rw-r--r-- | test/test_authentication.py | 58 | ||||
-rw-r--r-- | test/test_dump.py | 9 | ||||
-rw-r--r-- | test/test_flow.py | 18 | ||||
-rw-r--r-- | test/test_platform_pf.py | 13 | ||||
-rwxr-xr-x | test/tools/getcert | 2 | ||||
-rwxr-xr-x | test/tools/getcn | 17 | ||||
-rw-r--r-- | test/tutils.py | 4 |
8 files changed, 103 insertions, 22 deletions
diff --git a/test/data/pf01 b/test/data/pf01 new file mode 100644 index 00000000..3139a289 --- /dev/null +++ b/test/data/pf01 @@ -0,0 +1,4 @@ +No ALTQ support in kernel +ALTQ related functions disabled +ALL tcp 127.0.0.1:8080 <- 5.5.5.6:80 <- 192.168.1.111:40001 FIN_WAIT_2:FIN_WAIT_2 +ALL tcp 127.0.0.1:8080 <- 5.5.5.5:80 <- 192.168.1.111:40000 ESTABLISHED:ESTABLISHED diff --git a/test/test_authentication.py b/test/test_authentication.py new file mode 100644 index 00000000..f7a5ecd3 --- /dev/null +++ b/test/test_authentication.py @@ -0,0 +1,58 @@ +import binascii +from libmproxy import authentication +from netlib import odict +import tutils + + +class TestNullProxyAuth: + def test_simple(self): + na = authentication.NullProxyAuth(authentication.PermissivePasswordManager()) + assert not na.auth_challenge_headers() + assert na.authenticate("foo") + na.clean({}) + + +class TestBasicProxyAuth: + def test_simple(self): + ba = authentication.BasicProxyAuth(authentication.PermissivePasswordManager(), "test") + h = odict.ODictCaseless() + assert ba.auth_challenge_headers() + assert not ba.authenticate(h) + + def test_parse_auth_value(self): + ba = authentication.BasicProxyAuth(authentication.PermissivePasswordManager(), "test") + vals = ("basic", "foo", "bar") + assert ba.parse_auth_value(ba.unparse_auth_value(*vals)) == vals + tutils.raises(ValueError, ba.parse_auth_value, "") + tutils.raises(ValueError, ba.parse_auth_value, "foo bar") + + v = "basic " + binascii.b2a_base64("foo") + tutils.raises(ValueError, ba.parse_auth_value, v) + + def test_authenticate_clean(self): + ba = authentication.BasicProxyAuth(authentication.PermissivePasswordManager(), "test") + + hdrs = odict.ODictCaseless() + vals = ("basic", "foo", "bar") + hdrs[ba.AUTH_HEADER] = [ba.unparse_auth_value(*vals)] + assert ba.authenticate(hdrs) + + ba.clean(hdrs) + assert not ba.AUTH_HEADER in hdrs + + + hdrs[ba.AUTH_HEADER] = [""] + assert not ba.authenticate(hdrs) + + hdrs[ba.AUTH_HEADER] = ["foo"] + assert not ba.authenticate(hdrs) + + vals = ("foo", "foo", "bar") + hdrs[ba.AUTH_HEADER] = [ba.unparse_auth_value(*vals)] + assert not ba.authenticate(hdrs) + + ba = authentication.BasicProxyAuth(authentication.PasswordManager(), "test") + vals = ("basic", "foo", "bar") + hdrs[ba.AUTH_HEADER] = [ba.unparse_auth_value(*vals)] + assert not ba.authenticate(hdrs) + diff --git a/test/test_dump.py b/test/test_dump.py index 0337bb33..e1241e29 100644 --- a/test/test_dump.py +++ b/test/test_dump.py @@ -48,6 +48,15 @@ class TestDumpMaster: fw.add(t) f.close() + def test_error(self): + cs = StringIO() + o = dump.Options(verbosity=1) + m = dump.DumpMaster(None, o, None, outfile=cs) + f = tutils.tflow_err() + m.handle_request(f.request) + assert m.handle_error(f.error) + assert "error" in cs.getvalue() + def test_replay(self): cs = StringIO() diff --git a/test/test_flow.py b/test/test_flow.py index 277d2407..2af702ce 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -624,6 +624,7 @@ class TestFlowMaster: fm.handle_error(flow.Error(f.request, "error")) def test_server_playback(self): + controller.should_exit = False s = flow.State() f = tutils.tflow() @@ -641,8 +642,9 @@ class TestFlowMaster: r = tutils.tflow() r.request.content = "gibble" assert not fm.do_server_playback(r) - assert fm.do_server_playback(tutils.tflow()) + + fm.start_server_playback(pb, False, [], True, False) q = Queue.Queue() fm.tick(q) assert controller.should_exit @@ -650,6 +652,20 @@ class TestFlowMaster: fm.stop_server_playback() assert not fm.server_playback + def test_server_playback_kill(self): + s = flow.State() + f = tutils.tflow() + f.response = tutils.tresp(f.request) + pb = [f] + fm = flow.FlowMaster(None, s) + fm.refresh_server_playback = True + fm.start_server_playback(pb, True, [], False, False) + + f = tutils.tflow() + f.request.host = "nonexistent" + fm.process_new_request(f) + assert "killed" in f.error.msg + def test_stickycookie(self): s = flow.State() fm = flow.FlowMaster(None, s) diff --git a/test/test_platform_pf.py b/test/test_platform_pf.py new file mode 100644 index 00000000..a2e7c3c1 --- /dev/null +++ b/test/test_platform_pf.py @@ -0,0 +1,13 @@ +import tutils +from libmproxy.platform import pf + + +class TestLookup: + def test_simple(self): + p = tutils.test_data.path("data/pf01") + d = open(p).read() + assert pf.lookup("192.168.1.111", 40000, d) == ("5.5.5.5", 80) + assert not pf.lookup("192.168.1.112", 40000, d) + assert not pf.lookup("192.168.1.111", 40001, d) + + diff --git a/test/tools/getcert b/test/tools/getcert index 6447ecc7..8fabefb7 100755 --- a/test/tools/getcert +++ b/test/tools/getcert @@ -5,5 +5,3 @@ import socket, tempfile, ssl, subprocess addr = socket.gethostbyname(sys.argv[1]) print ssl.get_server_certificate((addr, 443)) - - diff --git a/test/tools/getcn b/test/tools/getcn deleted file mode 100755 index 212977c3..00000000 --- a/test/tools/getcn +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python -import sys -sys.path.insert(0, "../../") -from libmproxy import certutils - -if len(sys.argv) > 2: - port = int(sys.argv[2]) -else: - pport = 443 - -cn, san = certutils.get_remote_cn(sys.argv[1], port) -print cn -if san: - for i in san: - print "\t", i - - diff --git a/test/tutils.py b/test/tutils.py index 0e661a4b..5ce56cb4 100644 --- a/test/tutils.py +++ b/test/tutils.py @@ -4,7 +4,7 @@ from contextlib import contextmanager from libmproxy import proxy, flow, controller, utils from netlib import certutils import human_curl as hurl -import libpathod.test +import libpathod.test, libpathod.pathoc def treq(conn=None): if not conn: @@ -194,7 +194,6 @@ class ReverseProxTest(ProxTestBase): return r - @contextmanager def tmpdir(*args, **kwargs): orig_workdir = os.getcwd() @@ -245,4 +244,5 @@ def raises(exc, obj, *args, **kwargs): ) raise AssertionError("No exception raised.") + test_data = utils.Data(__name__) |