Introduce monger.core/authenticate
This commit is contained in:
parent
d0c7b601b4
commit
d2408faea6
5 changed files with 39 additions and 2 deletions
|
|
@ -1 +1,2 @@
|
|||
language: clojure
|
||||
language: clojure
|
||||
before_script: ./bin/ci/before_script.sh
|
||||
|
|
|
|||
8
bin/ci/before_script.sh
Executable file
8
bin/ci/before_script.sh
Executable file
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/sh
|
||||
|
||||
# MongoDB Java driver won't run authentication twice on the same DB instance,
|
||||
# so we need to use multiple DBs.
|
||||
mongo --eval 'db.addUser("clojurewerkz/monger", "monger")' monger-test
|
||||
mongo --eval 'db.addUser("clojurewerkz/monger", "monger")' monger-test2
|
||||
mongo --eval 'db.addUser("clojurewerkz/monger", "monger")' monger-test3
|
||||
mongo --eval 'db.addUser("clojurewerkz/monger", "monger")' monger-test4
|
||||
|
|
@ -66,6 +66,14 @@
|
|||
(.getDB connection name)))
|
||||
|
||||
|
||||
(defn authenticate
|
||||
([^String db ^String username ^chars password]
|
||||
(authenticate *mongodb-connection* db username password))
|
||||
([^Mongo connection ^String db ^String username ^chars password]
|
||||
(.authenticate (.getDB connection db) username password)))
|
||||
|
||||
|
||||
|
||||
(defmacro with-connection
|
||||
[conn & body]
|
||||
`(binding [*mongodb-connection* ~conn]
|
||||
|
|
|
|||
19
test/monger/test/authentication.clj
Normal file
19
test/monger/test/authentication.clj
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
(ns monger.test.authentication
|
||||
(:require [monger core util]
|
||||
[monger.test.helper :as helper])
|
||||
(:use [clojure.test]))
|
||||
|
||||
(helper/connect!)
|
||||
|
||||
|
||||
|
||||
(deftest test-authentication-with-valid-credentials
|
||||
;; see ./bin/ci/before_script.sh. MK.
|
||||
(let [username "clojurewerkz/monger"
|
||||
pwd "monger"]
|
||||
(is (monger.core/authenticate "monger-test" username (.toCharArray pwd)))))
|
||||
|
||||
(deftest test-authentication-with-invalid-credentials
|
||||
(let [username "monger"
|
||||
^String pwd (monger.util/random-str 128 32)]
|
||||
(is (not (monger.core/authenticate "monger-test2" username (.toCharArray pwd))))))
|
||||
|
|
@ -13,4 +13,5 @@
|
|||
(do
|
||||
(monger.core/connect!)
|
||||
(monger.core/set-db! (monger.core/get-db "monger-test"))
|
||||
(monger.core/set-default-write-concern! WriteConcern/SAFE))))
|
||||
(monger.core/set-default-write-concern! WriteConcern/SAFE)
|
||||
(reset! connected true))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue