From 628dda3f26ad183880fea5871c37b9cfa33b425a Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Sat, 9 Aug 2003 21:42:43 +0000 Subject: [PATCH] r5478: *** empty log message *** --- project.lisp | 9 +++++--- sessions.lisp | 47 ++++++++++++++++++-------------------- tests.lisp | 48 +++++++++++++++++++++++++++++++++++++++ uri.lisp | 63 ++++++++++++++++++++++++--------------------------- wol.asd | 17 +++++++++++++- 5 files changed, 122 insertions(+), 62 deletions(-) create mode 100644 tests.lisp diff --git a/project.lisp b/project.lisp index 6a285f6..027f1bd 100644 --- a/project.lisp +++ b/project.lisp @@ -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 ;;;; ************************************************************************* @@ -169,13 +169,16 @@ (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) diff --git a/sessions.lisp b/sessions.lisp index 39e2fe5..3de3293 100644 --- a/sessions.lisp +++ b/sessions.lisp @@ -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 ;;;; ************************************************************************* @@ -15,12 +15,6 @@ (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) @@ -51,24 +45,27 @@ 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 index 0000000..0ab814f --- /dev/null +++ b/tests.lisp @@ -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"))) diff --git a/uri.lisp b/uri.lisp index 1011b10..7c38f30 100644 --- 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) @@ -37,24 +36,22 @@ (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 @@ -91,12 +88,12 @@ (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 @@ -111,12 +108,12 @@ (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 241638b..65eeb70 100644 --- 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 ;;;; ************************************************************************* @@ -40,3 +40,18 @@ (: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"))) + -- 2.34.1