Browse Source

last bugs fixed

master
Christian Mueller 12 years ago
parent
commit
c84909d891
  1. 4
      resources/public/js/main.js
  2. 20
      src/NoteHub/api.clj
  3. 2
      test/NoteHub/test/api.clj
  4. 19
      test/NoteHub/test/views/pages.clj

4
resources/public/js/main.js

@ -5,7 +5,9 @@ var timerDelay = iosDetected ? 800 : 400; @@ -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);

20
src/NoteHub/api.clj

@ -4,13 +4,21 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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")

2
test/NoteHub/test/api.clj

@ -10,7 +10,7 @@ @@ -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
test/NoteHub/test/views/pages.clj

@ -48,6 +48,25 @@ @@ -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)

Loading…
Cancel
Save