diff --git a/LANDING.md b/LANDING.md index e0ed728..918ec53 100644 --- a/LANDING.md +++ b/LANDING.md @@ -9,6 +9,7 @@ - **API**: Integrate the publishing functionality into your editor using the official [NoteHub API](/api). ## Changelog + - July 2014: deprecated all API versions less than 1.4 - March 2014: all notes with __less than 30 views after the first 30 days__ will expire. - February 2014: a simple JS-client for API testing [added](/api-test.html). - January 2014: diff --git a/src/notehub/api.clj b/src/notehub/api.clj index 7a426dd..1dc4fd4 100644 --- a/src/notehub/api.clj +++ b/src/notehub/api.clj @@ -64,23 +64,7 @@ (let [req-version (Double/parseDouble req-version) version (Double/parseDouble version)] (if (< req-version version) - (let [args params - args (if (and (:noteID args) (< req-version 1.3)) - (assoc args - :noteID (sreplace (args :noteID) #" " "/") - :noteID* (args :noteID)) - args) - args (if (and (:note args) (< req-version 1.4)) - (assoc args :note* (sreplace (args :note) #"[\n\r]" "")) - args) - resp (f args) - 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!"))) + {:status (create-response false "Deprecated API version")} (f params))) {:status (create-response false "API version expected")})) @@ -98,12 +82,11 @@ {:status (create-response false "noteID '%s' unknown" noteID)})) (defn post-note - [{:keys [note pid signature password note*] :as params}] + [{:keys [note pid signature password] :as params}] ;(log "post-note: %s" {:pid pid :signature signature :password password :note note}) (let [errors (filter identity [(when-not (storage/valid-publisher? pid) "pid invalid") - ; TODO: remove note* after June 2014 - (when-not (= signature (storage/sign pid (storage/get-psk pid) (or note* note))) + (when-not (= signature (storage/sign pid (storage/get-psk pid) note)) "signature invalid") (when (blank? note) "note is empty")])] (if (empty? errors) @@ -129,14 +112,11 @@ {:status (create-response false (first errors))}))) -(defn update-note [{:keys [noteID note pid signature password noteID* note*]}] +(defn update-note [{:keys [noteID note pid signature password]}] ;(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") - ; 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) - ; TODO: remove note* after June 2014 - (or note* note) password)) + (when-not (= signature (storage/sign pid (storage/get-psk pid) noteID note password)) "signature invalid") (when (blank? note) "note is empty") (when-not (storage/valid-password? noteID password) "password invalid")])] diff --git a/src/notehub/storage.clj b/src/notehub/storage.clj index 4b33add..e6fa472 100644 --- a/src/notehub/storage.clj +++ b/src/notehub/storage.clj @@ -133,6 +133,7 @@ url)))) (defn gc [password dry] + (println (get-setting :admin-pw)) (when (= password (get-setting :admin-pw)) (let [N 30 timestamp (- (get-current-date) (* N 24 60 60 1000)) diff --git a/test/notehub/test/api.clj b/test/notehub/test/api.clj index 8f10b8b..0d4648a 100644 --- a/test/notehub/test/api.clj +++ b/test/notehub/test/api.clj @@ -125,15 +125,15 @@ (is (has-status response 200)) (is (get-in body ["status" "success"])) (is (= note ((parse-string - (:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID}))) "note"))) + (:body (send-request [:get "/api/note"] {:version "1.4" :noteID noteID}))) "note"))) + (is (= "Deprecated API version" (get-in (parse-string + (:body (send-request [:get "/api/note"] {:version "1.3" :noteID noteID}))) ["status" "message"]))) (is (= "API version expected" (get-in (parse-string (:body (send-request [:get "/api/note"] {:noteID noteID}))) ["status" "message"]))) (is (= note ((parse-string - (:body (send-request [:get "/api/note"] {:version "1.1" - :noteID (clojure.string/replace noteID #"/" " ")}))) "note"))) + (:body (send-request [:get "/api/note"] {:version "1.4" :noteID noteID}))) "note"))) (isnt (= note ((parse-string - (:body (send-request [:get "/api/note"] {:version "1.4" - :noteID (clojure.string/replace noteID #"/" " ")}))) "note"))) + (:body (send-request [:get "/api/note"] {:version "1.3" :noteID noteID}))) "note"))) (is (do (storage/delete-note noteID) (not (storage/note-exists? noteID))))))) @@ -170,31 +170,29 @@ :version "1.4" :password "qwerty"}) body (parse-string (:body response)) - origID (body "noteID") - noteID (clojure.string/replace origID #"/" " ")] + noteID (body "noteID")] (testing "Note update" (is (has-status response 200)) (is (get-in body ["status" "success"])) - (is (storage/note-exists? origID)) + (is (storage/note-exists? noteID)) (is (substring? "_test_ note" ((parse-string - (:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID}))) "note"))) + (:body (send-request [:get "/api/note"] {:version "1.4" :noteID noteID}))) "note"))) (let [response (send-request [:put "/api/note"] {:noteID noteID :note "WRONG pass" :pid pid :signature (storage/sign pid psk noteID "WRONG pass" "qwerty1") :password "qwerty1" - :version "1.0"}) + :version "1.4"}) body (parse-string (:body response))] (is (has-status response 200)) (isnt (get-in body ["status" "success"])) - (is (= "password invalid; this API version is deprecated and will be disabled by the end of June 2014!" - (get-in body ["status" "message"]))) + (is (= "password invalid" (get-in body ["status" "message"]))) (isnt (get-in body ["statistics" "edited"])) (is (substring? "_test_ note" ((parse-string - (:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID}))) "note")))) + (:body (send-request [:get "/api/note"] {:version "1.4" :noteID noteID}))) "note")))) (is (get-in (parse-string (:body (send-request [:put "/api/note"] {:noteID noteID @@ -202,13 +200,14 @@ :pid pid :signature (storage/sign pid psk noteID "UPDATED CONTENT" "qwerty") :password "qwerty" - :version "1.0"}))) ["status" "success"])) + :version "1.4"}))) ["status" "success"])) (isnt (= nil (((parse-string - (:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID}))) + (:body (send-request [:get "/api/note"] {:version "1.4" :noteID noteID}))) "statistics") "edited"))) - (is (substring? "UPDATED CONTENT" + (let [resp (send-request [:get "/api/note"] {:version "1.4" :noteID noteID})] + (is (substring? "UPDATED CONTENT" ((parse-string - (:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID}))) "note"))) + (:body resp)) "note")))) (is (do (storage/delete-note noteID) (not (storage/note-exists? noteID)))))))