Fixing tox cover

This commit is contained in:
TheNavigat
2016-02-12 14:25:59 +02:00
parent b68c5ace0c
commit fc2c907261
2 changed files with 18 additions and 26 deletions
+7 -25
View File
@@ -42,7 +42,6 @@ class AuthHandler(object):
form of :class:`letsencrypt.achallenges.AnnotatedChallenge`
"""
def __init__(self, dv_auth, cont_auth, acme, account):
self.dv_auth = dv_auth
self.cont_auth = cont_auth
@@ -76,32 +75,19 @@ class AuthHandler(object):
self._choose_challenges(domains)
failed_domains = set()
# While there are still challenges remaining...
while self.dv_c or self.cont_c:
cont_resp, dv_resp = self._solve_challenges()
logger.info("Waiting for verification...")
# Send all Responses - this modifies dv_c and cont_c
response = self._respond(cont_resp, dv_resp, best_effort)
if response:
failed_domains = failed_domains.union(response)
my_authzr = self.authzr
returnDomains = set()
#Remove failing domains if best_effort is true
for domain in domains:
if not domain in failed_domains:
returnDomains.add(domain)
self._respond(cont_resp, dv_resp, best_effort)
# Just make sure all decisions are complete.
self.verify_authzr_complete()
# Only return valid authorizations
return ([authzr for authzr in my_authzr.values()
if authzr.body.status == messages.STATUS_VALID], returnDomains)
return [authzr for authzr in self.authzr.values()
if authzr.body.status == messages.STATUS_VALID]
def _choose_challenges(self, domains):
"""Retrieve necessary challenges to satisfy server."""
@@ -153,13 +139,11 @@ class AuthHandler(object):
# Check for updated status...
try:
result = self._poll_challenges(chall_update, best_effort)
self._poll_challenges(chall_update, best_effort)
finally:
# This removes challenges from self.dv_c and self.cont_c
self._cleanup_challenges(active_achalls)
return result
def _send_responses(self, achalls, resps, chall_update):
"""Send responses and make sure errors are handled.
@@ -191,7 +175,6 @@ class AuthHandler(object):
"""Wait for all challenge results to be determined."""
dom_to_check = set(chall_update.keys())
comp_domains = set()
failed_domains = set()
rounds = 0
while dom_to_check and rounds < max_rounds:
@@ -209,8 +192,9 @@ class AuthHandler(object):
chall_update[domain].remove(achall)
# We failed some challenges... damage control
else:
# Right now... just assume a loss and carry on...
if best_effort:
failed_domains.add(domain)
comp_domains.add(domain)
else:
all_failed_achalls.update(
updated for _, updated in failed_achalls)
@@ -219,12 +203,10 @@ class AuthHandler(object):
_report_failed_challs(all_failed_achalls)
raise errors.FailedChallenges(all_failed_achalls)
dom_to_check -= comp_domains.union(failed_domains)
dom_to_check -= comp_domains
comp_domains.clear()
rounds += 1
return failed_domains
def _handle_check(self, domain, achalls):
"""Returns tuple of ('completed', 'failed')."""
completed = []
+11 -1
View File
@@ -98,6 +98,7 @@ class ClientTest(unittest.TestCase):
def _mock_obtain_certificate(self):
self.client.auth_handler = mock.MagicMock()
self.client.auth_handler.get_authorizations.return_value = (None, None)
self.acme.request_issuance.return_value = mock.sentinel.certr
self.acme.fetch_chain.return_value = mock.sentinel.chain
@@ -105,10 +106,14 @@ class ClientTest(unittest.TestCase):
self.client.auth_handler.get_authorizations.assert_called_once_with(
self.eg_domains,
self.config.allow_subset_of_names)
authzr, _ = self.client.auth_handler.get_authorizations()
self.acme.request_issuance.assert_called_once_with(
jose.ComparableX509(OpenSSL.crypto.load_certificate_request(
OpenSSL.crypto.FILETYPE_ASN1, CSR_SAN)),
self.client.auth_handler.get_authorizations())
authzr)
self.acme.fetch_chain.assert_called_once_with(mock.sentinel.certr)
# FIXME move parts of this to test_cli.py...
@@ -148,6 +153,11 @@ class ClientTest(unittest.TestCase):
mock_crypto_util.init_save_key.return_value = mock.sentinel.key
domains = ["example.com", "www.example.com"]
# return_value is essentially set to (None, None) in
# _mock_obtain_certificate(), which breaks this test.
# Thus fixed by the next line.
self.client.auth_handler.get_authorizations.return_value = (None, domains)
self.assertEqual(
self.client.obtain_certificate(domains),
(mock.sentinel.certr, mock.sentinel.chain, mock.sentinel.key, csr))