Add bdd stuff

This commit is contained in:
Fang-Pen Lin
2025-11-07 09:17:43 -08:00
parent 936b54073a
commit 375a74fc26
7 changed files with 236 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
from behave.runner import Context
def before_all(context: Context):
context.vars = {}
@@ -0,0 +1,5 @@
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"
Then the response header "Replay-Nonce" should contains non-empty value
+35
View File
@@ -0,0 +1,35 @@
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
@given('I have a PKI project as "{project_var}"')
def step_impl(context: Context, project_var: str):
# TODO: Fixed value for now, just to make test much easier,
# we should call infisical API to create such project instead
# in the future
project_id = "c051e74c-48a7-4724-832c-d5b496698546"
context.vars[project_var] = PkiProject(project_id)
@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))
@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