Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Add test for fetch order
Fang-Pen Lin0f3dce40265b
diff --git a/backend/bdd/features/pki/acme/new-order.feature b/backend/bdd/features/pki/acme/new-order.featureindex 35d1f23fe2..fee66245fc 100644--- a/backend/bdd/features/pki/acme/new-order.feature+++ b/backend/bdd/features/pki/acme/new-order.feature@@ -16,7 +16,13 @@ Feature: New OrderThen I create a RSA private key pair as cert_keyThen I sign the certificate signing request csr with private key cert_key and output it as csr_pem in PEM formatThen I submit the certificate signing request PEM csr_pem certificate order to the ACME server as order- Then the value order.uri should be true for jq startswith("{BASE_URL}/api/v1/pki/acme/profiles/{acme_profile.id}/orders/")+ Then the value order.uri with jq . should match pattern {BASE_URL}/api/v1/pki/acme/profiles/{acme_profile.id}/orders/(.+)Then the value order.body with jq .status should be equal to "pending"Then the value order.body with jq .identifiers should be equal to [{"type": "dns", "value": "localhost"}]+ Then the value order.body with jq .finalize should match pattern {BASE_URL}/api/v1/pki/acme/profiles/{acme_profile.id}/orders/(.+)/finalizeThen the value order.body with jq all(.authorizations[]; startswith("{BASE_URL}/api/v1/pki/acme/profiles/{acme_profile.id}/authorizations/")) should be equal to true+ Then I send an ACME post-as-get to order.uri as fetched_order+ Then the value fetched_order with jq .status should be equal to "pending"+ Then the value fetched_order with jq .identifiers should be equal to [{"type": "dns", "value": "localhost"}]+ Then the value fetched_order with jq .finalize should match pattern {BASE_URL}/api/v1/pki/acme/profiles/{acme_profile.id}/orders/(.+)/finalize+ Then the value fetched_order with jq all(.authorizations[]; startswith("{BASE_URL}/api/v1/pki/acme/profiles/{acme_profile.id}/authorizations/")) should be equal to truediff --git a/backend/bdd/features/steps/pki_acme.py b/backend/bdd/features/steps/pki_acme.pyindex 8e82a95a02..6167faaa9e 100644--- a/backend/bdd/features/steps/pki_acme.py+++ b/backend/bdd/features/steps/pki_acme.py@@ -1,6 +1,8 @@import json+import reimport jq+import requestsfrom acme import clientfrom acme import messagesfrom behave.runner import Context@@ -47,6 +49,8 @@ def eval_var(context: Context, var_path: str, as_json: bool = True):if as_json:if isinstance(value, JSONObjectWithFields):value = value.to_json()+ elif isinstance(value, requests.Response):+ value = value.json()return value@@ -121,6 +125,12 @@ def step_impl(context: Context, pem_var: str, order_var: str):context.vars[order_var] = context.acme_client.new_order(context.vars[pem_var])+@then("I send an ACME post-as-get to {uri_path} as {res_var}")+def step_impl(context: Context, uri_path: str, res_var: str):+ uri_value = eval_var(context, uri_path)+ context.vars[res_var] = context.acme_client._post_as_get(uri_value)++@when("I create certificate signing request as {csr_var}")def step_impl(context: Context, csr_var: str):context.vars[csr_var] = x509.CertificateSigningRequestBuilder()@@ -177,26 +187,48 @@ def step_impl(context: Context, var_path: str, query: str):assert result, f"{value} does not match {query}"-def match_value_with_jq(context: Context, var_path: str, jq_query: str, expected: str):+def apply_value_with_jq(context: Context, var_path: str, jq_query: str):value = eval_var(context, var_path)- result = jq.compile(replace_vars(jq_query, context.vars)).input_value(value).first()- expected_value = json.loads(expected)- assert result == expected_value, (- f"{json.dumps(value)!r} with jq {jq_query!r}, the result {json.dumps(result)!r} does not match {json.dumps(expected_value)!r}"- )+ return value, jq.compile(replace_vars(jq_query, context.vars)).input_value(+ value+ ).first()@then("the value {var_path} with jq {jq_query} should be equal to json")def step_impl(context: Context, var_path: str, jq_query: str):- return match_value_with_jq(- context=context, var_path=var_path, jq_query=jq_query, expected=context.text+ value, result = apply_value_with_jq(+ context=context,+ var_path=var_path,+ jq_query=jq_query,+ )+ expected_value = json.loads(context.text)+ assert result == expected_value, (+ f"{json.dumps(value)!r} with jq {jq_query!r}, the result {json.dumps(result)!r} does not match {json.dumps(expected_value)!r}")@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):- return match_value_with_jq(- context=context, var_path=var_path, jq_query=jq_query, expected=expected+ value, result = apply_value_with_jq(+ context=context,+ var_path=var_path,+ jq_query=jq_query,+ )+ expected_value = json.loads(expected)+ assert result == expected_value, (+ f"{json.dumps(value)!r} with jq {jq_query!r}, the result {json.dumps(result)!r} does not match {json.dumps(expected_value)!r}"+ )+++@then("the value {var_path} with jq {jq_query} should match pattern {regex}")+def step_impl(context: Context, var_path: str, jq_query: str, regex: str):+ value, result = apply_value_with_jq(+ context=context,+ var_path=var_path,+ jq_query=jq_query,+ )+ assert re.match(replace_vars(regex, context.vars), result), (+ f"{json.dumps(value)!r} with jq {jq_query!r}, the result {json.dumps(result)!r} does not match {regex!r}")@@ -205,3 +237,9 @@ def step_impl(context: Context, var_path: str, expected: str):value = eval_var(context, var_path)expected_value = json.loads(expected)assert value == expected_value, f"{value!r} does not match {expected_value!r}"+++@then("I print the value {var_path}")+def step_impl(context: Context, var_path: str):+ value = eval_var(context, var_path)+ print(json.dumps(value.json(), indent=2))