From 33cdd5d0836b706a9d06c332fa5381bbeb4fa69f Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 3 Mar 2013 11:04:33 +1300 Subject: [PATCH] Unit test proxy auth. --- test/test_server.py | 25 ++++++++++++++++++------- test/tservers.py | 3 ++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/test/test_server.py b/test/test_server.py index 0af4bae80..8a6228adf 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 7672f34ab..0c2f8c2ff 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)