Make sure we authenticate before calling set-db! (which instantiates a GridFS object)
Fixes Heroku/MongoHQ add-on issues
This commit is contained in:
parent
9a058ea45c
commit
19b8e48084
3 changed files with 12 additions and 2 deletions
|
|
@ -8,6 +8,7 @@
|
|||
:test-selectors {:default (complement :performance)
|
||||
:focus :focus
|
||||
:indexing :indexing
|
||||
:external :external
|
||||
:performance :performance
|
||||
:all (constantly true)}
|
||||
:codox {:exclude [monger.internal.pagination]}
|
||||
|
|
|
|||
|
|
@ -189,11 +189,12 @@
|
|||
;;
|
||||
;; First we set connection, then DB, then authentcate
|
||||
(set-connection! conn)
|
||||
(when db
|
||||
(set-db! db))
|
||||
(when (and user pwd)
|
||||
(when-not (authenticate (.getName db) user pwd)
|
||||
(throw (IllegalArgumentException. "Could not authenticate. Either database name or credentials are invalid."))))
|
||||
;; only do this *after* we authenticated because set-db! will try to set up a default GridFS instance. MK.
|
||||
(when db
|
||||
(set-db! db))
|
||||
conn))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,14 @@
|
|||
;; reconnect using regular host
|
||||
(helper/connect!))
|
||||
|
||||
(if-let [uri (System/getenv "MONGOHQ_URL")]
|
||||
(deftest ^{:external true} connect-to-mongo-via-uri-with-valid-credentials
|
||||
(let [connection (monger.core/connect-via-uri! uri)]
|
||||
(is (= (-> connection .getAddress (.sameHost "127.0.0.1")))))
|
||||
;; reconnect using regular host
|
||||
(helper/connect!)))
|
||||
|
||||
|
||||
(deftest connect-to-mongo-via-uri-with-invalid-credentials
|
||||
(is (thrown? IllegalArgumentException
|
||||
(monger.core/connect-via-uri! "mongodb://clojurewerkz/monger!:ahsidaysd78jahsdi8@127.0.0.1/monger-test4"))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue