From d3539e1d3ae55afceea7fd78ac94c5342ccaf797 Mon Sep 17 00:00:00 2001 From: Fang-Pen Lin Date: Mon, 27 Oct 2025 12:10:33 -0700 Subject: [PATCH] Add more steps --- backend/bdd/features/environment.py | 9 +++++++++ .../bdd/features/pki/nonce/pki-acme.feature | 3 ++- backend/bdd/features/steps/pki_acme.py | 20 ++++++++++++------- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/backend/bdd/features/environment.py b/backend/bdd/features/environment.py index 33d5238a0..20ffe31c6 100644 --- a/backend/bdd/features/environment.py +++ b/backend/bdd/features/environment.py @@ -1,5 +1,14 @@ +import os + +import httpx from behave.runner import Context +BASE_URL = os.environ.get("INFISICAL_API_URL", "http://localhost:8080") +AUTH_TOKEN = os.environ.get("INFISICAL_TOKEN") + def before_all(context: Context): context.vars = {} + context.http_client = httpx.Client( + base_url=BASE_URL, headers={"Authorization": f"Bearer {AUTH_TOKEN}"} + ) diff --git a/backend/bdd/features/pki/nonce/pki-acme.feature b/backend/bdd/features/pki/nonce/pki-acme.feature index f8a1bd890..77f408ba3 100644 --- a/backend/bdd/features/pki/nonce/pki-acme.feature +++ b/backend/bdd/features/pki/nonce/pki-acme.feature @@ -1,5 +1,6 @@ Feature: Nonce Scenario: Generate a new nonce Given I have a PKI project as "pki_project" - When I send a HEAD request to "/v1/pki/acme/profiles/{pki_project.id}/new-nonce" + When I send a HEAD request to "/api/v1/pki/acme/profiles/{pki_project.id}/new-nonce" + Then the response status code should be "200" Then the response header "Replay-Nonce" should contains non-empty value diff --git a/backend/bdd/features/steps/pki_acme.py b/backend/bdd/features/steps/pki_acme.py index dd173a927..d1ead5c23 100644 --- a/backend/bdd/features/steps/pki_acme.py +++ b/backend/bdd/features/steps/pki_acme.py @@ -1,14 +1,10 @@ from behave.runner import Context -import httpx from behave import given from behave import when from behave import then -BASE_URL = "http://localhost:8080" - - class PkiProject: def __init__(self, id: str): self.id = id @@ -25,11 +21,21 @@ def step_impl(context: Context, project_var: str): @when('I send a {method} request to "{url}"') def step_impl(context: Context, method: str, url: str): - with httpx.Client(base_url=BASE_URL) as client: - context.response = client.request(method, url.format(**context.vars)) + context.response = context.http_client.request(method, url.format(**context.vars)) + + +@then('the response status code should be "{expected_status_code}"') +def step_impl(context: Context, expected_status_code: int): + assert context.response.status_code == expected_status_code, ( + f"{context.response.status_code} != {expected_status_code}" + ) @then('the response header "{header}" should contains non-empty value') def step_impl(context: Context, header: str): header_value = context.response.headers.get(header) - assert header_value + print(context.response.headers) + assert header_value is not None, f"Header {header} not found in response" + assert header_value, ( + f"Header {header} found in response, but value {header_value:!r} is empty" + )