From 2ca115285ccb50971075b93ec81090a00c4882db Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 16 Dec 2021 21:14:15 +0100 Subject: [PATCH] crypto: fix private keys not being imported correctly closes #1945 Signed-off-by: Jens Langhammer --- authentik/crypto/tasks.py | 2 +- authentik/crypto/tests.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/authentik/crypto/tasks.py b/authentik/crypto/tasks.py index 723a603ee..df1f28bea 100644 --- a/authentik/crypto/tasks.py +++ b/authentik/crypto/tasks.py @@ -79,7 +79,7 @@ def certificate_discovery(self: MonitoredTask): cert.certificate_data = cert_data dirty = True if name in private_keys: - if cert.key_data == private_keys[name]: + if cert.key_data != private_keys[name]: cert.key_data = private_keys[name] dirty = True if dirty: diff --git a/authentik/crypto/tests.py b/authentik/crypto/tests.py index 112083698..d5c3388e8 100644 --- a/authentik/crypto/tests.py +++ b/authentik/crypto/tests.py @@ -191,9 +191,12 @@ class TestCrypto(APITestCase): with CONFIG.patch("cert_discovery_dir", temp_dir): # pyright: reportGeneralTypeIssues=false certificate_discovery() # pylint: disable=no-value-for-parameter - self.assertTrue( - CertificateKeyPair.objects.filter(managed=MANAGED_DISCOVERED % "foo").exists() - ) + keypair: CertificateKeyPair = CertificateKeyPair.objects.filter( + managed=MANAGED_DISCOVERED % "foo" + ).first() + self.assertIsNotNone(keypair) + self.assertIsNotNone(keypair.certificate) + self.assertIsNotNone(keypair.private_key) self.assertTrue( CertificateKeyPair.objects.filter(managed=MANAGED_DISCOVERED % "foo.bar").exists() )