From 916fb5e65ea32398c4c84412f307fc724c877320 Mon Sep 17 00:00:00 2001 From: Timothy Washington Date: Mon, 4 Oct 2010 22:43:41 -0400 Subject: [PATCH] -- added double login check --- src/helpers.clj | 24 ++++++++++++++++++++---- src/opts_handler.clj | 18 ++++++++++-------- test/login_test.clj | 13 +++++++------ 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/helpers.clj b/src/helpers.clj index ed69d1b..1454f3f 100644 --- a/src/helpers.clj +++ b/src/helpers.clj @@ -4,7 +4,10 @@ (:require clojure.contrib.string) (:require clojure.contrib.http.agent) (:require clojure-http.resourcefully) - (:require clojure.pprint)) + (:require clojure.pprint) + + (:import java.io.ByteArrayInputStream) +) (defn url-encode " Replacing these characters http encoded ones @@ -138,11 +141,19 @@ ) +(defn parse-xml-to-hash [x-input] + + (clojure.xml/parse (ByteArrayInputStream. (.getBytes + (clojure.contrib.str-utils/str-join nil x-input) ;; get the XML string + "UTF-8"))) +) (defn get-user [db-base-URL db-system-DIR working-USER] - (execute-http-call ;; TODO - put in 404 check - (str + (let + [result-hash + (execute-http-call ;; TODO - put in 404 check + (str db-base-URL db-system-DIR (working-dir-lookup (:tag working-USER)) ;; stringing together lookup URL leaf @@ -159,5 +170,10 @@ "GET" {"Content-Type" "text/xml"} nil - ) + ) ] + + (println "RESULT USER > result-hash... " result-hash) + (parse-xml-to-hash (:body-seq result-hash)) + ) + ) diff --git a/src/opts_handler.clj b/src/opts_handler.clj index 0913b56..308be8c 100644 --- a/src/opts_handler.clj +++ b/src/opts_handler.clj @@ -79,15 +79,19 @@ (handler -(clojure.xml/parse (ByteArrayInputStream. (.getBytes - (clojure.contrib.str-utils/str-join nil - (:body-seq +;;(clojure.xml/parse (ByteArrayInputStream. (.getBytes +;; (clojure.contrib.str-utils/str-join nil + + (helpers/parse-xml-to-hash + (:body-seq (execute-http-call (str db-full-PARENT "/" db-leaf (str "?" (url-encode db-query))) "GET" {"Content-Type" "text/xml"} nil ) - )) ;; get the XML string - "UTF-8"))) + ) + ) +;; ) ;; get the XML string +;; "UTF-8"))) ) @@ -95,6 +99,4 @@ ) ) - - - \ No newline at end of file + diff --git a/test/login_test.clj b/test/login_test.clj index 2a87f60..4e5100d 100644 --- a/test/login_test.clj +++ b/test/login_test.clj @@ -43,7 +43,7 @@ ;; make the shell inactive (dosync (alter bkell/shell conj { :active false })) - (remove-user (:url-test configs) (:system-dir configs) { :tag "user" :attrs { :id "test.user" } } ) + (remove-user (:url-test configs) (:system-dir configs) { :tag "user" :attrs { :id "test.user" } :content { :tag "stub" } } ) ) @@ -56,7 +56,10 @@ (let [ user_seq - (login-user (helpers/get-user (:url-test configs) (:system-dir configs) { :tag "user" :attrs { :id "test.user"}} )) ] + (login-user + (helpers/get-user (:url-test configs) (:system-dir configs) + { :tag "user" :attrs { :id "test.user"} :content {:tag "stub"} } + )) ] (is (not (nil? user_seq)) (str @@ -65,8 +68,6 @@ ) (is (not (nil? (@bkell/shell :logged-in-user))) "User should be in a 'logged-in-user' state") - - (println "ZZzzz... " (@bkell/shell :logged-in-user)) ) ) @@ -76,12 +77,12 @@ (let [ user_seq - (login-user (helpers/get-user (:url-test configs) (:system-dir configs) { :tag "user" :attrs { :id "test.user"}} )) ] + (login-user (helpers/get-user (:url-test configs) (:system-dir configs) { :tag "user" :attrs { :id "test.user"} :content {:tag "stub"} } )) ] (try (def nd_user - (login-user (helpers/get-user (:url-test configs) (:system-dir configs) { :tag "user" :attrs { :id "test.user"}} )) ) + (login-user (helpers/get-user (:url-test configs) (:system-dir configs) { :tag "user" :attrs { :id "test.user"} :content {:tag "stub"} } )) ) ;;(catch ...) (finally (is (not (nil? nd_user)) "2nd_user SHOULD NOT be nil") -- 2.11.4.GIT