Merge "Handle missing CA better"

This commit is contained in:
Jenkins 2016-02-24 02:43:13 +00:00 committed by Gerrit Code Review
commit d2277c0879
2 changed files with 16 additions and 2 deletions

View File

@ -105,8 +105,11 @@ def get_ca(ra_name):
if not ca_path:
pecan.abort(404, "CA certificate not available")
with open(ca_path) as f:
return f.read()
try:
with open(ca_path) as f:
return f.read()
except IOError:
pecan.abort(500, "CA certificate not available")
def dispatch_sign(ra_name, csr):

View File

@ -135,3 +135,14 @@ class CertificateOpsTests(tests.DefaultConfigMixin, tests.DefaultRequestMixin,
with self.assertRaises(http_status.HTTPException) as cm:
certificate_ops.dispatch_sign('default_ra', csr_obj)
self.assertEqual(cm.exception.code, 500)
def test_ca_cert_not_configured(self):
"""Test CA cert read failure."""
config = "anchor.jsonloader.conf._config"
self.sample_conf_ca['default_ca']['cert_path'] = None
data = self.sample_conf
with mock.patch.dict(config, data):
with self.assertRaises(http_status.HTTPException) as cm:
certificate_ops.get_ca('default_ra')
self.assertEqual(cm.exception.code, 404)