             [buddy.core.hash :as hash]
             [buddy.sign.jws :as jws]
             [buddy.sign.jwe :as jwe]
-            [buddy.auth :refer [throw-unauthorized]]
+            [buddy.auth :refer [throw-unauthorized authenticated?]]
             [buddy.auth.backends.token :as token]
             [buddy.auth.middleware :refer [wrap-authentication wrap-authorization]]))
 

  (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) 401))
      (is (= (:body response) "Unauthorized"))))

  (testing "Jws token authorization - authenticated but unathorized thrown yields 403"
    (let [request (make-jws-request {:userid 1} jws-secret)
