Skip to content

Commit

Permalink
Added some generic crypto tests back in
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Jun 26, 2009
1 parent 76256ae commit 5cf8f81
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions test/compojure/crypto.clj
Expand Up @@ -2,9 +2,34 @@
(:use compojure.crypto)
(:use clojure.contrib.test-is))

(deftest secret-key-length
(are (= (count (gen-secret-key {:key-size _1})) _2)
256 32
128 16))

(deftest secret-key-uniqueness
(let [a (gen-secret-key {:key-size 128})
b (gen-secret-key {:key-size 128})]
(is (not= a b))))

(def secret-key
(.getBytes "0123456789ABCDEF"))

(deftest test-seal-unseal
(is (= (unseal secret-key (seal secret-key "Foobar"))
"Foobar")))
(deftest seal-string
(is (not= (seal secret-key "Foobar") "Foobar")))

(deftest seal-uniqueness
(let [a (seal secret-key "Foobar")
b (seal secret-key "Foobar")]
(is (not= a b))))

(deftest seal-then-unseal
(are (= (unseal secret-key (seal secret-key _1)) _1)
"Foobar"
[1 2 3]
{:a 10}))

(deftest seal-then-tamper
(let [data (seal secret-key "Foobar")
data (apply str "A" (rest data))]
(is (nil? (unseal secret-key "Foobar")))))

0 comments on commit 5cf8f81

Please sign in to comment.