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
+3 -1
View File
@@ -8,7 +8,9 @@ AUTH_TOKEN = os.environ.get("INFISICAL_TOKEN")
def before_all(context: Context):
context.vars = {}
context.vars = {
"BASE_URL": BASE_URL,
}
context.http_client = httpx.Client(
base_url=BASE_URL, # headers={"Authorization": f"Bearer {AUTH_TOKEN}"}
)
@@ -0,0 +1,13 @@
Feature: Directory
Scenario: Get the directory of ACME service urls
Given I have an ACME cert profile as "acme_profile"
When I send a GET request to "/api/v1/pki/acme/profiles/{acme_profile.id}/directory"
Then the response status code should be "200"
Then the response body should match JSON value
"""
{
"newNonce": "{BASE_URL}/api/v1/pki/acme/profiles/{acme_profile.id}/new-nonce",
"newAccount": "{BASE_URL}/api/v1/pki/acme/profiles/{acme_profile.id}/new-account",
"newOrder": "{BASE_URL}/api/v1/pki/acme/profiles/{acme_profile.id}/new-order"
}
"""
@@ -0,0 +1,4 @@
Feature: New Account
Scenario: Create a new account
Given I have an ACME cert profile as "acme_profile"
When I register a new ACME account
@@ -1,6 +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 "/api/v1/pki/acme/profiles/{pki_project.id}/new-nonce"
Given I have an ACME cert profile as "acme_profile"
When I send a HEAD request to "/api/v1/pki/acme/profiles/{acme_profile.id}/new-nonce"
Then the response status code should be "200"
Then the response header "Replay-Nonce" should contains non-empty value
+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}"