Skip to content

Instantly share code, notes, and snippets.

@boxxxie
Created December 23, 2012 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boxxxie/4364133 to your computer and use it in GitHub Desktop.
Save boxxxie/4364133 to your computer and use it in GitHub Desktop.
;;this fn doesn't work. couchdb is still being called even though with-redef is replacing the authenticator.
(with-redefs [
api.routes.login/conn (db.datomic.seeding/connection-to-seeded-db)
api.db.couch/authenticator (constantly {:basic-authentication {:ok true :name nil :roles ["_admin"] } :couchdb-id "sharedadmin"})
]
;;use mem DB for this
(deftest login-route
(testing "testing logging in as sharedadmin"
(is (= (-> (session api.core/app) ;Use your ring app
(request ,,, "/login" :request-method :post
:headers { :authorization (str "Basic " (encode-str "sharedadmin:ujJWj5jM"))}))
{:username "sharedadmin" :admin true :firstname "En" :lastname "Ginuity"})))))
;;this works.
;;api.routes.login/couch-auth-proxy called api.db.couch/authenticator through another fn (testing if i could redef more than 1 level deep)
(with-redefs [
api.db.couch/authenticator
(fn [username pass]
;(if (= username "sharedadmin")
{:basic-authentication {:ok true :name nil :roles ["_admin"] } :couchdb-id "sharedadmin"}
; nil)
)]
(println (api.routes.login/couch-auth-proxy)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment