mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
client-cert: Simplify and cleanup
simplify the error message when cert path does not exist. During tests, reset the clientcerts proxy config setting to None Remove now-unused clientcerts code from class ProxTestBase
This commit is contained in:
parent
80690b7906
commit
09168e1274
@ -133,12 +133,9 @@ def process_proxy_options(parser, options):
|
||||
|
||||
if options.clientcerts:
|
||||
options.clientcerts = os.path.expanduser(options.clientcerts)
|
||||
if not (os.path.exists(options.clientcerts) or
|
||||
os.path.isdir(options.clientcerts) or
|
||||
os.path.isfile(options.clientcerts)):
|
||||
if not os.path.exists(options.clientcerts):
|
||||
return parser.error(
|
||||
"Client certificate argument is not a file or directory, "
|
||||
"or does not exist: %s" % options.clientcerts
|
||||
"Client certificate path does not exist: %s" % options.clientcerts
|
||||
)
|
||||
|
||||
if options.auth_nonanonymous or options.auth_singleuser or options.auth_htpasswd:
|
||||
|
@ -104,7 +104,7 @@ class TestProcessProxyOptions:
|
||||
"--client-certs",
|
||||
os.path.join(tutils.test_data.path("data/clientcert"), "client.pem"))
|
||||
self.assert_err(
|
||||
"not a file or directory",
|
||||
"path does not exist",
|
||||
"--client-certs",
|
||||
"nonexistent")
|
||||
|
||||
|
@ -314,21 +314,24 @@ class TestHTTPAuth(tservers.HTTPProxTest):
|
||||
class TestHTTPS(tservers.HTTPProxTest, CommonMixin, TcpMixin):
|
||||
ssl = True
|
||||
ssloptions = pathod.SSLOptions(request_client_cert=True)
|
||||
clientcerts = True
|
||||
|
||||
def test_clientcert(self):
|
||||
def test_clientcert_file(self):
|
||||
try:
|
||||
self.config.clientcerts = os.path.join(
|
||||
tutils.test_data.path("data/clientcert"), "client.pem")
|
||||
f = self.pathod("304")
|
||||
assert f.status_code == 304
|
||||
assert self.server.last_log()["request"]["clientcert"]["keyinfo"]
|
||||
|
||||
def test_clientcerts(self):
|
||||
finally:
|
||||
self.config.clientcerts = None
|
||||
def test_clientcert_dir(self):
|
||||
try:
|
||||
self.config.clientcerts = tutils.test_data.path("data/clientcert")
|
||||
f = self.pathod("304")
|
||||
assert f.status_code == 304
|
||||
assert self.server.last_log()["request"]["clientcert"]["keyinfo"]
|
||||
|
||||
finally:
|
||||
self.config.clientcerts = None
|
||||
def test_error_post_connect(self):
|
||||
p = self.pathoc()
|
||||
assert p.request("get:/:i0,'invalid\r\n\r\n'").status_code == 400
|
||||
|
@ -83,7 +83,6 @@ class ProxTestBase(object):
|
||||
# Test Configuration
|
||||
ssl = None
|
||||
ssloptions = False
|
||||
clientcerts = False
|
||||
no_upstream_cert = False
|
||||
authenticator = None
|
||||
masterclass = TestMaster
|
||||
@ -130,7 +129,6 @@ class ProxTestBase(object):
|
||||
no_upstream_cert = cls.no_upstream_cert,
|
||||
cadir = cls.cadir,
|
||||
authenticator = cls.authenticator,
|
||||
clientcerts = tutils.test_data.path("data/clientcert") if cls.clientcerts else None
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user