tests fixed

This commit is contained in:
Christian Mueller
2014-01-07 23:02:09 +01:00
parent 5e6e7fb5c7
commit bf7cebf044
4 changed files with 66 additions and 36 deletions
+10 -9
View File
@@ -55,12 +55,11 @@
([note pid signature] (post-note note pid signature nil))
([note pid signature password]
(let [errors (filter identity
(lazy-seq
[(when-not (storage/valid-publisher? pid) "pid invalid")
(when-not (= signature
(get-signature pid (storage/get-psk pid) note))
"signature invalid")
(when (blank? note) "note is empty")]))]
(when (blank? note) "note is empty")])]
(if (empty? errors)
(let [[year month day] (get-date)
untrimmed-line (filter #(or (= \- %) (Character/isLetterOrDigit %))
@@ -88,17 +87,19 @@
(defn update-note [noteID note pid signature password]
(let [errors (filter identity
(lazy-seq
(seq
[(when-not (storage/valid-publisher? pid) "pid invalid")
(when-not (= signature
(get-signature pid (storage/get-psk pid) noteID note password))
"signature invalid")
(when (blank? note) "note is empty")
(when-not (storage/update-note noteID note password) "password invalid")]))]
(when-not (storage/valid-password? noteID password) "password invalid")]))]
(if (empty? errors)
{
:longURL (getURL noteID)
:shortURL (getURL noteID :short)
:status (create-response true)
}
(do
(storage/edit-note noteID note)
{
:longURL (getURL noteID)
:shortURL (getURL noteID :short)
:status (create-response true)
})
{:status (create-response false (first errors))})))
+11
View File
@@ -54,6 +54,7 @@
(do (redis/srem db sessions token)
was-valid))))
; TODO: deprecated
(defn update-note
[noteID text passwd]
(let [stored-password (redis/hget db password noteID)]
@@ -61,6 +62,12 @@
(redis/hset db edited noteID (get-current-date))
(redis/hset db note noteID text))))
(defn edit-note
[noteID text]
(do
(redis/hset db edited noteID (get-current-date))
(redis/hset db note noteID text)))
(defn add-note
([noteID text] (add-note noteID text nil))
([noteID text passwd]
@@ -70,6 +77,10 @@
(when (not (blank? passwd))
(redis/hset db password noteID passwd)))))
(defn valid-password? [noteID passwd]
(let [stored (redis/hget db password noteID)]
(and stored (= stored passwd))))
(defn get-note
[noteID]
(let [text (redis/hget db note noteID)]