Skip to content
Snippets Groups Projects
Commit 223c7188 authored by William Turner's avatar William Turner
Browse files

Removes unused LDAP test utils

parent 7d95a088
No related branches found
No related tags found
No related merge requests found
...@@ -3,27 +3,23 @@ ...@@ -3,27 +3,23 @@
[expectations :refer [expect]] [expectations :refer [expect]]
[metabase.test.util :as tu]) [metabase.test.util :as tu])
(:import (com.unboundid.ldap.listener InMemoryDirectoryServer InMemoryDirectoryServerConfig InMemoryListenerConfig)) (:import (com.unboundid.ldap.listener InMemoryDirectoryServer InMemoryDirectoryServerConfig InMemoryListenerConfig))
(:import (com.unboundid.ldap.sdk.schema Schema)) (:import com.unboundid.ldap.sdk.schema.Schema)
(:import (com.unboundid.ldif LDIFReader))) (:import com.unboundid.ldif.LDIFReader))
(def ^:dynamic *ldap-server* (def ^:dynamic *ldap-server*
"An in-memory testing LDAP server." "An in-memory LDAP testing server."
nil)
(def ^:dynamic *ldap-connection*
"A connection to the in-memory LDAP server in `*ldap-server*`."
nil) nil)
(defn- get-server-config [] (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") (.addAdditionalBindCredentials "cn=Directory Manager" "password")
(.setSchema (Schema/getDefaultStandardSchema)) (.setSchema (Schema/getDefaultStandardSchema))
(.setListenerConfigs (into-array InMemoryListenerConfig [(InMemoryListenerConfig/createLDAPConfig "LDAP" 0)])))) (.setListenerConfigs (into-array InMemoryListenerConfig [(InMemoryListenerConfig/createLDAPConfig "LDAP" 0)]))))
(defn- start-ldap-server! [] (defn- start-ldap-server! []
(with-open [ldif (new LDIFReader (io/file (io/resource "ldap.ldif")))] (with-open [ldif (LDIFReader. (io/file (io/resource "ldap.ldif")))]
(doto (new InMemoryDirectoryServer (get-server-config)) (doto (InMemoryDirectoryServer. (get-server-config))
(.importFromLDIF true ldif) (.importFromLDIF true ldif)
(.startListening)))) (.startListening))))
...@@ -57,22 +53,3 @@ ...@@ -57,22 +53,3 @@
"Generate a unit test that runs ACTUAL with a bound `*ldap-server*` and relevant settings." "Generate a unit test that runs ACTUAL with a bound `*ldap-server*` and relevant settings."
[expected actual] [expected actual]
`(expect ~expected (with-ldap-server ~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)))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment