Commit 88a97708 authored by Adrien Dorsaz's avatar Adrien Dorsaz

acme_dns_tiny/tests: fixes issues introduced by updates made for pylint

parent 6b454a54
Pipeline #267 failed with stages
in 21 minutes and 38 seconds
......@@ -67,7 +67,7 @@ above files. This user should *NOT* have access to your domain key!
This project has a very, very limited scope and codebase. The project is happy
to receive bug reports and pull requests, but please don't add any new features.
This script must stay under ~250 lines of code to ensure it can be easily
This script must stay under ~400 lines of code to ensure it can be easily
audited by anyone who wants to run it.
If you want to add features for your own setup to make things easier for you,
......
......@@ -51,7 +51,8 @@ def get_crt(config, 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 = _base64(json.dumps(protected).encode("utf8"))
......@@ -60,7 +61,8 @@ def get_crt(config, log=LOGGER):
jose = {
"protected": protected64, "payload": payload64, "signature": _base64(signature)
}
joseheaders = {'Content-Type': 'application/jose+json'}.update(adtheaders)
joseheaders = {'Content-Type': 'application/jose+json'}
joseheaders.update(adtheaders)
joseheaders.update(extra_headers or {})
try:
response = requests.post(url, json=jose, headers=joseheaders)
......@@ -68,9 +70,10 @@ def get_crt(config, 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',
......
......@@ -23,12 +23,15 @@ class TestACMEAccountRollover(unittest.TestCase):
#pylint: disable=bare-except
@classmethod
def tearDownClass(cls):
# deactivate account key registration at end of tests
# (we assume the key has been roll oved)
account_deactivate(cls.configs["newaccountkey"], ACME_DIRECTORY)
# Remove temporary files
parser = configparser.ConfigParser()
parser.read(cls.configs['config'])
try:
# deactivate account key registration at end of tests
# (we assume the key has been rolled over)
account_deactivate(cls.configs["new_account_key"], ACME_DIRECTORY)
except:
pass
try:
os.remove(parser["acmednstiny"]["AccountKeyFile"])
except:
......
......@@ -44,17 +44,17 @@ class TestACMEDNSTiny(unittest.TestCase):
parser = configparser.ConfigParser()
parser.read(cls.configs[conffile])
try:
os.remove(parser["acmednstiny"]["AccountKeyFile"])
# for each configuration, deactivate the account key
if conffile != "cname_csr":
account_deactivate(parser["acmednstiny"]["AccountKeyFile"], ACME_DIRECTORY)
except:
pass
try:
os.remove(parser["acmednstiny"]["CSRFile"])
os.remove(parser["acmednstiny"]["AccountKeyFile"])
except:
pass
try:
# for each configuration, deactivate the account key
if conffile != "cname_csr":
account_deactivate(parser["acmednstiny"]["AccountKeyFile"], ACME_DIRECTORY)
os.remove(parser["acmednstiny"]["CSRFile"])
except:
pass
try:
......
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