last bugs fixed
This commit is contained in:
@@ -5,7 +5,9 @@ var timerDelay = iosDetected ? 800 : 400;
|
|||||||
var show = function(elem) { elem.style.display = "block" }
|
var show = function(elem) { elem.style.display = "block" }
|
||||||
var $note, $action, $preview, $plain_password, $input_elems, $dashed_line, updatePreview;
|
var $note, $action, $preview, $plain_password, $input_elems, $dashed_line, updatePreview;
|
||||||
|
|
||||||
var md5 = hex_md5;
|
var md5 = function (input) {
|
||||||
|
return hex_md5(input.replace(/[\n\r]/g, ""));
|
||||||
|
}
|
||||||
|
|
||||||
function md2html(input){
|
function md2html(input){
|
||||||
return marked(input);
|
return marked(input);
|
||||||
|
|||||||
+16
-4
@@ -4,13 +4,21 @@
|
|||||||
(:use
|
(:use
|
||||||
[NoteHub.settings]
|
[NoteHub.settings]
|
||||||
[clojure.string :rename {replace sreplace}
|
[clojure.string :rename {replace sreplace}
|
||||||
:only [replace blank? lower-case split-lines]])
|
:only [replace blank? lower-case split-lines split]])
|
||||||
(:require [NoteHub.storage :as storage]))
|
(:require
|
||||||
|
[ring.util.codec]
|
||||||
|
[NoteHub.storage :as storage]))
|
||||||
|
|
||||||
(def version "1.0")
|
(def version "1.0")
|
||||||
|
|
||||||
(def domain (get-setting :domain))
|
(def domain (get-setting :domain))
|
||||||
|
|
||||||
|
(defn log
|
||||||
|
"Logs args to the server stdout"
|
||||||
|
[string & args]
|
||||||
|
(apply printf (str "%s:" string) (str (storage/get-current-date) ":LOG") args)
|
||||||
|
(println))
|
||||||
|
|
||||||
; Concatenates all fields to a string
|
; Concatenates all fields to a string
|
||||||
(defn build-key
|
(defn build-key
|
||||||
"Returns a storage-key for the given note coordinates"
|
"Returns a storage-key for the given note coordinates"
|
||||||
@@ -31,13 +39,15 @@
|
|||||||
(defn- getPath [noteID & description]
|
(defn- getPath [noteID & description]
|
||||||
(if description
|
(if description
|
||||||
(str "/" (storage/get-short-url noteID))
|
(str "/" (storage/get-short-url noteID))
|
||||||
(str "/" (sreplace noteID #" " "/"))))
|
(let [[year month day title] (split noteID #" ")]
|
||||||
|
(apply str (interpose "/"
|
||||||
|
[year month day (ring.util.codec/url-encode title)])))))
|
||||||
|
|
||||||
(let [md5Instance (java.security.MessageDigest/getInstance "MD5")]
|
(let [md5Instance (java.security.MessageDigest/getInstance "MD5")]
|
||||||
(defn get-signature
|
(defn get-signature
|
||||||
"Returns the MD5 hash for the concatenation of all passed parameters"
|
"Returns the MD5 hash for the concatenation of all passed parameters"
|
||||||
[& args]
|
[& args]
|
||||||
(let [input (apply str args)]
|
(let [input (sreplace (apply str args) #"[\r\n]" "")]
|
||||||
(do (.reset md5Instance)
|
(do (.reset md5Instance)
|
||||||
(.update md5Instance (.getBytes input))
|
(.update md5Instance (.getBytes input))
|
||||||
(.toString (new java.math.BigInteger 1 (.digest md5Instance)) 16)))))
|
(.toString (new java.math.BigInteger 1 (.digest md5Instance)) 16)))))
|
||||||
@@ -54,6 +64,7 @@
|
|||||||
(defn post-note
|
(defn post-note
|
||||||
([note pid signature] (post-note note pid signature nil))
|
([note pid signature] (post-note note pid signature nil))
|
||||||
([note pid signature password]
|
([note pid signature password]
|
||||||
|
;(log "post-note: %s" {:pid pid :signature signature :password password :note note})
|
||||||
(let [errors (filter identity
|
(let [errors (filter identity
|
||||||
[(when-not (storage/valid-publisher? pid) "pid invalid")
|
[(when-not (storage/valid-publisher? pid) "pid invalid")
|
||||||
(when-not (= signature
|
(when-not (= signature
|
||||||
@@ -84,6 +95,7 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn update-note [noteID note pid signature password]
|
(defn update-note [noteID note pid signature password]
|
||||||
|
;(log "update-note: %s" {:pid pid :noteID noteID :signature signature :password password :note note})
|
||||||
(let [errors (filter identity
|
(let [errors (filter identity
|
||||||
(seq
|
(seq
|
||||||
[(when-not (storage/valid-publisher? pid) "pid invalid")
|
[(when-not (storage/valid-publisher? pid) "pid invalid")
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
(def pid "somePlugin")
|
(def pid "somePlugin")
|
||||||
(def pid2 "somePlugin2")
|
(def pid2 "somePlugin2")
|
||||||
(def note-title (str (apply print-str (get-date)) " hello-world-this-is-a-test-note"))
|
(def note-title (str (apply print-str (get-date)) " hello-world-this-is-a-test-note"))
|
||||||
(def note-url (str "/" (apply str (interpose "/" (get-date))) "/hello-world-this-is-a-test-note"))
|
(def note-url (str (apply str (interpose "/" (get-date))) "/hello-world-this-is-a-test-note"))
|
||||||
(defn substring? [a b] (not (= nil (re-matches (re-pattern (str "(?s).*" a ".*")) b))))
|
(defn substring? [a b] (not (= nil (re-matches (re-pattern (str "(?s).*" a ".*")) b))))
|
||||||
|
|
||||||
(defmacro isnt [arg] `(is (not ~arg)))
|
(defmacro isnt [arg] `(is (not ~arg)))
|
||||||
|
|||||||
@@ -48,6 +48,25 @@
|
|||||||
(delete-note (build-key date title))
|
(delete-note (build-key date title))
|
||||||
(not (note-exists? (build-key date title))))))))
|
(not (note-exists? (build-key date title))))))))
|
||||||
|
|
||||||
|
(deftest note-creation-utf
|
||||||
|
(let [session-key (create-session)
|
||||||
|
date (get-date)
|
||||||
|
title "радуга"
|
||||||
|
note "# Радуга\nкаждый охотник желает знать, где сидят фазаны."
|
||||||
|
[year month day] date]
|
||||||
|
(testing "Note creation with UTF8 symbols"
|
||||||
|
(is (has-status
|
||||||
|
(send-request
|
||||||
|
[:post "/post-note"]
|
||||||
|
{:session session-key
|
||||||
|
:note note
|
||||||
|
:signature (get-signature session-key note)}) 302))
|
||||||
|
(is (note-exists? (build-key date title)))
|
||||||
|
(is (substring? "знать" ((send-request (url year month day title)) :body)))
|
||||||
|
(is (do
|
||||||
|
(delete-note (build-key date title))
|
||||||
|
(not (note-exists? (build-key date title))))))))
|
||||||
|
|
||||||
(deftest note-update
|
(deftest note-update
|
||||||
(let [session-key (create-session)
|
(let [session-key (create-session)
|
||||||
date (get-date)
|
date (get-date)
|
||||||
|
|||||||
Reference in New Issue
Block a user