diff --git a/test/metabase/test/integrations/ldap.clj b/test/metabase/test/integrations/ldap.clj index 205700dee7c83e64ff87e309d2834f6167aff508..b698d2be2034218ecaede949eaf17271d9a6bedc 100644 --- a/test/metabase/test/integrations/ldap.clj +++ b/test/metabase/test/integrations/ldap.clj @@ -3,27 +3,23 @@ [expectations :refer [expect]] [metabase.test.util :as tu]) (:import (com.unboundid.ldap.listener InMemoryDirectoryServer InMemoryDirectoryServerConfig InMemoryListenerConfig)) - (:import (com.unboundid.ldap.sdk.schema Schema)) - (:import (com.unboundid.ldif LDIFReader))) + (:import com.unboundid.ldap.sdk.schema.Schema) + (:import com.unboundid.ldif.LDIFReader)) (def ^:dynamic *ldap-server* - "An in-memory testing LDAP server." - nil) - -(def ^:dynamic *ldap-connection* - "A connection to the in-memory LDAP server in `*ldap-server*`." + "An in-memory LDAP testing server." nil) (defn- get-server-config [] - (doto (new InMemoryDirectoryServerConfig (into-array String ["dc=metabase,dc=com"])) + (doto (InMemoryDirectoryServerConfig. (into-array String ["dc=metabase,dc=com"])) (.addAdditionalBindCredentials "cn=Directory Manager" "password") (.setSchema (Schema/getDefaultStandardSchema)) (.setListenerConfigs (into-array InMemoryListenerConfig [(InMemoryListenerConfig/createLDAPConfig "LDAP" 0)])))) (defn- start-ldap-server! [] - (with-open [ldif (new LDIFReader (io/file (io/resource "ldap.ldif")))] - (doto (new InMemoryDirectoryServer (get-server-config)) + (with-open [ldif (LDIFReader. (io/file (io/resource "ldap.ldif")))] + (doto (InMemoryDirectoryServer. (get-server-config)) (.importFromLDIF true ldif) (.startListening)))) @@ -57,22 +53,3 @@ "Generate a unit test that runs ACTUAL with a bound `*ldap-server*` and relevant settings." [expected actual] `(expect ~expected (with-ldap-server ~actual))) - -(defn do-with-ldap-connection - "Bind `*ldap-connection*` to a connection to an in-memory LDAP testing server and executes `f`." - [f] - (with-ldap-server - (binding [*ldap-connection* (.getConnection *ldap-server*)] - (try - (f) - (finally (.close *ldap-connection*)))))) - -(defmacro with-ldap-connection - "Bind `*ldap-connection*` to a connection to an in-memory LDAP testing server and executes BODY." - [& body] - `(do-with-ldap-connection (fn [] ~@body))) - -(defmacro expect-with-ldap-connection - "Generate a unit test that runs ACTUAL with a bound `*ldap-server*` and `*ldap-connection*`." - [expected actual] - `(expect ~expected (with-ldap-connection ~actual)))