Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

another condition to fire a signal on cookie failure and fix the tests

  • Loading branch information...
commit 3e4fcd0a15d3f02113b2286c8331a95e1a14c334 1 parent 77b106b
@nicferrier authored
Showing with 26 additions and 7 deletions.
  1. +8 −3 elnode-tests.el
  2. +18 −4 elnode.el
View
11 elnode-tests.el
@@ -1408,11 +1408,15 @@ the wrapping of a specified handler with the login sender."
:header-name "Location"
:header-value "/my-login/?redirect=/somepage/test/")))))
+
+(defvar elnode-test--my-db nil
+ "Special variable just for specific db test.")
+
(ert-deftest elnode-with-auth-specific-db ()
"Test using a specific database."
;; Setup the user db
(let ((elnode-auth-db (elnode-db-make '(elnode-db-hash)))
- (my-db (elnode-db-make '(elnode-db-hash))))
+ (elnode-test--my-db (elnode-db-make '(elnode-db-hash))))
(elnode--auth-init-user-db
'(("nferrier" . "password")
("someuser" . "secret"))
@@ -1420,13 +1424,13 @@ the wrapping of a specified handler with the login sender."
(elnode--auth-init-user-db
'(("nic" . "test")
("other" . "simple"))
- my-db)
+ elnode-test--my-db)
;; Setup handlers to wrap
(elnode-auth-flets
(elnode-auth-define-scheme
'test-auth
:test :cookie
- :auth-db my-db
+ :auth-db elnode-test--my-db
:cookie-name "secret"
:redirect (elnode-auth-make-login-wrapper
'auth-reqd-handler
@@ -1456,6 +1460,7 @@ the wrapping of a specified handler with the login sender."
:header-name "Location"
:header-value "/somepage/test/")))))
+
(provide 'elnode-tests)
;;; elnode-tests.el ends here
View
22 elnode.el
@@ -3267,6 +3267,20 @@ be an `elnode-db'. By default it is `elnode-loggedin-db'."
(token (match-string 2 cookie-value)))
(elnode-auth-check-p username token :loggedin-db loggedin-db)))))
+(defun* elnode-auth-cookie-check (httpcon
+ &key
+ (cookie-name "elnode-auth")
+ (loggedin-db elnode-loggedin-db))
+ "Signal on cookie failure.
+
+See `elnode-auth-cookie-check-p' for more details."
+ (unless (elnode-auth-cookie-check-p
+ httpcon
+ :cookie-name cookie-name
+ :loggedin-db loggedin-db)
+ ;; Not sure this is the correct token...
+ (signal 'elnode-auth-token :not-logged-in)))
+
(defun* elnode-auth-http-login (httpcon
username password logged-in
&key
@@ -3507,10 +3521,10 @@ If the auth fails then evaluate ANONYMOUS instead."
elnode--defined-authentication-schemes)))
(if (eq :cookie (plist-get scheme-list :test))
(condition-case token
- (let ((cookie
- (elnode-auth-cookie-check-p
- ,httpconv
- :cookie-name (plist-get scheme-list :cookie-name))))
+ (progn
+ (elnode-auth-cookie-check
+ ,httpconv
+ :cookie-name (plist-get scheme-list :cookie-name))
;; Do whatever the code was now.
,authd)
;; On auth failure do the ELSE
Please sign in to comment.
Something went wrong with that request. Please try again.