Add new account

This commit is contained in:
Fang-Pen Lin
2025-11-07 09:17:46 -08:00
parent 6b220030d1
commit c4ced36767
7 changed files with 81 additions and 11 deletions
+28 -8
View File
@@ -1,22 +1,35 @@
from behave.runner import Context
import json
from behave.runner import Context
from behave import given
from behave import when
from behave import then
class PkiProject:
class AcmeProfile:
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):
def replace_vars(payload: dict, vars: dict):
for key, value in payload.items():
if isinstance(value, dict):
replace_vars(value, vars)
elif isinstance(value, list):
payload[key] = [replace_vars(item, vars) for item in value]
elif isinstance(value, str):
payload[key] = value.format(**vars)
else:
payload[key] = value
@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 project instead
# we should call infisical API to create such profile instead
# in the future
project_id = "c051e74c-48a7-4724-832c-d5b496698546"
context.vars[project_var] = PkiProject(project_id)
profile_id = "c051e74c-48a7-4724-832c-d5b496698546"
context.vars[profile_var] = AcmeProfile(profile_id)
@when('I send a {method} request to "{url}"')
@@ -34,8 +47,15 @@ def step_impl(context: Context, expected_status_code: int):
@then('the response header "{header}" should contains non-empty value')
def step_impl(context: Context, header: str):
header_value = context.response.headers.get(header)
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"
)
@then("the response body should match JSON value")
def step_impl(context: Context):
payload = context.response.json()
expected = json.loads(context.text)
replace_vars(expected, context.vars)
assert payload == expected, f"{payload} != {expected}"