sources/ldap: clean-up certs written from db (#7617)

* sources/ldap: clean-up certs written from db

* fix test when certificate is none
This commit is contained in:
ChandonPierre 2023-11-20 09:29:18 -05:00 committed by GitHub
parent 6b78e6e283
commit c0b7d32b36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,7 @@
"""authentik LDAP Models"""
from os import chmod
from os.path import dirname, exists
from shutil import rmtree
from ssl import CERT_REQUIRED
from tempfile import NamedTemporaryFile, mkdtemp
from typing import Optional
@ -189,6 +191,11 @@ class LDAPSource(Source):
raise exc
server_kwargs["get_info"] = NONE
return self.connection(server, server_kwargs, connection_kwargs)
finally:
if connection.server.tls.certificate_file is not None and exists(
connection.server.tls.certificate_file
):
rmtree(dirname(connection.server.tls.certificate_file))
return RuntimeError("Failed to bind")
@property