last bugs fixed

This commit is contained in:
Christian Mueller
2014-01-17 22:27:08 +01:00
parent 9bd70deadc
commit c84909d891
4 changed files with 39 additions and 6 deletions
+3 -1
View File
@@ -5,7 +5,9 @@ var timerDelay = iosDetected ? 800 : 400;
var show = function(elem) { elem.style.display = "block" }
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){
return marked(input);
+16 -4
View File
@@ -4,13 +4,21 @@
(:use
[NoteHub.settings]
[clojure.string :rename {replace sreplace}
:only [replace blank? lower-case split-lines]])
(:require [NoteHub.storage :as storage]))
:only [replace blank? lower-case split-lines split]])
(:require
[ring.util.codec]
[NoteHub.storage :as storage]))
(def version "1.0")
(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
(defn build-key
"Returns a storage-key for the given note coordinates"
@@ -31,13 +39,15 @@
(defn- getPath [noteID & description]
(if description
(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")]
(defn get-signature
"Returns the MD5 hash for the concatenation of all passed parameters"
[& args]
(let [input (apply str args)]
(let [input (sreplace (apply str args) #"[\r\n]" "")]
(do (.reset md5Instance)
(.update md5Instance (.getBytes input))
(.toString (new java.math.BigInteger 1 (.digest md5Instance)) 16)))))
@@ -54,6 +64,7 @@
(defn post-note
([note pid signature] (post-note note pid signature nil))
([note pid signature password]
;(log "post-note: %s" {:pid pid :signature signature :password password :note note})
(let [errors (filter identity
[(when-not (storage/valid-publisher? pid) "pid invalid")
(when-not (= signature
@@ -84,6 +95,7 @@
(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
(seq
[(when-not (storage/valid-publisher? pid) "pid invalid")
+1 -1
View File
@@ -10,7 +10,7 @@
(def pid "somePlugin")
(def pid2 "somePlugin2")
(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))))
(defmacro isnt [arg] `(is (not ~arg)))
+19
View File
@@ -48,6 +48,25 @@
(delete-note (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
(let [session-key (create-session)
date (get-date)