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:
Michael J. Bazzinotti 2015-12-29 11:48:02 -05:00
parent 80690b7906
commit 09168e1274
4 changed files with 20 additions and 22 deletions

View File

@ -133,12 +133,9 @@ def process_proxy_options(parser, options):
if options.clientcerts: if options.clientcerts:
options.clientcerts = os.path.expanduser(options.clientcerts) options.clientcerts = os.path.expanduser(options.clientcerts)
if not (os.path.exists(options.clientcerts) or if not os.path.exists(options.clientcerts):
os.path.isdir(options.clientcerts) or
os.path.isfile(options.clientcerts)):
return parser.error( return parser.error(
"Client certificate argument is not a file or directory, " "Client certificate path does not exist: %s" % options.clientcerts
"or does not exist: %s" % options.clientcerts
) )
if options.auth_nonanonymous or options.auth_singleuser or options.auth_htpasswd: if options.auth_nonanonymous or options.auth_singleuser or options.auth_htpasswd:

View File

@ -104,7 +104,7 @@ class TestProcessProxyOptions:
"--client-certs", "--client-certs",
os.path.join(tutils.test_data.path("data/clientcert"), "client.pem")) os.path.join(tutils.test_data.path("data/clientcert"), "client.pem"))
self.assert_err( self.assert_err(
"not a file or directory", "path does not exist",
"--client-certs", "--client-certs",
"nonexistent") "nonexistent")

View File

@ -314,21 +314,24 @@ class TestHTTPAuth(tservers.HTTPProxTest):
class TestHTTPS(tservers.HTTPProxTest, CommonMixin, TcpMixin): class TestHTTPS(tservers.HTTPProxTest, CommonMixin, TcpMixin):
ssl = True ssl = True
ssloptions = pathod.SSLOptions(request_client_cert=True) ssloptions = pathod.SSLOptions(request_client_cert=True)
clientcerts = True
def test_clientcert(self):
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):
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"]
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"]
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): def test_error_post_connect(self):
p = self.pathoc() p = self.pathoc()
assert p.request("get:/:i0,'invalid\r\n\r\n'").status_code == 400 assert p.request("get:/:i0,'invalid\r\n\r\n'").status_code == 400

View File

@ -83,7 +83,6 @@ class ProxTestBase(object):
# Test Configuration # Test Configuration
ssl = None ssl = None
ssloptions = False ssloptions = False
clientcerts = False
no_upstream_cert = False no_upstream_cert = False
authenticator = None authenticator = None
masterclass = TestMaster masterclass = TestMaster
@ -130,7 +129,6 @@ class ProxTestBase(object):
no_upstream_cert = cls.no_upstream_cert, no_upstream_cert = cls.no_upstream_cert,
cadir = cls.cadir, cadir = cls.cadir,
authenticator = cls.authenticator, authenticator = cls.authenticator,
clientcerts = tutils.test_data.path("data/clientcert") if cls.clientcerts else None
) )