From 62013fd070bdde7b2fb262d89a90b03f53b0e71a Mon Sep 17 00:00:00 2001 From: Michael Klishin Date: Thu, 28 Feb 2013 16:45:34 +0400 Subject: [PATCH] Introduce 2-arity monger.core/authenticate that authenticates on the default DB --- ChangeLog.md | 13 +++++++++++++ src/clojure/monger/core.clj | 2 ++ test/monger/test/authentication_test.clj | 10 ++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 4040757..d826a44 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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`. diff --git a/src/clojure/monger/core.clj b/src/clojure/monger/core.clj index 9d4a3a3..fa5f8f6 100644 --- a/src/clojure/monger/core.clj +++ b/src/clojure/monger/core.clj @@ -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] diff --git a/test/monger/test/authentication_test.clj b/test/monger/test/authentication_test.clj index 3cd34ac..c10b6ff 100644 --- a/test/monger/test/authentication_test.clj +++ b/test/monger/test/authentication_test.clj @@ -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"]