r5478: *** empty log message ***
authorKevin M. Rosenberg <kevin@rosenberg.net>
Sat, 9 Aug 2003 21:42:43 +0000 (21:42 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Sat, 9 Aug 2003 21:42:43 +0000 (21:42 +0000)
project.lisp
sessions.lisp
tests.lisp [new file with mode: 0644]
uri.lisp
wol.asd

index 6a285f65f706dd0ca4e3562e0a9dd0413b22f8f0..027f1bdcf7914bd98a1dbc00f775398709e0b9aa 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  July 2003
 ;;;;
-;;;; $Id: project.lisp,v 1.8 2003/08/08 23:40:13 kevin Exp $
+;;;; $Id: project.lisp,v 1.9 2003/08/09 21:42:24 kevin Exp $
 ;;;;
 ;;;; This file and Wol are Copyright (c) 2001-2003 by Kevin M. Rosenberg
 ;;;; *************************************************************************
 
 (defun redirect-entity (page req ent &optional plist)
   (let ((proj (entity-project ent))
-       (url (make-wol-url page req ent plist)))
+       (url (render-uri
+             (copy-uri (request-uri req)
+                       :path (make-wol-url page req ent plist))
+             nil)))
     (ecase (project-connector proj)
       (:aserve
        (net.aserve:with-http-response 
           ((aserve-request req) 
            (entity-aserve-entity ent)
-           :response net.aserve:*response-moved-permanently*)
+           :response net.aserve:*response-temporary-redirect*)
         (set-cookie req ent)
         (net.aserve:with-http-body 
             ((aserve-request req) 
index 39e2fe579efde1b469f7656f70de28ecbc96e667..3de32938fef02f3bf487d463fc5ce00ab7065f99 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  July 2003
 ;;;;
-;;;; $Id: sessions.lisp,v 1.4 2003/08/08 23:40:13 kevin Exp $
+;;;; $Id: sessions.lisp,v 1.5 2003/08/09 21:42:24 kevin Exp $
 ;;;;
 ;;;; This file and Wol are Copyright (c) 2003 by Kevin M. Rosenberg
 ;;;; *************************************************************************
 (in-package #:wol)
 
 
-#||
-(awhen (and session-id (find-websession session-id ent))
-       (setf (websession-from-req req) it)
-       (setf (websession-method it) :url))
-||#
-
 (defun find-websession (key ent)
   (let ((sessions (sessions (session-master (entity-project ent)))))
     (maphash
@@ -43,7 +37,7 @@
                 :key key
                 :lastref (get-universal-time)
                 :lifetime (lifetime (session-master (entity-project ent)))
-                :method :try-cookie))
+                :method nil))
         (hash (sessions (session-master (entity-project ent)))))
     (when hash
       (setf (gethash key hash) sess)
       sess)))
 
 
-(defun compute-session (req ent)
+(defun compute-session (req ent url-session-id)
   (when (is-session-enabled ent)
-    (let ((key (cookie-session-key ent (request-cookies req)))
-         (has-cookie-key nil)
-         (has-url-key nil))
-      (if key
-         (setq has-cookie-key t)
-       (when (setq key (url-session-key (request-raw-uri req)))
-         (setq has-url-key t)))
-      (let* ((found-session (when key (find-websession key ent)))
-            (session (aif found-session it (make-websession req ent)))) 
-       (setf (websession-from-req req) session)
-       (when found-session
-         (if has-cookie-key
-             (setf (websession-method session) :cookies)
-           (when has-url-key
-             (setf (websession-method session) :url))))
-       session))))
+    (let* ((cookie-session-id (cookie-session-key ent (request-cookies req)))
+          (session-id (or url-session-id cookie-session-id))
+          (found-session (when session-id
+                           (find-websession session-id ent)))
+          (session (aif found-session
+                        it
+                        (make-websession req ent))))
+      (cond
+       (cookie-session-id
+        (setf (websession-method session) :cookies))
+       (url-session-id
+        (case (websession-method session)
+          (nil
+           (setf (websession-method session) :try-cookie))
+          (:try-cookie
+           (setf (websession-method session) :try-cookie-2))
+          (t
+           (setf (websession-method session) :url)))))
+      (setf (websession-from-req req) session))))
   
 
 ;;; Reap expired sessions
diff --git a/tests.lisp b/tests.lisp
new file mode 100644 (file)
index 0000000..0ab814f
--- /dev/null
@@ -0,0 +1,48 @@
+;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
+;;;; *************************************************************************
+;;;; FILE IDENTIFICATION
+;;;;
+;;;; Id:      $Id: tests.lisp,v 1.1 2003/08/09 21:42:24 kevin Exp $
+;;;; Purpose: Self Test suite for WOL
+;;;;
+;;;; *************************************************************************
+
+(in-package #:cl-user)
+(defpackage #:wol-tests
+  (:use #:xlunit #:cl #:wol #:puri)
+  (:export #:do-tests))
+(in-package #:wol-tests)
+
+(import '(wol::req-recode-uri-sans-session-id wol::request-uri
+         wol::request-decoded-uri-path))
+
+;; Helper test fixture
+
+(defclass test-url (test-case)
+  ((req :accessor req)))
+
+(defmethod set-up ((self test-url))
+  (let ((uri (parse-uri "/~abcdefg~/index.html")))
+    (setf (req self) (make-instance 'wol::http-request
+                      :raw-uri uri
+                      :uri uri))))
+
+(def-test-method test-returned-session ((self test-url) :run nil)
+  (assert-equal "abcdefg" (req-recode-uri-sans-session-id (req self))))
+(def-test-method test-recomputed-uri ((self test-url) :run nil)
+  (req-recode-uri-sans-session-id (req self))
+  (assert-equal (render-uri (request-uri (req self)) nil)
+               "/index.html"))
+
+(def-test-method test-decoded-uri ((self test-url) :run nil)
+  (req-recode-uri-sans-session-id (req self))
+  (assert-equal (request-decoded-uri-path (req self))
+               "/index.html"))
+
+
+(textui-test-run (get-suite test-url))
+
+(defun do-tests ()
+  (or (was-successful (run (get-suite test-url)))
+      (error "Failed tests")))
index 1011b1036dcd0e6a60f8d67753953dacaf04e4cc..7c38f304226c95c1c43d190cb8aadb25143fff39 100644 (file)
--- a/uri.lisp
+++ b/uri.lisp
@@ -7,24 +7,23 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  July 2003
 ;;;;
-;;;; $Id: uri.lisp,v 1.6 2003/08/08 23:40:13 kevin Exp $
+;;;; $Id: uri.lisp,v 1.7 2003/08/09 21:42:24 kevin Exp $
 ;;;;
 ;;;; This file and Wol are Copyright (c) 2003 by Kevin M. Rosenberg
 ;;;; *************************************************************************
 
 (in-package #:wol)
 
-(defun uri->recode-uri-sans-session-id (uri)
-  (let ((parsed-path (puri:uri-parsed-path uri)))
-    (cond
-     ((and (eq :absolute (first parsed-path))
-          (is-raw-session-id (second parsed-path)))
-      (values (copy-uri uri :place t
-                             :parsed-path 
-                             (list* :absolute (cddr parsed-path)))
-             (raw-session-id->session-id (second parsed-path))))
-     (t
-      (values uri nil)))))
+(defun req-recode-uri-sans-session-id (req)
+  (setq cl-user::r req)
+  (let ((ppath (puri:uri-parsed-path (request-uri req))))
+    (when (is-raw-session-id (second ppath))
+      (let ((new-path (list* (car ppath) (cddr ppath))))
+       (setf (uri-parsed-path (request-uri req)) new-path)
+       (setf (uri-parsed-path (request-raw-uri req)) new-path))
+      (setf (request-decoded-uri-path req)
+       (uridecode-string (uri-path (request-raw-uri req))))
+      (raw-session-id->session-id (second ppath)))))
 
 (defun request-cookies (req)
   (aif (aserve-request req)
   (let ((name (project-name (entity-project ent))))
     (cdr (assoc name cookies :test #'string-equal))))
 
-(defun url-session-key (url)
-  "Return a session key encoded in a URL"
-  nil)
-
 (defun compute-uris (req ent)
   "Compute URI's of a request"
-  (compute-session req ent)
-  (multiple-value-bind (page plists query) 
-      (decode-url (puri:uri-path (request-raw-uri req)))
-    (when page
-      (setf (request-page req) (base-page-name page ent)))
-    (when plists
-      (setf (request-plist req) (car plists))
-      (setf (request-next-plists req) (cdr plists))
-      (when (null page)
-       (awhen (getf (request-plist req) :page)
-              (setf (request-page req) it))))
-    (setf (request-uri-query req) query)))
+  (let ((url-session-id (req-recode-uri-sans-session-id req)))
+    (compute-session req ent url-session-id)
+    
+    (multiple-value-bind (page plists query) 
+       (decode-url (puri:uri-path (request-raw-uri req)))
+      (when page
+       (setf (request-page req) (base-page-name page ent)))
+      (when plists
+       (setf (request-plist req) (car plists))
+       (setf (request-next-plists req) (cdr plists))
+       (when (null page)
+         (awhen (getf (request-plist req) :page)
+                (setf (request-page req) it))))
+      (setf (request-uri-query req) query))))
 
 
 ;;; URI Functions
        (url-plist (append (list :page page) plist))
        (prefix (project-prefix (entity-project ent))))
     (concatenate 'string
+      prefix
       (if (and session
                 (websession-key session)
-                (eq :url (websession-method session)))
-         (format nil "/~~~A~~/" (websession-key session))
+                (not (eq :cookies (websession-method session))))
+         (format nil "~~~A~~/" (websession-key session))
        "")
-      prefix
       (if (null plist)
        (concatenate 'string page ".html")
        (concatenate 'string
   (let ((str (plist-to-compressed-string plist)))
     (if base64
        (string-to-base64-string str :uri t)
-       (escape-uri-field str))))
+       (uriencode-string str))))
 
 (defun url-string-to-plist (str &key (base64 t))
   (let ((decode (if base64
                    (base64-string-to-string str :uri t)
-                   (unescape-uri-field str))))
+                   (uridecode-string str))))
     (when decode
       (ignore-errors (compressed-string-to-plist decode)))))
 
diff --git a/wol.asd b/wol.asd
index 241638b03ac6784913216908acac911472290f06..65eeb7022a134416cc8737cbbd68b083914a2db8 100644 (file)
--- a/wol.asd
+++ b/wol.asd
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  July 2003
 ;;;;
-;;;; $Id: wol.asd,v 1.5 2003/08/05 23:00:28 kevin Exp $
+;;;; $Id: wol.asd,v 1.6 2003/08/09 21:42:24 kevin Exp $
 ;;;;
 ;;;; This file and Wol are Copyright (c) 2003 by Kevin M. Rosenberg
 ;;;; *************************************************************************
      (:file "log" :depends-on ("classes"))
      (:file "color-picker" :depends-on ("package"))
      ))
+
+(defmethod perform ((o test-op) (c (eql (find-system 'wol))))
+  (operate 'load-op 'wol-tests)
+  (operate 'test-op 'wol-tests))
+
+(defsystem wol-tests
+    :depends-on (wol xlunit)
+    :components ((:file "tests")))
+
+(defmethod perform ((o test-op) (c (eql (find-system 'wol-tests))))
+  (operate 'load-op 'wol-tests)
+  (or (funcall (intern (symbol-name '#:do-tests)
+                      (find-package '#:wol-tests)))
+      (error "test-op failed")))
+