From d76127de49a7ccfbdb50fc96b0f2fb386263d8e9 Mon Sep 17 00:00:00 2001 From: Michael Klishin Date: Sat, 10 May 2014 16:36:19 -0400 Subject: [PATCH] Authentication and URI connection tests now pass --- test/monger/test/authentication_test.clj | 69 ++++++++++++------------ 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/test/monger/test/authentication_test.clj b/test/monger/test/authentication_test.clj index d6da98d..1fd999e 100644 --- a/test/monger/test/authentication_test.clj +++ b/test/monger/test/authentication_test.clj @@ -1,52 +1,53 @@ (ns monger.test.authentication-test - (:require [monger core util db] - [monger.test.helper :as helper] + (:require [monger util db] + [monger.core :as mg] [monger.collection :as mc] [clojure.test :refer :all])) -(helper/connect!) - +;; +;; Connection via URI +;; (when-not (System/getenv "CI") (deftest ^{:authentication true} connect-to-mongo-via-uri-without-credentials - (let [connection (monger.core/connect-via-uri! "mongodb://127.0.0.1/monger-test4")] - (is (= (-> connection .getAddress ^InetAddress (.sameHost "127.0.0.1"))))) - ;; reconnect using regular host - (helper/connect!)) + (let [{:keys [conn db]} (mg/connect-via-uri "mongodb://127.0.0.1/monger-test4")] + (is (= (-> conn .getAddress ^InetAddress (.sameHost "127.0.0.1")))))) (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")] - (is (= "monger-test4" (.getName (monger.core/current-db)))) - (is (= (-> connection .getAddress ^InetAddress (.sameHost "127.0.0.1")))) - (mc/remove "documents") + (let [{:keys [conn db]} (mg/connect-via-uri "mongodb://clojurewerkz/monger:monger@127.0.0.1/monger-test4")] + (is (= "monger-test4" (.getName db))) + (is (= (-> conn .getAddress ^InetAddress (.sameHost "127.0.0.1")))) + (mc/remove db "documents") ;; make sure that the database is selected ;; and operations get through. - (mc/insert "documents" {:field "value"}) - (is (= 1 (mc/count "documents" {})))) - ;; reconnect using regular host - (helper/connect!))) + (mc/insert db "documents" {:field "value"}) + (is (= 1 (mc/count db "documents" {})))))) (if-let [uri (System/getenv "MONGOHQ_URL")] (deftest ^{:external true :authentication true} connect-to-mongo-via-uri-with-valid-credentials - (let [connection (monger.core/connect-via-uri! uri)] - (is (= (-> connection .getAddress ^InetAddress (.sameHost "127.0.0.1"))))) - ;; reconnect using regular host - (helper/connect!))) + (let [{:keys [conn db]} (mg/connect-via-uri uri)] + (is (= (-> conn .getAddress ^InetAddress (.sameHost "127.0.0.1"))))))) -(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))))) +;; +;; Regular connecton +;; -(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"] - (is (monger.core/authenticate (monger.core/get-db "monger-test") username (.toCharArray pwd))))) +(let [conn (mg/connect) + db (mg/get-db conn "monger-test")] + (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 (mg/authenticate db username (.toCharArray pwd))))) -(deftest ^{:authentication true} test-authentication-with-invalid-credentials - (let [username "monger" - ^String pwd (monger.util/random-str 128 32)] - (is (not (monger.core/authenticate (monger.core/get-db "monger-test2") 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"] + (is (mg/authenticate (mg/get-db conn "monger-test") username (.toCharArray pwd))))) + + (deftest ^{:authentication true} test-authentication-with-invalid-credentials + (let [username "monger" + ^String pwd (monger.util/random-str 128 32)] + (is (not (mg/authenticate (mg/get-db conn "monger-test2") username (.toCharArray pwd)))))))