Skip to content

Commit

Permalink
tests.testlib.licensing: Fix ca-certificate() logic
Browse files Browse the repository at this point in the history
Change-Id: I3a7b0d0833937e3aeca24eb8681d9d9b2b9a77e7
  • Loading branch information
rene-slowenski-checkmk committed Oct 17, 2024
1 parent 341d2ef commit 38df051
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tests/testlib/licensing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,21 @@
@contextmanager
def ca_certificate(site: Site) -> Iterator[LicensingKeyOrCert]:
"""Update CA certificate (create a backup of the original certificate)"""
ca_cert_file = site.licensing_dir / "ca-certificate.pem"
ca_cert_file = Path(site.root) / "share" / "check_mk" / "licensing" / "ca-certificate.pem"
ca_cert_backup = Path(site.root) / f"{ca_cert_file.name}.bak"
# NOTE: The certificate is owned by root!
run(["cp", ca_cert_file.as_posix(), ca_cert_backup.as_posix()], sudo=True)
restore_backup = (
run(
["cp", ca_cert_file.as_posix(), ca_cert_backup.as_posix()], check=False, sudo=True
).returncode
== 0
) and os.getenv("CLEANUP", "1") == "1"
try:
key_or_cert = licensing_key_or_cert()
write_file(ca_cert_file, key_or_cert.certificate.dump_pem().bytes, sudo=True)
yield key_or_cert
finally:
if os.getenv("CLEANUP", "1") == "1":
if restore_backup:
run(["cp", ca_cert_backup.as_posix(), ca_cert_file.as_posix()], sudo=True)


Expand Down

0 comments on commit 38df051

Please sign in to comment.