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):
return response, json.dumps({})
# 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")}
nonce = None
......@@ -242,8 +242,9 @@ def get_crt(config, log=LOGGER):
challenge_verified = (challenge_verified
or response.to_text() == '"{0}"'.format(keydigest64))
except dns.exception.DNSException as dnsexception:
log.debug(" - Will retry as a DNS error occurred while checking challenge:\
%s : %s", type(dnsexception).__name__, dnsexception)
log.debug(
" - Will retry as a DNS error occurred while checking challenge: %s : %s",
type(dnsexception).__name__, dnsexception)
finally:
if challenge_verified is False:
if number_check_fail >= 10:
......
......@@ -53,5 +53,5 @@ class TestACMEAccountDeactivate(unittest.TestCase):
self.assertIn("INFO:acme_account_deactivate:The account has been deactivated.",
accountdeactivatelog.output)
if __name__ == "__main__":
if __name__ == "__main__": # pragma: no cover
unittest.main()
......@@ -59,5 +59,5 @@ class TestACMEAccountRollover(unittest.TestCase):
self.assertIn("INFO:acme_account_rollover:Keys rolled over.",
accountrolloverlog.output)
if __name__ == "__main__":
if __name__ == "__main__": # pragma: no cover
unittest.main()
......@@ -212,5 +212,5 @@ host: we will use either resource found if one exists or directly the DNS Host c
"Error updating DNS",
acme_dns_tiny.main, [self.configs['invalid_tsig_name'], "--verbose"])
if __name__ == "__main__":
if __name__ == "__main__": # pragma: no cover
unittest.main()
......@@ -37,5 +37,5 @@ class TestACMEDNSTiny(unittest.TestCase):
self.assertRaisesRegex(ValueError, r"Some required settings are missing.",
acme_dns_tiny.main, [self.configs['missing_dns'], "--verbose"])
if __name__ == "__main__":
if __name__ == "__main__": # pragma: no cover
unittest.main()
......@@ -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["url"] = url
if url == acme_config["newAccount"]:
del protected["kid"]
if "kid" in protected:
del protected["kid"]
else:
del protected["jwk"]
protected64 = _b64(json.dumps(protected).encode("utf8"))
......@@ -60,12 +61,13 @@ def account_deactivate(accountkeypath, acme_directory, log=LOGGER):
response = error.response
finally:
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, response.json()
# main code
adtheaders = {'User-Agent': 'acme-dns-tiny/2.1'}
adtheaders = {'User-Agent': 'acme-dns-tiny/2.2'}
nonce = None
log.info("Fetch informations from the ACME directory.")
......@@ -86,7 +88,6 @@ def account_deactivate(accountkeypath, acme_directory, log=LOGGER):
"kty": "RSA",
"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.")
......
......@@ -45,7 +45,6 @@ def account_rollover(old_accountkeypath, new_accountkeypath, acme_directory, log
"kty": "RSA",
"n": _b64(binascii.unhexlify(re.sub(r"(\s|:)", "", pub_hex).encode("utf-8"))),
},
"kid": None
}
def _sign_request(url, keypath, payload, is_inner=False):
......@@ -61,7 +60,8 @@ def account_rollover(old_accountkeypath, new_accountkeypath, acme_directory, log
protected = copy.deepcopy(private_acme_old_signature)
if is_inner or url == acme_config["newAccount"]:
del protected["kid"]
if "kid" in protected:
del protected["kid"]
else:
del protected["jwk"]
......@@ -91,12 +91,13 @@ def account_rollover(old_accountkeypath, new_accountkeypath, acme_directory, log
response = error.response
finally:
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, response.json()
# main code
adtheaders = {'User-Agent': 'acme-dns-tiny/2.0'}
adtheaders = {'User-Agent': 'acme-dns-tiny/2.2'}
nonce = None
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