Unit test proxy auth.
This commit is contained in:
parent
5c6587d4a8
commit
33cdd5d083
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue