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:
		@ -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
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user