Introduce 2-arity monger.core/authenticate that authenticates on the default DB

This commit is contained in:
Michael Klishin 2013-02-28 16:45:34 +04:00
parent d647542d86
commit 62013fd070
3 changed files with 23 additions and 2 deletions

View file

@ -1,5 +1,18 @@
## Changes between 1.4.0 and 1.5.0
### Authentication On Default Database
`monger.core/authenticate` now has a 2-arity version that will authenticate
on the default database:
``` clojure
(let [username "myservice"
pwd "LGo5h#B`cTRQ>28tba6u"]
(monger.core/set-db! "mydb")
;; authenticates requests for mydb
(monger.core/authenticate username (.toCharArray pwd)))
```
### ClojureWerkz Support Upgrade
ClojureWerkz Support dependency has been updated to version `0.14.0`.

View file

@ -203,6 +203,8 @@
(defn authenticate
([^String username ^chars password]
(authenticate *mongodb-connection* *mongodb-database* username password))
([^DB db ^String username ^chars password]
(authenticate *mongodb-connection* db username password))
([^MongoClient connection ^DB db ^String username ^chars password]

View file

@ -15,7 +15,7 @@
(helper/connect!))
(deftest ^{:authentication true} connect-to-mongo-via-uri-with-valid-credentials
(let [connection (monger.core/connect-via-uri! "mongodb://clojurewerkz/monger!:monger!@127.0.0.1/monger-test4")]
(let [connection (monger.core/connect-via-uri! "mongodb://clojurewerkz/monger:monger@127.0.0.1/monger-test4")]
(is (= "monger-test4" (.getName (monger.core/current-db))))
(is (= (-> connection .getAddress ^InetAddress (.sameHost "127.0.0.1"))))
(mc/remove "documents")
@ -34,7 +34,13 @@
(helper/connect!)))
(deftest ^{:authentication true} test-authentication-with-valid-credentials
(deftest ^{:authentication true} test-authentication-with-valid-credentials-on-the-default-db
;; see ./bin/ci/before_script.sh. MK.
(let [username "clojurewerkz/monger"
pwd "monger"]
(is (monger.core/authenticate username (.toCharArray pwd)))))
(deftest ^{:authentication true} test-authentication-with-valid-credentials-on-an-arbitrary-db
;; see ./bin/ci/before_script.sh. MK.
(let [username "clojurewerkz/monger"
pwd "monger"]