Skip to content

Commit

Permalink
Fix changed authentication behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
neotyk committed Apr 7, 2011
1 parent d17987c commit a409899
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
9 changes: 7 additions & 2 deletions src/clj/http/async/client/util.clj
Expand Up @@ -121,11 +121,17 @@
(ProxyServer. (proto-map protocol) host port user password)
(ProxyServer. (proto-map protocol) host port))))

(defn- type->auth-scheme [type]
(or ({:basic Realm$AuthScheme/BASIC
:digest Realm$AuthScheme/DIGEST} type)
Realm$AuthScheme/BASIC))

(defn set-realm
"Sets realm on builder."
[{:keys [type user password realm preemptive]
:or {:type :basic}} b]
(let [rbld (Realm$RealmBuilder.)]
(.setScheme rbld (type->auth-scheme type))
(when (nil? user)
(if (nil? password)
(throw (IllegalArgumentException. "For authentication user and password is required"))
Expand All @@ -135,8 +141,7 @@
(when (= :digest type)
(when (nil? realm) (throw (IllegalArgumentException.
"For DIGEST authentication realm is required")))
(.setRealmName rbld realm)
(.setScheme rbld Realm$AuthScheme/DIGEST))
(.setRealmName rbld realm))
(when (not (nil? preemptive))
(.setUsePreemptiveAuth rbld preemptive))
(doto rbld
Expand Down
24 changes: 12 additions & 12 deletions test/http/async/client/test.clj
Expand Up @@ -483,18 +483,18 @@
200)))

;; breaks with AsyncHttpClient 1.6.3
;; (deftest preemptive-authentication
;; (is (=
;; (:code (status (GET "http://localhost:8123/preemptive-auth"
;; :auth {:user "beastie"
;; :password "boys"})))
;; 401))
;; (is (=
;; (:code (status (GET "http://localhost:8123/preemptive-auth"
;; :auth {:user "beastie"
;; :password "boys"
;; :preemptive true})))
;; 200)))
(deftest preemptive-authentication
(is (=
(:code (status (GET "http://localhost:8123/preemptive-auth"
:auth {:user "beastie"
:password "boys"})))
401))
(is (=
(:code (status (GET "http://localhost:8123/preemptive-auth"
:auth {:user "beastie"
:password "boys"
:preemptive true})))
200)))

(deftest canceling-request
(let [resp (GET "http://localhost:8123/")]
Expand Down

0 comments on commit a409899

Please sign in to comment.