note update broken, when updating with older API verison
This commit is contained in:
+15
-5
@@ -61,9 +61,18 @@
|
||||
|
||||
(defn version-manager [f params]
|
||||
(if-let [version (:version params)]
|
||||
(f (if (and (:noteID params) (< (Double/parseDouble version) 1.3))
|
||||
(assoc params :noteID (sreplace (params :noteID) #" " "/"))
|
||||
params))
|
||||
(if (and (:noteID params) (< (Double/parseDouble version) 1.3))
|
||||
(let [resp (f (assoc params
|
||||
:noteID (sreplace (params :noteID) #" " "/")
|
||||
:noteID* (params :noteID)))
|
||||
server-message (get-in resp [:status :message])]
|
||||
(assoc-in resp [:status :message]
|
||||
(str
|
||||
server-message
|
||||
(when server-message "; ")
|
||||
"this API version is deprecated and "
|
||||
"will be disabled by the end of June 2014!")))
|
||||
(f params))
|
||||
{:status (create-response false "API version expected")}))
|
||||
|
||||
(defn get-note [{:keys [noteID]}]
|
||||
@@ -109,11 +118,12 @@
|
||||
{:status (create-response false (first errors))})))
|
||||
|
||||
|
||||
(defn update-note [{:keys [noteID note pid signature password]}]
|
||||
(defn update-note [{:keys [noteID note pid signature password noteID*]}]
|
||||
;(log "update-note: %s" {:pid pid :noteID noteID :signature signature :password password :note note})
|
||||
(let [errors (filter identity
|
||||
[(when-not (storage/valid-publisher? pid) "pid invalid")
|
||||
(when-not (= signature (storage/sign pid (storage/get-psk pid) noteID note password))
|
||||
; TODO: noteID* is a hack introduced by backwards-comp. to older APIs
|
||||
(when-not (= signature (storage/sign pid (storage/get-psk pid) (or noteID* noteID) note password))
|
||||
"signature invalid")
|
||||
(when (blank? note) "note is empty")
|
||||
(when-not (storage/valid-password? noteID password) "password invalid")])]
|
||||
|
||||
@@ -66,7 +66,11 @@
|
||||
(is (= (:title get-response) (derive-title note)))
|
||||
(is (= "1" (get-in get-response [:statistics :views])))
|
||||
(isnt (get-in get-response [:statistics :edited]))
|
||||
(is (= "noteID 'randomString' unknown"(get-in (parse-string (:body (send-request "/api/note" {:version "1.3" :noteID "randomString"}))) ["status" "message"])))
|
||||
(is (= "noteID 'randomString' unknown"
|
||||
(get-in
|
||||
(parse-string
|
||||
(:body (send-request "/api/note" {:version "1.3" :noteID "randomString"})))
|
||||
["status" "message"])))
|
||||
(is (= "3" (get-in (get-note post-response) [:statistics :views])))))
|
||||
(testing "creation with wrong signature"
|
||||
(let [response (post-note {:note note :pid pid :signature (storage/sign pid2 psk note)})]
|
||||
@@ -166,11 +170,12 @@
|
||||
:version "1.0"
|
||||
:password "qwerty"})
|
||||
body (parse-string (:body response))
|
||||
noteID (body "noteID")]
|
||||
origID (body "noteID")
|
||||
noteID (clojure.string/replace origID #"/" " ")]
|
||||
(testing "Note update"
|
||||
(is (has-status response 200))
|
||||
(is (get-in body ["status" "success"]))
|
||||
(is (storage/note-exists? noteID))
|
||||
(is (storage/note-exists? origID))
|
||||
(is (substring? "_test_ note"
|
||||
((parse-string
|
||||
(:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID}))) "note")))
|
||||
@@ -184,7 +189,8 @@
|
||||
body (parse-string (:body response))]
|
||||
(is (has-status response 200))
|
||||
(isnt (get-in body ["status" "success"]))
|
||||
(is (= "password invalid" (get-in body ["status" "message"])))
|
||||
(is (= "password invalid; this API version is deprecated and will be disabled by the end of June 2014!"
|
||||
(get-in body ["status" "message"])))
|
||||
(isnt (get-in body ["statistics" "edited"]))
|
||||
(is (substring? "_test_ note"
|
||||
((parse-string
|
||||
|
||||
Reference in New Issue
Block a user