Add challenge selection

This commit is contained in:
Fang-Pen Lin
2025-11-07 09:19:11 -08:00
parent 6cf08622ed
commit 5d31627afd
2 changed files with 26 additions and 7 deletions
@@ -16,5 +16,5 @@ Feature: Challenge
Then I create a RSA private key pair as cert_key
Then I sign the certificate signing request csr with private key cert_key and output it as csr_pem in PEM format
Then I submit the certificate signing request PEM csr_pem certificate order to the ACME server as order
Then I select challenge with type http-01 from order as challenge
Then I select challenge with type http-01 for domain localhost from order at order as challenge
+25 -6
View File
@@ -304,20 +304,39 @@ def step_impl(context: Context, var_path: str):
@then(
"I select challenge with type {challenge_type} from {var_path} as {challenge_var}"
"I select challenge with type {challenge_type} for domain {domain} from order at {var_path} as {challenge_var}"
)
def step_impl(context: Context, challenge_type: str, var_path: str, challenge_var: str):
order = eval_var(context, var_path)
def step_impl(
context: Context,
challenge_type: str,
domain: str,
var_path: str,
challenge_var: str,
):
order = eval_var(context, var_path, as_json=False)
if not isinstance(order, messages.OrderResource):
raise ValueError(
f"Expected OrderResource but got {(type(order),)!r} at {var_path!r}"
f"Expected OrderResource but got {type(order)!r} at {var_path!r}"
)
auths = list(filter(lambda a: a.type == challenge_type, order.authorizations))
auths = list(
filter(lambda o: o.body.identifier.value == domain, order.authorizations)
)
if not auths:
raise ValueError(
f"Authorization for domain {domain!r} not found in {var_path!r}"
)
if len(auths) > 1:
raise ValueError(
f"More than one order for domain {domain!r} found in {var_path!r}"
)
auth = auths[0]
challenges = list(filter(lambda a: a.typ == challenge_type, auth.body.challenges))
if not challenges:
raise ValueError(
f"Authorization type {challenge_type!r} not found in {var_path!r}"
)
if len(auths) > 1:
if len(challenges) > 1:
raise ValueError(
f"More than one authorization for type {challenge_type!r} found in {var_path!r}"
)