diff --git a/backend/bdd/features/environment.py b/backend/bdd/features/environment.py index 5b94d0415..8aa78e276 100644 --- a/backend/bdd/features/environment.py +++ b/backend/bdd/features/environment.py @@ -4,12 +4,20 @@ import httpx from behave.runner import Context BASE_URL = os.environ.get("INFISICAL_API_URL", "http://localhost:8080") +PROJECT_ID = os.environ.get("PROJECT_ID", "c051e74c-48a7-4724-832c-d5b496698546") +CERT_CA_ID = os.environ.get("CERT_CA_ID", "2f0d9820-e5a8-48bb-aac8-deed9d868a1e") +CERT_TEMPLATE_ID = os.environ.get( + "CERT_TEMPLATE_ID", "4dbf6bb0-6e86-4ee6-8550-9171428c8e82" +) AUTH_TOKEN = os.environ.get("INFISICAL_TOKEN") def before_all(context: Context): context.vars = { "BASE_URL": BASE_URL, + "PROJECT_ID": PROJECT_ID, + "CERT_CA_ID": CERT_CA_ID, + "CERT_TEMPLATE_ID": CERT_TEMPLATE_ID, } context.http_client = httpx.Client( base_url=BASE_URL, # headers={"Authorization": f"Bearer {AUTH_TOKEN}"} diff --git a/backend/bdd/features/pki/acme/cert-profile.feature b/backend/bdd/features/pki/acme/cert-profile.feature new file mode 100644 index 000000000..4af911a93 --- /dev/null +++ b/backend/bdd/features/pki/acme/cert-profile.feature @@ -0,0 +1,23 @@ +Feature: ACME Cert Profile + + Scenario: Create a cert profile + Given I make a random slug as profile_slug + When I send a POST request to "/api/v1/pki/certificate-profiles" with JSON payload + """ + { + "projectId": "{PROJECT_ID}", + "slug": "{profile_slug}", + "description": "", + "enrollmentType": "acme", + "caId": "{CA_ID}", + "certificateTemplateId": "{CERT_TEMPLATE_ID}", + "acmeConfig": {} + } + """ + Then the value response.status should be equal to 201 + Then the value response with jq .eab_kid should be present + Then the value response with jq .eab_secret should be present + Then the value response with jq .slug should be equal to {profile_slug} + Then the value response with jq .caId should be equal to {CA_ID} + Then the value response with jq .certificateTemplateId should be equal to {CERT_TEMPLATE_ID} + Then the value response with jq .enrollmentTYpe should be equal to acme diff --git a/backend/bdd/features/steps/pki_acme.py b/backend/bdd/features/steps/pki_acme.py index 3156d4a71..81b4b6023 100644 --- a/backend/bdd/features/steps/pki_acme.py +++ b/backend/bdd/features/steps/pki_acme.py @@ -2,6 +2,7 @@ import json import re import threading +import faker import jq import requests import glom @@ -107,6 +108,11 @@ def eval_var(context: Context, var_path: str, as_json: bool = True): return value +@given("I make a random {faker_type} as {var_name}") +def step_impl(context: Context, faker_type: str, var_name: str): + context.vars[var_name] = getattr(faker, faker_type)() + + @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, @@ -121,6 +127,13 @@ def step_impl(context: Context, method: str, url: str): context.response = context.http_client.request(method, url.format(**context.vars)) +@when('I send a {method} request to "{url}" with JSON payload') +def step_impl(context: Context, method: str, url: str): + context.response = context.http_client.request( + method, url.format(**context.vars), json_payload=context.text + ) + + @when("I have an ACME client connecting to {url}") def step_impl(context: Context, url: str): private_key = rsa.generate_private_key( @@ -260,6 +273,18 @@ def step_impl(context: Context, var_path: str, jq_query: str): ) +@then("the value {var_path} with jq {jq_query} should be present") +def step_impl(context: Context, var_path: str, jq_query: str): + value, result = apply_value_with_jq( + context=context, + var_path=var_path, + jq_query=jq_query, + ) + assert result, ( + f"{json.dumps(value)!r} with jq {jq_query!r}, the result {json.dumps(result)!r} is not present" + ) + + @then("the value {var_path} with jq {jq_query} should be equal to {expected}") def step_impl(context: Context, var_path: str, jq_query: str, expected: str): value, result = apply_value_with_jq( diff --git a/backend/bdd/pyproject.toml b/backend/bdd/pyproject.toml index 80e1979a1..2decf1967 100644 --- a/backend/bdd/pyproject.toml +++ b/backend/bdd/pyproject.toml @@ -7,6 +7,7 @@ requires-python = ">=3.12" dependencies = [ "acme>=5.1.0", "behave>=1.3.3", + "faker>=37.12.0", "glom>=24.11.0", "httpx>=0.28.1", "josepy>=2.2.0", diff --git a/backend/bdd/uv.lock b/backend/bdd/uv.lock index beceb0f26..17e9a4d28 100644 --- a/backend/bdd/uv.lock +++ b/backend/bdd/uv.lock @@ -48,6 +48,7 @@ source = { virtual = "." } dependencies = [ { name = "acme" }, { name = "behave" }, + { name = "faker" }, { name = "glom" }, { name = "httpx" }, { name = "josepy" }, @@ -58,6 +59,7 @@ dependencies = [ requires-dist = [ { name = "acme", specifier = ">=5.1.0" }, { name = "behave", specifier = ">=1.3.3" }, + { name = "faker", specifier = ">=37.12.0" }, { name = "glom", specifier = ">=24.11.0" }, { name = "httpx", specifier = ">=0.28.1" }, { name = "josepy", specifier = ">=2.2.0" }, @@ -308,6 +310,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/e9/47/21867c2e5fd006c8d36a560df9e32cb4f1f566b20c5dd41f5f8a2124f7de/face-24.0.0-py3-none-any.whl", hash = "sha256:0e2c17b426fa4639a4e77d1de9580f74a98f4869ba4c7c8c175b810611622cd3", size = 54742, upload-time = "2024-11-02T05:24:24.939Z" }, ] +[[package]] +name = "faker" +version = "37.12.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "tzdata" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/3d/84/e95acaa848b855e15c83331d0401ee5f84b2f60889255c2e055cb4fb6bdf/faker-37.12.0.tar.gz", hash = "sha256:7505e59a7e02fa9010f06c3e1e92f8250d4cfbb30632296140c2d6dbef09b0fa", size = 1935741, upload-time = "2025-10-24T15:19:58.764Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/8e/98/2c050dec90e295a524c9b65c4cb9e7c302386a296b2938710448cbd267d5/faker-37.12.0-py3-none-any.whl", hash = "sha256:afe7ccc038da92f2fbae30d8e16d19d91e92e242f8401ce9caf44de892bab4c4", size = 1975461, upload-time = "2025-10-24T15:19:55.739Z" }, +] + [[package]] name = "glom" version = "24.11.0" @@ -503,6 +517,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/18/67/36e9267722cc04a6b9f15c7f3441c2363321a3ea07da7ae0c0707beb2a9c/typing_extensions-4.15.0-py3-none-any.whl", hash = "sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548", size = 44614, upload-time = "2025-08-25T13:49:24.86Z" }, ] +[[package]] +name = "tzdata" +version = "2025.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/95/32/1a225d6164441be760d75c2c42e2780dc0873fe382da3e98a2e1e48361e5/tzdata-2025.2.tar.gz", hash = "sha256:b60a638fcc0daffadf82fe0f57e53d06bdec2f36c4df66280ae79bce6bd6f2b9", size = 196380, upload-time = "2025-03-23T13:54:43.652Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/5c/23/c7abc0ca0a1526a0774eca151daeb8de62ec457e77262b66b359c3c7679e/tzdata-2025.2-py2.py3-none-any.whl", hash = "sha256:1a403fada01ff9221ca8044d701868fa132215d84beb92242d9acd2147f667a8", size = 347839, upload-time = "2025-03-23T13:54:41.845Z" }, +] + [[package]] name = "urllib3" version = "2.5.0"