diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2013-03-03 11:04:33 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2013-03-03 11:04:33 +1300 |
commit | 33cdd5d0836b706a9d06c332fa5381bbeb4fa69f (patch) | |
tree | 8d124a23778cbfb8082be0947304c358cf7ada4f /test | |
parent | 5c6587d4a80cc45b23154237ca94858da60c7da5 (diff) | |
download | mitmproxy-33cdd5d0836b706a9d06c332fa5381bbeb4fa69f.tar.gz mitmproxy-33cdd5d0836b706a9d06c332fa5381bbeb4fa69f.tar.bz2 mitmproxy-33cdd5d0836b706a9d06c332fa5381bbeb4fa69f.zip |
Unit test proxy auth.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_server.py | 25 | ||||
-rw-r--r-- | test/tservers.py | 3 |
2 files changed, 20 insertions, 8 deletions
diff --git a/test/test_server.py b/test/test_server.py index 0af4bae8..8a6228ad 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -1,6 +1,6 @@ import socket, time import mock -from netlib import tcp +from netlib import tcp, http_auth, http from libpathod import pathoc import tutils, tservers from libmproxy import flow, proxy @@ -135,6 +135,23 @@ class TestHTTP(tservers.HTTPProxTest, CommonMixin): assert req.status_code == 400 +class TestHTTPAuth(tservers.HTTPProxTest): + authenticator = http_auth.BasicProxyAuth(http_auth.PassManSingleUser("test", "test"), "realm") + def test_auth(self): + assert self.pathod("202").status_code == 407 + p = self.pathoc() + ret = p.request(""" + get + 'http://localhost:%s/p/202' + h'%s'='%s' + """%( + self.server.port, + http_auth.BasicProxyAuth.AUTH_HEADER, + http.assemble_http_basic_auth("basic", "test", "test") + )) + assert ret.status_code == 202 + + class TestHTTPConnectSSLError(tservers.HTTPProxTest): certfile = True def test_go(self): @@ -163,7 +180,6 @@ class TestHTTPS(tservers.HTTPProxTest, CommonMixin): assert p.request("get:/:i0,'invalid\r\n\r\n'").status_code == 400 - class TestHTTPSNoUpstream(tservers.HTTPProxTest, CommonMixin): ssl = True no_upstream_cert = True @@ -303,8 +319,3 @@ class TestTransparentResolveError(tservers.TransparentProxTest): def test_resolve_error(self): assert self.pathod("304").status_code == 502 - - - - - diff --git a/test/tservers.py b/test/tservers.py index 7672f34a..0c2f8c2f 100644 --- a/test/tservers.py +++ b/test/tservers.py @@ -72,7 +72,7 @@ class ProxTestBase: clientcerts = False certfile = None no_upstream_cert = False - + authenticator = None masterclass = TestMaster @classmethod def setupAll(cls): @@ -83,6 +83,7 @@ class ProxTestBase: config = proxy.ProxyConfig( no_upstream_cert = cls.no_upstream_cert, cacert = tutils.test_data.path("data/serverkey.pem"), + authenticator = cls.authenticator, **pconf ) tmaster = cls.masterclass(cls.tqueue, config) |