diff --git a/backend/bdd/features/pki/acme/challenge.feature b/backend/bdd/features/pki/acme/challenge.feature index 0bf568123..2079b9a57 100644 --- a/backend/bdd/features/pki/acme/challenge.feature +++ b/backend/bdd/features/pki/acme/challenge.feature @@ -17,4 +17,5 @@ Feature: Challenge 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 for domain localhost from order at order as challenge + Then I serve challenge response for challenge at localhost diff --git a/backend/bdd/features/steps/pki_acme.py b/backend/bdd/features/steps/pki_acme.py index ca90c5415..f1219b801 100644 --- a/backend/bdd/features/steps/pki_acme.py +++ b/backend/bdd/features/steps/pki_acme.py @@ -6,6 +6,7 @@ import requests import glom from acme import client from acme import messages +from acme import standalone from behave.runner import Context from behave import given from behave import when @@ -340,4 +341,21 @@ def step_impl( raise ValueError( f"More than one authorization for type {challenge_type!r} found in {var_path!r}" ) - context.vars[challenge_var] = auths[0] + context.vars[challenge_var] = challenges[0] + + +@then("I serve challenge response for {var_path} at {hostname}") +def step_impl(context: Context, var_path: str, hostname: str): + if hostname != "localhost": + raise ValueError("Currently only localhost is supported") + challenge = eval_var(context, var_path, as_json=False) + acme_challenge = challenge.chall + response, validation = acme_challenge.response_and_validation( + context.acme_client.net.key + ) + resource = standalone.HTTP01RequestHandler.HTTP01Resource( + chall=acme_challenge, response=response, validation=validation + ) + servers = standalone.HTTP01DualNetworkedServers(("", 8087), resource) + # Start client standalone web server. + servers.serve_forever()