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)
|
:test-selectors {:default (complement :performance)
|
||||||
:focus :focus
|
:focus :focus
|
||||||
:indexing :indexing
|
:indexing :indexing
|
||||||
|
:external :external
|
||||||
:performance :performance
|
:performance :performance
|
||||||
:all (constantly true)}
|
:all (constantly true)}
|
||||||
:codox {:exclude [monger.internal.pagination]}
|
:codox {:exclude [monger.internal.pagination]}
|
||||||
|
|
|
||||||
|
|
@ -189,11 +189,12 @@
|
||||||
;;
|
;;
|
||||||
;; First we set connection, then DB, then authentcate
|
;; First we set connection, then DB, then authentcate
|
||||||
(set-connection! conn)
|
(set-connection! conn)
|
||||||
(when db
|
|
||||||
(set-db! db))
|
|
||||||
(when (and user pwd)
|
(when (and user pwd)
|
||||||
(when-not (authenticate (.getName db) user pwd)
|
(when-not (authenticate (.getName db) user pwd)
|
||||||
(throw (IllegalArgumentException. "Could not authenticate. Either database name or credentials are invalid."))))
|
(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))
|
conn))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,14 @@
|
||||||
;; reconnect using regular host
|
;; reconnect using regular host
|
||||||
(helper/connect!))
|
(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
|
(deftest connect-to-mongo-via-uri-with-invalid-credentials
|
||||||
(is (thrown? IllegalArgumentException
|
(is (thrown? IllegalArgumentException
|
||||||
(monger.core/connect-via-uri! "mongodb://clojurewerkz/monger!:ahsidaysd78jahsdi8@127.0.0.1/monger-test4"))))
|
(monger.core/connect-via-uri! "mongodb://clojurewerkz/monger!:ahsidaysd78jahsdi8@127.0.0.1/monger-test4"))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue