Skip to content

Commit e3e4e63

Browse files
author
Martin Maney
committed
Here's the simple "fix" for #201, plus the tedious patches of the quirky tests
1 parent 47c77dc commit e3e4e63

File tree

2 files changed

+39
-31
lines changed

2 files changed

+39
-31
lines changed

sewer/client.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,16 @@ def get_acme_endpoints(self):
202202
)
203203
return get_acme_endpoints
204204

205+
### FIX ME ### this is a kludge to fix Alec's needs until there's time to do the Acme* refactor
206+
205207
def acme_register(self):
206-
"""
207-
RFC8555 has some changes in behavior.
208208

209-
For now,leaving the behavior unchanged except replacing "self.PRIOR_REGISTERED"
210-
with "not self.is_new_acct". But further work is needed - I don't think a
211-
409 result is part of the protocol any more, for one thing.
212-
"""
213209
self.logger.info("acme_register%s" % " (is new account)" if self.is_new_acct else "")
210+
211+
if self.acct_key.kid:
212+
self.logger.info("acme_register: key was already registered")
213+
return None
214+
214215
if not self.is_new_acct:
215216
payload = {"onlyReturnExisting": True}
216217
elif self.contact_email:
@@ -222,27 +223,26 @@ def acme_register(self):
222223
payload = {"termsOfServiceAgreed": True}
223224

