#5 bug fix for claims containing string key

This commit is contained in:
liquidz 2014-06-18 22:24:16 +09:00
parent fc1ae52a92
commit c611871156
3 changed files with 13 additions and 4 deletions

View file

@ -1,4 +1,4 @@
(defproject clj-jwt "0.0.6" (defproject clj-jwt "0.0.7"
:description "Clojure library for JSON Web Token(JWT)" :description "Clojure library for JSON Web Token(JWT)"
:url "https://github.com/liquidz/clj-jwt" :url "https://github.com/liquidz/clj-jwt"
:license {:name "Eclipse Public License" :license {:name "Eclipse Public License"

View file

@ -7,8 +7,11 @@
[clojure.string :as str])) [clojure.string :as str]))
(def ^:private DEFAULT_SIGNATURE_ALGORITHM :HS256) (def ^:private DEFAULT_SIGNATURE_ALGORITHM :HS256)
(def ^:private map->encoded-json (comp url-safe-encode-str json/write-str)) (def ^:private full-key-name #(subs (str %) 1))
(def ^:private encoded-json->map (comp #(json/read-str % :key-fn keyword) url-safe-decode-str)) (def ^:private map->encoded-json (comp url-safe-encode-str
#(json/write-str % :key-fn full-key-name)))
(def ^:private encoded-json->map (comp #(json/read-str % :key-fn keyword)
url-safe-decode-str))
(defn- update-map [m k f] (if (contains? m k) (update-in m [k] f) m)) (defn- update-map [m k f] (if (contains? m k) (update-in m [k] f) m))
(defrecord JWT [header claims signature]) (defrecord JWT [header claims signature])

View file

@ -147,7 +147,13 @@
(fact "ES512 signed JWT shoud be verified." (fact "ES512 signed JWT shoud be verified."
(-> claim jwt (sign :ES512 ec-prv-key) (verify ec-pub-key)) => true (-> claim jwt (sign :ES512 ec-prv-key) (verify ec-pub-key)) => true
(-> claim jwt (sign :ES512 ec-prv-key) to-str str->jwt (verify ec-pub-key)) => true)) (-> claim jwt (sign :ES512 ec-prv-key) to-str str->jwt (verify ec-pub-key)) => true)
(fact "Claims containing string key should be verified"
(let [sclaim {"a/b" "c"}]
(-> sclaim jwt (sign "foo") (verify "foo")) => true
(-> sclaim jwt (sign "foo") to-str str->jwt (verify "foo")) => true
(-> sclaim jwt (sign "foo") (verify "bar")) => false)))
(facts "str->jwt function should work." (facts "str->jwt function should work."