   (testing "Jws token backend authentication"
     (let [request (make-jws-request jws-data jws-secret)
           handler (wrap-authentication identity jws-backend)
-          response (handler request)]
-      (is (= (:identity response) jws-data))))
+          request' (handler request)]
+      (is (authenticated? request'))
+      (is (= (:identity request') jws-data))))
 
   (testing "Jws token backend authentication with wrong key yields nil"
     (let [request (make-jws-request jws-data  "wrong-key")
           handler (wrap-authentication identity jws-backend)
-          response (handler request)]
-      (is (nil? (:identity response)))))
-
-  (testing "Jws token backend authentication with no token yields nil"
+          request' (handler request)]
+      (is (not (authenticated? request')))
+      (is (nil? (:identity request')))))
+
+  (testing "Jws token backend authentication without token yields nil"
     (let [request {}
           handler (wrap-authentication identity jws-backend)
-          response (handler request)]
-      (is (nil? (:identity response)))))
+          request' (handler request)]
+      (is (not (authenticated? request')))
+      (is (nil? (:identity request')))))
 
   (testing "Jws token authorizaton with wrong key yields 401"
     (let [request (make-jws-request jws-data "wrong-key")

  (testing "Jwe token backend authentication"
    (let [request (make-jwe-request jwe-data jwe-secret)
          handler (wrap-authentication identity jwe-backend)
          response (handler request)]
      (is (= (:identity response) jwe-data))))

  (testing "Jwe token backend authentication with wrong key yields nil"
    (let [request (make-jwe-request jwe-data (hash/sha256 "wrong-key"))
          handler (wrap-authentication identity jwe-backend)
          response (handler request)]
      (is (nil? (:identity response)))))

  (testing "Jwe token backend authentication with no token yields nil"
    (let [request {}
          handler (wrap-authentication identity jwe-backend)
          response (handler request)]
      (is (nil? (:identity response)))))

  (testing "Jwe token authorizaton with wrong key yields 401"
    (let [request (make-jwe-request jwe-data (hash/sha256 "wrong-key"))

                      (wrap-authorization jws-backend)
                      (wrap-authentication jws-backend))
          response (handler request)]
      (is (= (:status response) 403))
      (is (= (:body response) "Permission denied"))))

  (testing "Jws token unathorized - :unauthorized-handlercalled when provided"
    (let [request (make-jws-request jws-data "wrong-key")
          onerror (fn [_ _] {:status 3000})
          backend (token/jws-backend {:secret jws-secret
                                      :unauthorized-handler onerror})
          handler (-> (fn [req] (throw-unauthorized))
                      (wrap-authorization backend)
                      (wrap-authentication backend))
          response (handler request)]
      (is (= (:status response) 3000))))

  (testing "Jws token wrongdata - onerror handler called when provided"
    (let [request (make-jws-request jws-data "wrong-key")
          onerror (fn [_ _] {:status 3000})
          backend (token/jws-backend {:secret jws-secret
                                      :on-error onerror})
          handler (-> identity
                      (wrap-authorization backend)
                      (wrap-authentication backend))
          response (handler request)]