224225
url = self.ACME_NEW_ACCOUNT_URL
225-
acme_register_response = self.make_signed_acme_request(
226+
response = self.make_signed_acme_request(
226227
url=url, payload=json.dumps(payload), needs_jwk=True
227228
)
228229
self.logger.debug(
229-
"acme_register_response. status_code={0}. response={1}".format(
230-
acme_register_response.status_code, log_response(acme_register_response)
230+
"response. status_code={0}. response={1}".format(
231+
response.status_code, log_response(response)
231232
)
232233
)
233234

234-
if acme_register_response.status_code not in [201, 200, 409]:
235+
if response.status_code not in [201, 200, 409]:
235236
raise ValueError(
236237
"Error while registering: status_code={status_code} response={response}".format(
237-
status_code=acme_register_response.status_code,
238-
response=log_response(acme_register_response),
238+
status_code=response.status_code, response=log_response(response),
239239
)
240240
)
241241

242-
self.acct_key.set_kid(acme_register_response.headers["Location"])
242+
self.acct_key.set_kid(response.headers["Location"])
243243

244244
self.logger.info("acme_register_success")
245-
return acme_register_response
245+
return response
246246

247247
def apply_for_cert_issuance(self):
248248
"""

sewer/tests/test_Client.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,23 @@
2424

2525
LOG_LEVEL = "CRITICAL"
2626

27-
keys_for_ACME = {"acct_key": AcmeKey.create("rsa2048"), "cert_key": AcmeKey.create("rsa2048")}
27+
### FIX ME ### even with making the keys new each time, some tests manage to re-register!
28+
# luckily it's working anyway, but it's a good thing most of this will have to be scrapped soon
2829

29-
usual_ACME = {
30-
"ACME_REQUEST_TIMEOUT": 1,
31-
"ACME_AUTH_STATUS_WAIT_PERIOD": 0,
32-
"ACME_DIRECTORY_URL": ACME_DIRECTORY_URL_STAGING,
33-
"LOG_LEVEL": LOG_LEVEL,
34-
}
35-
usual_ACME.update(keys_for_ACME)
30+
31+
def keys_for_ACME():
32+
return {"acct_key": AcmeKey.create("secp256r1"), "cert_key": AcmeKey.create("secp256r1")}
33+
34+
35+
def usual_ACME():
36+
res = {
37+
"ACME_REQUEST_TIMEOUT": 1,
38+
"ACME_AUTH_STATUS_WAIT_PERIOD": 0,
39+
"ACME_DIRECTORY_URL": ACME_DIRECTORY_URL_STAGING,
40+
"LOG_LEVEL": LOG_LEVEL,
41+
}
42+
res.update(keys_for_ACME())
43+
return res
3644

3745

3846
class TestClient(TestCase):
@@ -57,7 +65,7 @@ def setUp(self):
5765

5866
self.provider = test_utils.ExmpleHttpProvider()
5967
self.client = sewer.client.Client(
60-
domain_name=self.domain_name, provider=self.provider, **usual_ACME
68+
domain_name=self.domain_name, provider=self.provider, **usual_ACME()
6169
)
6270

6371
def tearDown(self):
@@ -74,7 +82,7 @@ def mock_create_acme_client():
7482
provider=test_utils.ExmpleHttpProvider(),
7583
ACME_DIRECTORY_URL=ACME_DIRECTORY_URL_STAGING,
7684
LOG_LEVEL=LOG_LEVEL,
77-
**keys_for_ACME,
85+
**keys_for_ACME(),
7886
)
7987

8088
self.assertRaises(ValueError, mock_create_acme_client)
@@ -243,7 +251,7 @@ def mock_instantiate_client():
243251
domain_name=self.domain_name,
244252
provider=self.provider,
245253
domain_alt_names="domain_alt_names",
246-
**usual_ACME,
254+
**usual_ACME(),
247255
)
248256

249257
with self.assertRaises(ValueError) as raised_exception:
@@ -275,7 +283,7 @@ def setUp(self):
275283
domain_name="exampleSAN.com",
276284
dns_class=self.dns_class,
277285
domain_alt_names=self.domain_alt_names,
278-
**usual_ACME,
286+
**usual_ACME(),
279287
)
280288
super(TestClientForSAN, self).setUp()
281289

@@ -305,7 +313,7 @@ def setUp(self):
305313
dns_class=self.dns_class,
306314
domain_alt_names=self.domain_alt_names,
307315
ACME_AUTH_STATUS_MAX_CHECKS=1,
308-
**usual_ACME,
316+
**usual_ACME(),
309317
)
310318
super(TestClientForWildcard, self).setUp()
311319

@@ -327,7 +335,7 @@ def setUp(self):
327335

328336
self.dns_class = test_utils.ExmpleDnsProvider()
329337
self.client = sewer.client.Client(
330-
domain_name=self.domain_name, dns_class=self.dns_class, **usual_ACME
338+
domain_name=self.domain_name, dns_class=self.dns_class, **usual_ACME()
331339
)
332340

333341
def test_get_get_acme_endpoints_failure_results_in_exception_with(self):
@@ -341,7 +349,7 @@ def mock_create_acme_client():
341349
dns_class=test_utils.ExmpleDnsProvider(), # NOTE: dns_class used here
342350
ACME_DIRECTORY_URL=ACME_DIRECTORY_URL_STAGING,
343351
LOG_LEVEL=LOG_LEVEL,
344-
**keys_for_ACME,
352+
**keys_for_ACME(),
345353
)
346354

347355
self.assertRaises(ValueError, mock_create_acme_client)
@@ -377,7 +385,7 @@ def mock_instantiate_client():
377385
domain_name=self.domain_name,
378386
dns_class=self.dns_class, # NOTE: dns_class used here
379387
domain_alt_names="domain_alt_names",
380-
**usual_ACME,
388+
**usual_ACME(),
381389
)
382390

383391
with self.assertRaises(ValueError) as raised_exception:
@@ -392,7 +400,7 @@ class TestClientUnits(TestCase):
392400
def __init__(self, *args, **kwargs):
393401
super().__init__(*args, **kwargs)
394402
self.mock_args = {"domain_name": "example.com", "LOG_LEVEL": LOG_LEVEL}
395-
self.mock_args.update(keys_for_ACME)
403+
self.mock_args.update(keys_for_ACME())
396404
self.mock_challenges = [{"ident_value": "example.com", "key_auth": "abcdefgh12345678"}]
397405

398406
def mock_sewer(self, provider):

0 commit comments

Comments
 (0)