Commit e1fe3ad7 authored by Adrien Dorsaz's avatar Adrien Dorsaz

unify send_request between the different tools, add pragma nocover to tests and pass to version 2.2

parent 1ae4370d
...@@ -76,7 +76,7 @@ def get_crt(config, log=LOGGER): ...@@ -76,7 +76,7 @@ def get_crt(config, log=LOGGER):
return response, json.dumps({}) return response, json.dumps({})
# main code # main code
adtheaders = {'User-Agent': 'acme-dns-tiny/2.1', adtheaders = {'User-Agent': 'acme-dns-tiny/2.2',
'Accept-Language': config["acmednstiny"].get("Language", "en")} 'Accept-Language': config["acmednstiny"].get("Language", "en")}
nonce = None nonce = None
...@@ -242,8 +242,9 @@ def get_crt(config, log=LOGGER): ...@@ -242,8 +242,9 @@ def get_crt(config, log=LOGGER):
challenge_verified = (challenge_verified challenge_verified = (challenge_verified
or response.to_text() == '"{0}"'.format(keydigest64)) or response.to_text() == '"{0}"'.format(keydigest64))
except dns.exception.DNSException as dnsexception: except dns.exception.DNSException as dnsexception:
log.debug(" - Will retry as a DNS error occurred while checking challenge:\ log.debug(
%s : %s", type(dnsexception).__name__, dnsexception) " - Will retry as a DNS error occurred while checking challenge: %s : %s",
type(dnsexception).__name__, dnsexception)
finally: finally:
if challenge_verified is False: if challenge_verified is False:
if number_check_fail >= 10: if number_check_fail >= 10:
......
...@@ -53,5 +53,5 @@ class TestACMEAccountDeactivate(unittest.TestCase): ...@@ -53,5 +53,5 @@ class TestACMEAccountDeactivate(unittest.TestCase):
self.assertIn("INFO:acme_account_deactivate:The account has been deactivated.", self.assertIn("INFO:acme_account_deactivate:The account has been deactivated.",
accountdeactivatelog.output) accountdeactivatelog.output)
if __name__ == "__main__": if __name__ == "__main__": # pragma: no cover
unittest.main() unittest.main()
...@@ -59,5 +59,5 @@ class TestACMEAccountRollover(unittest.TestCase): ...@@ -59,5 +59,5 @@ class TestACMEAccountRollover(unittest.TestCase):
self.assertIn("INFO:acme_account_rollover:Keys rolled over.", self.assertIn("INFO:acme_account_rollover:Keys rolled over.",
accountrolloverlog.output) accountrolloverlog.output)
if __name__ == "__main__": if __name__ == "__main__": # pragma: no cover
unittest.main() unittest.main()
...@@ -212,5 +212,5 @@ host: we will use either resource found if one exists or directly the DNS Host c ...@@ -212,5 +212,5 @@ host: we will use either resource found if one exists or directly the DNS Host c
"Error updating DNS", "Error updating DNS",
acme_dns_tiny.main, [self.configs['invalid_tsig_name'], "--verbose"]) acme_dns_tiny.main, [self.configs['invalid_tsig_name'], "--verbose"])
if __name__ == "__main__": if __name__ == "__main__": # pragma: no cover
unittest.main() unittest.main()
...@@ -37,5 +37,5 @@ class TestACMEDNSTiny(unittest.TestCase): ...@@ -37,5 +37,5 @@ class TestACMEDNSTiny(unittest.TestCase):
self.assertRaisesRegex(ValueError, r"Some required settings are missing.", self.assertRaisesRegex(ValueError, r"Some required settings are missing.",
acme_dns_tiny.main, [self.configs['missing_dns'], "--verbose"]) acme_dns_tiny.main, [self.configs['missing_dns'], "--verbose"])
if __name__ == "__main__": if __name__ == "__main__": # pragma: no cover
unittest.main() unittest.main()
...@@ -41,7 +41,8 @@ def account_deactivate(accountkeypath, acme_directory, log=LOGGER): ...@@ -41,7 +41,8 @@ def account_deactivate(accountkeypath, acme_directory, log=LOGGER):
protected["nonce"] = nonce or requests.get(acme_config["newNonce"]).headers['Replay-Nonce'] protected["nonce"] = nonce or requests.get(acme_config["newNonce"]).headers['Replay-Nonce']
protected["url"] = url protected["url"] = url
if url == acme_config["newAccount"]: if url == acme_config["newAccount"]:
del protected["kid"] if "kid" in protected:
del protected["kid"]
else: else:
del protected["jwk"] del protected["jwk"]
protected64 = _b64(json.dumps(protected).encode("utf8")) protected64 = _b64(json.dumps(protected).encode("utf8"))
...@@ -60,12 +61,13 @@ def account_deactivate(accountkeypath, acme_directory, log=LOGGER): ...@@ -60,12 +61,13 @@ def account_deactivate(accountkeypath, acme_directory, log=LOGGER):
response = error.response response = error.response
finally: finally:
nonce = response.headers['Replay-Nonce'] nonce = response.headers['Replay-Nonce']
if not response.text: try:
return response, response.json()
except ValueError: # if body is empty or not JSON formatted
return response, json.dumps({}) return response, json.dumps({})
return response, response.json()
# main code # main code
adtheaders = {'User-Agent': 'acme-dns-tiny/2.1'} adtheaders = {'User-Agent': 'acme-dns-tiny/2.2'}
nonce = None nonce = None
log.info("Fetch informations from the ACME directory.") log.info("Fetch informations from the ACME directory.")
...@@ -86,7 +88,6 @@ def account_deactivate(accountkeypath, acme_directory, log=LOGGER): ...@@ -86,7 +88,6 @@ def account_deactivate(accountkeypath, acme_directory, log=LOGGER):
"kty": "RSA", "kty": "RSA",
"n": _b64(binascii.unhexlify(re.sub(r"(\s|:)", "", pub_hex).encode("utf-8"))), "n": _b64(binascii.unhexlify(re.sub(r"(\s|:)", "", pub_hex).encode("utf-8"))),
}, },
"kid": None,
} }
log.info("Ask to the ACME server the account identifier to complete the private signature.") log.info("Ask to the ACME server the account identifier to complete the private signature.")
......
...@@ -45,7 +45,6 @@ def account_rollover(old_accountkeypath, new_accountkeypath, acme_directory, log ...@@ -45,7 +45,6 @@ def account_rollover(old_accountkeypath, new_accountkeypath, acme_directory, log
"kty": "RSA", "kty": "RSA",
"n": _b64(binascii.unhexlify(re.sub(r"(\s|:)", "", pub_hex).encode("utf-8"))), "n": _b64(binascii.unhexlify(re.sub(r"(\s|:)", "", pub_hex).encode("utf-8"))),
}, },
"kid": None
} }
def _sign_request(url, keypath, payload, is_inner=False): def _sign_request(url, keypath, payload, is_inner=False):
...@@ -61,7 +60,8 @@ def account_rollover(old_accountkeypath, new_accountkeypath, acme_directory, log ...@@ -61,7 +60,8 @@ def account_rollover(old_accountkeypath, new_accountkeypath, acme_directory, log
protected = copy.deepcopy(private_acme_old_signature) protected = copy.deepcopy(private_acme_old_signature)
if is_inner or url == acme_config["newAccount"]: if is_inner or url == acme_config["newAccount"]:
del protected["kid"] if "kid" in protected:
del protected["kid"]
else: else:
del protected["jwk"] del protected["jwk"]
...@@ -91,12 +91,13 @@ def account_rollover(old_accountkeypath, new_accountkeypath, acme_directory, log ...@@ -91,12 +91,13 @@ def account_rollover(old_accountkeypath, new_accountkeypath, acme_directory, log
response = error.response response = error.response
finally: finally:
nonce = response.headers['Replay-Nonce'] nonce = response.headers['Replay-Nonce']
if not response.text: try:
return response, response.json()
except ValueError: # if body is empty or not JSON formatted
return response, json.dumps({}) return response, json.dumps({})
return response, response.json()
# main code # main code
adtheaders = {'User-Agent': 'acme-dns-tiny/2.0'} adtheaders = {'User-Agent': 'acme-dns-tiny/2.2'}
nonce = None nonce = None
log.info("Fetch informations from the ACME directory.") log.info("Fetch informations from the ACME directory.")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment