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 PKI SCEP e2e tests
Carlos Monastyrski387f0ad6c7ef
diff --git a/.github/workflows/run-backend-bdd-tests.yml b/.github/workflows/run-backend-bdd-tests.ymlindex 217a9ec4c3..7488367b07 100644--- a/.github/workflows/run-backend-bdd-tests.yml+++ b/.github/workflows/run-backend-bdd-tests.yml@@ -45,6 +45,8 @@ jobs:uses: actions/setup-python@v5with:python-version: "3.11"+ - name: Install sscep (SCEP client for BDD tests)+ run: sudo apt-get update && sudo apt-get install -y sscep- name: Install dependenciesrun: npm installworking-directory: backend@@ -64,8 +66,9 @@ jobs:# We are not using FIPS mode, need a different encryption key for BDD testsNEW_ENCRYPTION_KEY=6c1fe4e407b8911c104518103505b218sed -i "s#ENCRYPTION_KEY=.*#ENCRYPTION_KEY=$NEW_ENCRYPTION_KEY#" .env- # Enable ACME feature in license for BDD tests+ # Enable ACME and SCEP features in license for BDD testssed -i 's/pkiAcme: .*/pkiAcme: true,/g' backend/src/ee/services/license/license-fns.ts+ sed -i 's/pkiScep: .*/pkiScep: true,/g' backend/src/ee/services/license/license-fns.ts- name: Set up Docker Buildxuses: docker/setup-buildx-action@v3with:diff --git a/backend/bdd/features/environment.py b/backend/bdd/features/environment.pyindex e3724396de..ee0b3a13c8 100644--- a/backend/bdd/features/environment.py+++ b/backend/bdd/features/environment.py@@ -1,5 +1,6 @@import jsonimport os+import shutilimport pathlibimport typing@@ -222,5 +223,9 @@ def before_scenario(context: Context, scenario: typing.Any):def after_scenario(context: Context, scenario: typing.Any):if hasattr(context, "web_server"):context.web_server.shutdown_and_server_close()+ # Clean up SCEP temp directories+ for work_dir in getattr(context, "_scep_work_dirs", []):+ shutil.rmtree(work_dir, ignore_errors=True)+ context._scep_work_dirs = []clean_all_nock(context)restore_nock(context)diff --git a/backend/bdd/features/pki/scep/enrollment-failure.feature b/backend/bdd/features/pki/scep/enrollment-failure.featurenew file mode 100644index 0000000000..a72a6702c7--- /dev/null+++ b/backend/bdd/features/pki/scep/enrollment-failure.feature@@ -0,0 +1,16 @@+Feature: Enrollment Failure++ Scenario: Enrollment with wrong challenge password+ Given I have a SCEP cert profile with challenge password "testpassword123" as "scep_profile"+ When I enroll via SCEP for CN "test-device.example.com" with challenge "wrongpassword99" on profile "scep_profile"+ Then the SCEP enrollment should fail++ Scenario: Enrollment without challenge password+ Given I have a SCEP cert profile with challenge password "testpassword123" as "scep_profile"+ When I enroll via SCEP for CN "test-device.example.com" without challenge password on profile "scep_profile"+ Then the SCEP enrollment should fail++ Scenario: GetCACaps against non-existent profile returns 404+ Given I make a random uuid4 as FAKE_PROFILE_ID+ When I send a "GET" request to "/scep/{FAKE_PROFILE_ID}/pkiclient.exe?operation=GetCACaps"+ Then the response status code should be "404"diff --git a/backend/bdd/features/pki/scep/enrollment.feature b/backend/bdd/features/pki/scep/enrollment.featurenew file mode 100644index 0000000000..368286b082--- /dev/null+++ b/backend/bdd/features/pki/scep/enrollment.feature@@ -0,0 +1,23 @@+Feature: Enrollment++ Scenario: Successful enrollment with valid challenge password+ Given I have a SCEP cert profile with challenge password "testpassword123" as "scep_profile"+ When I enroll via SCEP for CN "test-device.example.com" with challenge "testpassword123" on profile "scep_profile"+ Then the SCEP enrollment should succeed+ And the issued SCEP certificate subject CN should be "test-device.example.com"+ And the issued SCEP certificate should be signed by the CA++ Scenario: Enrollment with different common names+ Given I have a SCEP cert profile with challenge password "mySecurePass99" as "scep_profile"+ When I enroll via SCEP for CN "router-01.corp.local" with challenge "mySecurePass99" on profile "scep_profile"+ Then the SCEP enrollment should succeed+ And the issued SCEP certificate subject CN should be "router-01.corp.local"++ Scenario: Multiple enrollments on the same profile+ Given I have a SCEP cert profile with challenge password "testpassword123" as "scep_profile"+ When I enroll via SCEP for CN "device-01.example.com" with challenge "testpassword123" on profile "scep_profile"+ Then the SCEP enrollment should succeed+ And the issued SCEP certificate subject CN should be "device-01.example.com"+ When I enroll via SCEP for CN "device-02.example.com" with challenge "testpassword123" on profile "scep_profile"+ Then the SCEP enrollment should succeed+ And the issued SCEP certificate subject CN should be "device-02.example.com"diff --git a/backend/bdd/features/pki/scep/getcacaps.feature b/backend/bdd/features/pki/scep/getcacaps.featurenew file mode 100644index 0000000000..bfce7ad33a--- /dev/null+++ b/backend/bdd/features/pki/scep/getcacaps.feature@@ -0,0 +1,36 @@+Feature: GetCACaps++ Scenario: Get capabilities for a SCEP profile+ Given I have a SCEP cert profile with challenge password "testpassword123" as "scep_profile"+ When I send a SCEP GetCACaps request for profile "scep_profile"+ Then the response status code should be "200"+ And the response content type should be "text/plain"+ And the SCEP GetCACaps response should contain "POSTPKIOperation"+ And the SCEP GetCACaps response should contain "SHA-256"+ And the SCEP GetCACaps response should contain "SHA-1"+ And the SCEP GetCACaps response should contain "AES"+ And the SCEP GetCACaps response should contain "DES3"+ And the SCEP GetCACaps response should contain "SCEPStandard"++ Scenario: Get capabilities with cert-based renewal enabled+ Given I have a SCEP cert profile with config as "scep_profile"+ """+ { "challengePassword": "testpassword123", "allowCertBasedRenewal": true }+ """+ When I send a SCEP GetCACaps request for profile "scep_profile"+ Then the response status code should be "200"+ And the SCEP GetCACaps response should contain "Renewal"++ Scenario: Get capabilities with cert-based renewal disabled+ Given I have a SCEP cert profile with config as "scep_profile"+ """+ { "challengePassword": "testpassword123", "allowCertBasedRenewal": false }+ """+ When I send a SCEP GetCACaps request for profile "scep_profile"+ Then the response status code should be "200"+ And the SCEP GetCACaps response should not contain "Renewal"++ Scenario: Unsupported SCEP operation returns 400+ Given I have a SCEP cert profile with challenge password "testpassword123" as "scep_profile"+ When I send a SCEP request with unsupported operation "BadOperation" for profile "scep_profile"+ Then the response status code should be "400"diff --git a/backend/bdd/features/pki/scep/getcacert.feature b/backend/bdd/features/pki/scep/getcacert.featurenew file mode 100644index 0000000000..99069dea9d--- /dev/null+++ b/backend/bdd/features/pki/scep/getcacert.feature@@ -0,0 +1,25 @@+Feature: GetCACert++ Scenario: Get CA cert bundle with CA cert included+ Given I have a SCEP cert profile with config as "scep_profile"+ """+ { "challengePassword": "testpassword123", "includeCaCertInResponse": true }+ """+ When I fetch the SCEP CA certificates for profile "scep_profile"+ Then the SCEP CA certificate bundle should contain at least 2 certificate(s)+ And the first certificate in the SCEP bundle should have CN containing Infisical SCEP RA++ Scenario: Get CA cert bundle without CA cert+ Given I have a SCEP cert profile with config as "scep_profile"+ """+ { "challengePassword": "testpassword123", "includeCaCertInResponse": false }+ """+ When I fetch the SCEP CA certificates for profile "scep_profile"+ Then the SCEP CA certificate bundle should contain exactly 1 certificate(s)+ And the first certificate in the SCEP bundle should have CN containing Infisical SCEP RA++ Scenario: GetCACert response has correct content type+ Given I have a SCEP cert profile with challenge password "testpassword123" as "scep_profile"+ When I send a SCEP GetCACert request for profile "scep_profile"+ Then the response status code should be "200"+ And the response content type should be "application/x-x509-ca-ra-cert"diff --git a/backend/bdd/features/pki/scep/renewal.feature b/backend/bdd/features/pki/scep/renewal.featurenew file mode 100644index 0000000000..6cd4b68887--- /dev/null+++ b/backend/bdd/features/pki/scep/renewal.feature@@ -0,0 +1,20 @@+Feature: Renewal++ Scenario: Successful cert-based renewal with previously issued certificate+ Given I have a SCEP cert profile with config as "scep_profile"+ """+ { "challengePassword": "testpassword123", "allowCertBasedRenewal": true }+ """+ And I perform a successful SCEP enrollment for CN "renew-device.example.com" with challenge "testpassword123" on profile "scep_profile"+ When I renew via SCEP for CN "renew-device.example.com" on profile "scep_profile" using the previously issued certificate+ Then the SCEP enrollment should succeed+ And the issued SCEP certificate subject CN should be "renew-device.example.com"++ Scenario: Renewal denied when cert-based renewal is disabled+ Given I have a SCEP cert profile with config as "scep_profile"+ """+ { "challengePassword": "testpassword123", "allowCertBasedRenewal": false }+ """+ And I perform a successful SCEP enrollment for CN "deny-device.example.com" with challenge "testpassword123" on profile "scep_profile"+ When I renew via SCEP for CN "deny-device.example.com" on profile "scep_profile" using the previously issued certificate+ Then the SCEP enrollment should faildiff --git a/backend/bdd/features/steps/pki_scep.py b/backend/bdd/features/steps/pki_scep.pynew file mode 100644index 0000000000..2531b95452--- /dev/null+++ b/backend/bdd/features/steps/pki_scep.py@@ -0,0 +1,464 @@+import json+import logging+import os+import subprocess+import tempfile++from behave import given+from behave import when+from behave import then+from behave.runner import Context+from cryptography import x509+from faker import Faker++from utils import replace_vars++logger = logging.getLogger(__name__)+faker = Faker()++RSA_KEY_SIZE = 2048+_enroll_counter = 0+++def _next_enroll_name() -> str:+ global _enroll_counter+ _enroll_counter += 1+ return f"enroll-{_enroll_counter}"+++class ScepProfile:+ def __init__(self, profile_id: str, challenge_password: str):+ self.id = profile_id+ self.challenge_password = challenge_password+++class SscepHelper:+ def __init__(self, base_url: str, profile_id: str, work_dir: str):+ self.scep_url = f"{base_url}/scep/{profile_id}/pkiclient.exe"+ self.work_dir = work_dir+ self.ca_cert_prefix = os.path.join(work_dir, "ca.pem")++ def _run(self, cmd: list[str], check: bool = True) -> subprocess.CompletedProcess:+ logger.debug("Running command: %s", " ".join(cmd))+ result = subprocess.run(+ cmd,+ capture_output=True,+ text=True,+ timeout=30,+ )+ logger.debug("stdout: %s", result.stdout)+ logger.debug("stderr: %s", result.stderr)+ if check and result.returncode != 0:+ raise RuntimeError(+ f"Command failed (exit {result.returncode}): {' '.join(cmd)}\n"+ f"stdout: {result.stdout}\nstderr: {result.stderr}"+ )+ return result++ def getcaps(self) -> str:+ result = self._run(["sscep", "getcaps", "-u", self.scep_url])+ return result.stdout++ def getca(self) -> list[x509.Certificate]:+ self._run([+ "sscep", "getca",+ "-u", self.scep_url,+ "-c", self.ca_cert_prefix,+ ])+ certs = []+ for i in range(10):+ cert_path = f"{self.ca_cert_prefix}-{i}"+ if not os.path.exists(cert_path):+ break+ with open(cert_path, "rb") as f:+ cert_data = f.read()+ try:+ cert = x509.load_pem_x509_certificate(cert_data)+ except Exception:+ cert = x509.load_der_x509_certificate(cert_data)+ certs.append(cert)+ return certs++ def generate_key(self, name: str = "device") -> str:+ key_path = os.path.join(self.work_dir, f"{name}.key")+ self._run([+ "openssl", "genrsa",+ "-out", key_path,+ str(RSA_KEY_SIZE),+ ])+ return key_path++ def generate_csr(+ self,+ key_path: str,+ cn: str,+ challenge_password: str | None = None,+ name: str = "device",+ ) -> str:+ csr_path = os.path.join(self.work_dir, f"{name}.csr")+ conf_path = os.path.join(self.work_dir, f"{name}-csr.cnf")++ conf_lines = [+ "[req]",+ "prompt = no",+ "distinguished_name = dn",+ ]+ if challenge_password is not None:+ conf_lines.append("attributes = req_attributes")++ conf_lines.extend([+ "",+ "[dn]",+ f"CN = {cn}",+ ])++ if challenge_password is not None:+ conf_lines.extend([+ "",+ "[req_attributes]",+ f"challengePassword = {challenge_password}",+ ])++ with open(conf_path, "w") as f:+ f.write("\n".join(conf_lines) + "\n")++ self._run([+ "openssl", "req", "-new",+ "-key", key_path,+ "-out", csr_path,+ "-config", conf_path,+ ])+ return csr_path++ def enroll(+ self,+ key_path: str,+ csr_path: str,+ name: str = "device",+ check: bool = True,+ ) -> tuple[subprocess.CompletedProcess, str]:+ cert_path = os.path.join(self.work_dir, f"{name}.crt")+ ra_cert = f"{self.ca_cert_prefix}-0"++ result = self._run(+ [+ "sscep", "enroll",+ "-u", self.scep_url,+ "-c", ra_cert,+ "-k", key_path,+ "-r", csr_path,+ "-l", cert_path,+ "-E", "aes256",+ "-S", "sha256",+ "-v",+ ],+ check=check,+ )+ return result, cert_path++ def renew(+ self,+ old_key_path: str,+ old_cert_path: str,+ new_key_path: str,+ new_csr_path: str,+ name: str = "renewed",+ check: bool = True,+ ) -> tuple[subprocess.CompletedProcess, str]:+ cert_path = os.path.join(self.work_dir, f"{name}.crt")+ ra_cert = f"{self.ca_cert_prefix}-0"++ result = self._run(+ [+ "sscep", "enroll",+ "-u", self.scep_url,+ "-c", ra_cert,+ "-K", old_key_path,+ "-O", old_cert_path,+ "-k", new_key_path,+ "-r", new_csr_path,+ "-l", cert_path,+ "-E", "aes256",+ "-S", "sha256",+ "-v",+ ],+ check=check,+ )+ return result, cert_path+++def _create_scep_profile(+ context: Context,+ challenge_password: str,+ include_ca_cert: bool = True,+ allow_renewal: bool = True,+) -> ScepProfile:+ jwt_token = context.vars["AUTH_TOKEN"]+ profile_slug = faker.slug()++ response = context.http_client.post(+ "/api/v1/cert-manager/certificate-profiles",+ headers={"authorization": f"Bearer {jwt_token}"},+ json={+ "projectId": context.vars["PROJECT_ID"],+ "slug": profile_slug,+ "description": "SCEP Profile created by BDD test",+ "enrollmentType": "scep",+ "caId": context.vars["CERT_CA_ID"],+ "certificatePolicyId": context.vars["CERT_POLICY_ID"],+ "scepConfig": {+ "challengePassword": challenge_password,+ "includeCaCertInResponse": include_ca_cert,+ "allowCertBasedRenewal": allow_renewal,+ },+ },+ )+ response.raise_for_status()+ resp_json = response.json()+ profile_id = resp_json["certificateProfile"]["id"]++ return ScepProfile(profile_id, challenge_password)+++def _get_sscep_helper(context: Context, profile_var: str) -> SscepHelper:+ profile: ScepProfile = context.vars[profile_var]+ helper_key = f"_sscep_{profile_var}"++ if helper_key not in context.vars:+ work_dir = tempfile.mkdtemp(prefix="scep_bdd_")+ context.vars[helper_key] = SscepHelper(+ base_url=context.vars["BASE_URL"],+ profile_id=profile.id,+ work_dir=work_dir,+ )+ if not hasattr(context, "_scep_work_dirs"):+ context._scep_work_dirs = []+ context._scep_work_dirs.append(work_dir)++ return context.vars[helper_key]+++@given('I have a SCEP cert profile with challenge password "{password}" as "{profile_var}"')+def step_impl(context: Context, password: str, profile_var: str):+ context.vars[profile_var] = _create_scep_profile(context, challenge_password=password)+++@given('I have a SCEP cert profile with config as "{profile_var}"')+def step_impl(context: Context, profile_var: str):+ config = json.loads(context.text)+ context.vars[profile_var] = _create_scep_profile(+ context,+ challenge_password=config["challengePassword"],+ include_ca_cert=config.get("includeCaCertInResponse", True),+ allow_renewal=config.get("allowCertBasedRenewal", True),+ )+++@when('I send a SCEP GetCACaps request for profile "{profile_var}"')+def step_impl(context: Context, profile_var: str):+ profile: ScepProfile = context.vars[profile_var]+ url = f"/scep/{profile.id}/pkiclient.exe?operation=GetCACaps"+ response = context.http_client.get(url)+ context.vars["response"] = response+ context.vars["scep_caps_response"] = response.text+++@when('I send a SCEP GetCACert request for profile "{profile_var}"')+def step_impl(context: Context, profile_var: str):+ profile: ScepProfile = context.vars[profile_var]+ url = f"/scep/{profile.id}/pkiclient.exe?operation=GetCACert"+ response = context.http_client.get(url)+ context.vars["response"] = response+ context.vars["scep_getcacert_response"] = response+++@when('I send a SCEP request with unsupported operation "{operation}" for profile "{profile_var}"')+def step_impl(context: Context, operation: str, profile_var: str):+ profile: ScepProfile = context.vars[profile_var]+ url = f"/scep/{profile.id}/pkiclient.exe?operation={operation}"+ response = context.http_client.get(url)+ context.vars["response"] = response+++@when('I fetch the SCEP CA certificates for profile "{profile_var}"')+def step_impl(context: Context, profile_var: str):+ helper = _get_sscep_helper(context, profile_var)+ context.vars["scep_ca_certs"] = helper.getca()+++@when('I enroll via SCEP for CN "{cn}" with challenge "{password}" on profile "{profile_var}"')+def step_impl(context: Context, cn: str, password: str, profile_var: str):+ helper = _get_sscep_helper(context, profile_var)++ if not os.path.exists(f"{helper.ca_cert_prefix}-0"):+ context.vars["scep_ca_certs"] = helper.getca()++ name = _next_enroll_name()+ key_path = helper.generate_key(name)+ csr_path = helper.generate_csr(key_path, cn, challenge_password=password, name=name)+ result, cert_path = helper.enroll(key_path, csr_path, name=name, check=False)++ context.vars["scep_enroll_result"] = result+ context.vars["scep_enroll_cert_path"] = cert_path+ context.vars["scep_enroll_key_path"] = key_path+ context.vars["scep_enroll_exit_code"] = result.returncode+ context.vars["scep_enroll_stdout"] = result.stdout+ context.vars["scep_enroll_stderr"] = result.stderr+++@when('I enroll via SCEP for CN "{cn}" without challenge password on profile "{profile_var}"')+def step_impl(context: Context, cn: str, profile_var: str):+ helper = _get_sscep_helper(context, profile_var)++ if not os.path.exists(f"{helper.ca_cert_prefix}-0"):+ context.vars["scep_ca_certs"] = helper.getca()++ name = _next_enroll_name()+ key_path = helper.generate_key(name)+ csr_path = helper.generate_csr(key_path, cn, challenge_password=None, name=name)+ result, cert_path = helper.enroll(key_path, csr_path, name=name, check=False)++ context.vars["scep_enroll_result"] = result+ context.vars["scep_enroll_cert_path"] = cert_path+ context.vars["scep_enroll_key_path"] = key_path+ context.vars["scep_enroll_exit_code"] = result.returncode+ context.vars["scep_enroll_stdout"] = result.stdout+ context.vars["scep_enroll_stderr"] = result.stderr+++@when('I renew via SCEP for CN "{cn}" on profile "{profile_var}" using the previously issued certificate')+def step_impl(context: Context, cn: str, profile_var: str):+ helper = _get_sscep_helper(context, profile_var)++ old_key_path = context.vars["scep_initial_key_path"]+ old_cert_path = context.vars["scep_initial_cert_path"]++ new_key_path = helper.generate_key("renew")+ new_csr_path = helper.generate_csr(new_key_path, cn, challenge_password=None, name="renew")++ result, cert_path = helper.renew(+ old_key_path=old_key_path,+ old_cert_path=old_cert_path,+ new_key_path=new_key_path,+ new_csr_path=new_csr_path,+ name="renewed",+ check=False,+ )++ context.vars["scep_enroll_result"] = result+ context.vars["scep_enroll_cert_path"] = cert_path+ context.vars["scep_enroll_key_path"] = new_key_path+ context.vars["scep_enroll_exit_code"] = result.returncode+ context.vars["scep_enroll_stdout"] = result.stdout+ context.vars["scep_enroll_stderr"] = result.stderr+++@given('I perform a successful SCEP enrollment for CN "{cn}" with challenge "{password}" on profile "{profile_var}"')+def step_impl(context: Context, cn: str, password: str, profile_var: str):+ helper = _get_sscep_helper(context, profile_var)++ if not os.path.exists(f"{helper.ca_cert_prefix}-0"):+ context.vars["scep_ca_certs"] = helper.getca()++ key_path = helper.generate_key("initial")+ csr_path = helper.generate_csr(key_path, cn, challenge_password=password, name="initial")+ result, cert_path = helper.enroll(key_path, csr_path, name="initial", check=True)++ assert os.path.exists(cert_path), f"Enrollment cert not created at {cert_path}"++ context.vars["scep_initial_cert_path"] = cert_path+ context.vars["scep_initial_key_path"] = key_path+++@then("the SCEP enrollment should succeed")+def step_impl(context: Context):+ exit_code = context.vars["scep_enroll_exit_code"]+ cert_path = context.vars["scep_enroll_cert_path"]+ assert exit_code == 0, (+ f"sscep enroll failed (exit {exit_code})\n"+ f"stdout: {context.vars['scep_enroll_stdout']}\n"+ f"stderr: {context.vars['scep_enroll_stderr']}"+ )+ assert os.path.exists(cert_path), f"Certificate file not created at {cert_path}"+++@then("the SCEP enrollment should fail")+def step_impl(context: Context):+ exit_code = context.vars["scep_enroll_exit_code"]+ assert exit_code != 0, (+ f"sscep enroll unexpectedly succeeded (exit 0)\n"+ f"stdout: {context.vars['scep_enroll_stdout']}"+ )+++@then('the issued SCEP certificate subject CN should be "{expected_cn}"')+def step_impl(context: Context, expected_cn: str):+ cert_path = context.vars["scep_enroll_cert_path"]+ assert os.path.exists(cert_path), f"No certificate file at {cert_path}"++ with open(cert_path, "rb") as f:+ cert_data = f.read()++ try:+ cert = x509.load_pem_x509_certificate(cert_data)+ except Exception:+ cert = x509.load_der_x509_certificate(cert_data)++ cn_attrs = cert.subject.get_attributes_for_oid(x509.oid.NameOID.COMMON_NAME)+ assert len(cn_attrs) > 0, "Issued certificate has no CN"+ actual_cn = cn_attrs[0].value+ assert actual_cn == expected_cn, f"Expected CN '{expected_cn}', got '{actual_cn}'"++ context.vars["scep_issued_cert"] = cert+++@then("the issued SCEP certificate should be signed by the CA")+def step_impl(context: Context):+ cert = context.vars.get("scep_issued_cert")+ assert cert is not None, "No issued certificate to check"+ ca_certs = context.vars.get("scep_ca_certs", [])+ assert len(ca_certs) >= 2, f"Expected at least 2 certs in CA bundle (RA + CA), got {len(ca_certs)}"+ ca_cert = ca_certs[1]+ assert cert.issuer == ca_cert.subject, (+ f"Certificate issuer {cert.issuer} does not match CA subject {ca_cert.subject}"+ )+++@then("the SCEP CA certificate bundle should contain at least {count:d} certificate(s)")+def step_impl(context: Context, count: int):+ certs = context.vars["scep_ca_certs"]+ assert len(certs) >= count, f"Expected at least {count} certs, got {len(certs)}"+++@then("the SCEP CA certificate bundle should contain exactly {count:d} certificate(s)")+def step_impl(context: Context, count: int):+ certs = context.vars["scep_ca_certs"]+ assert len(certs) == count, f"Expected exactly {count} certs, got {len(certs)}"+++@then("the first certificate in the SCEP bundle should have CN containing {expected_cn}")+def step_impl(context: Context, expected_cn: str):+ certs = context.vars["scep_ca_certs"]+ assert len(certs) > 0, "No certificates in bundle"+ cn = certs[0].subject.get_attributes_for_oid(x509.oid.NameOID.COMMON_NAME)+ assert len(cn) > 0, "First certificate has no CN"+ expected = replace_vars(expected_cn, context.vars)+ assert expected in cn[0].value, f"Expected CN containing '{expected}', got '{cn[0].value}'"+++@then('the SCEP GetCACaps response should contain "{capability}"')+def step_impl(context: Context, capability: str):+ text = context.vars["scep_caps_response"]+ assert capability in text, f"Capability '{capability}' not found in response: {text}"+++@then('the SCEP GetCACaps response should not contain "{capability}"')+def step_impl(context: Context, capability: str):+ text = context.vars["scep_caps_response"]+ assert capability not in text, f"Capability '{capability}' unexpectedly found in: {text}"+++@then('the response content type should be "{expected_ct}"')+def step_impl(context: Context, expected_ct: str):+ actual = context.vars["response"].headers.get("content-type", "")+ assert expected_ct in actual, f"Expected content type '{expected_ct}', got '{actual}'"diff --git a/backend/bdd/pyproject.toml b/backend/bdd/pyproject.tomlindex 4f19cb0de9..bc56fed1d9 100644--- a/backend/bdd/pyproject.toml+++ b/backend/bdd/pyproject.toml@@ -7,6 +7,7 @@ requires-python = ">=3.12"dependencies = ["acme>=5.1.0","behave>=1.3.3",+ "cryptography>=44.0.0","dotenv>=0.9.9","faker>=37.12.0","glom>=24.11.0",diff --git a/backend/bdd/uv.lock b/backend/bdd/uv.lockindex 8ae5b6c016..49e1fca735 100644--- a/backend/bdd/uv.lock+++ b/backend/bdd/uv.lock@@ -1,5 +1,5 @@version = 1-revision = 2+revision = 3requires-python = ">=3.12"[[package]]@@ -48,6 +48,7 @@ source = { virtual = "." }dependencies = [{ name = "acme" },{ name = "behave" },+ { name = "cryptography" },{ name = "dotenv" },{ name = "faker" },{ name = "glom" },@@ -60,6 +61,7 @@ dependencies = [requires-dist = [{ name = "acme", specifier = ">=5.1.0" },{ name = "behave", specifier = ">=1.3.3" },+ { name = "cryptography", specifier = ">=44.0.0" },{ name = "dotenv", specifier = ">=0.9.9" },{ name = "faker", specifier = ">=37.12.0" },{ name = "glom", specifier = ">=24.11.0" },