From 1ad84f0450f0de30a14c36b16fc15f561cd35059 Mon Sep 17 00:00:00 2001 From: Fang-Pen Lin Date: Fri, 7 Nov 2025 11:24:13 -0800 Subject: [PATCH] Provision a new profile automatically if not provided --- backend/bdd/features/steps/pki_acme.py | 35 +++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/backend/bdd/features/steps/pki_acme.py b/backend/bdd/features/steps/pki_acme.py index be4383b08..33dc8c939 100644 --- a/backend/bdd/features/steps/pki_acme.py +++ b/backend/bdd/features/steps/pki_acme.py @@ -138,12 +138,39 @@ def step_impl(context: Context, faker_type: str, var_name: str): @given('I have an ACME cert profile as "{profile_var}"') def step_impl(context: Context, profile_var: str): - # TODO: Fixed value for now, just to make test much easier, - # we should call infisical API to create such profile instead - # in the future profile_id = os.getenv("PROFILE_ID") - kid = profile_id secret = os.getenv("EAB_SECRET") + if profile_id is None and secret is None: + kid = profile_id + + else: + profile_slug = faker.slug() + response = context.http_client.post( + "/api/v1/pki/certificate-profiles", + headers=prepare_headers(context), + json={ + "projectId": context.vars["PROJECT_ID"], + "slug": profile_slug, + "description": "ACME Profile created by BDD test", + "enrollmentType": "acme", + "caId": context.vars["CERT_CA_ID"], + "certificateTemplateId": context.vars["CERT_TEMPLATE_ID"], + "acmeConfig": {}, + }, + ) + response.raise_for_status() + resp_json = response.json() + profile_id = resp_json["certificateProfile"]["id"] + kid = profile_id + + response = context.http_client.get( + f"/api/v1/pki/certificate-profiles/{profile_id}/acme/eab-secret/reveal", + headers=prepare_headers(context), + ) + response.raise_for_status() + resp_json = response.json() + secret = resp_json["eabSecret"] + context.vars[profile_var] = AcmeProfile( profile_id, eab_kid=kid,