diff --git a/doc/How-To.md b/doc/How-To.md index 3b46de5f..1ca15959 100644 --- a/doc/How-To.md +++ b/doc/How-To.md @@ -32,7 +32,7 @@ To implement login, you need to [use the session interceptor](tutorials.md#inter ```clojure (let [;; Create a unique ID - session-id (UUID/randomUUID)] + session-id (random-uuid)] ;; Store a new session in session storage (add! session-storage session-id {:session-id session-id}) ;; Make sure session-id is part of the response @@ -64,7 +64,7 @@ you already have this injected, you can modify your create session function like (let [;; Get user from database result user (-> state :response-data :db-data first) ;; Create session - session-id (UUID/randomUUID)] + session-id (random-uuid)] ;; Store the new session in session storage. Notice the addition of user. (add! session-storage session-id (assoc user :session-id session-id)) ;; Make sure session-id is part of the response @@ -82,7 +82,7 @@ Be sure to remove user's password and any other sensitive information before sto ;; Remove password for session storage (dissoc :users/password)) ;; Create session id - session-id (UUID/randomUUID)] + session-id (random-uuid)] ;; Store the new session in session storage (add! session-storage session-id (assoc user :session-id session-id)) ;; Make sure session-id is part of the response @@ -101,7 +101,7 @@ Next, we check if the credentials are correct, so we use an `if` statement. ;; Remove password for session storage (dissoc :users/password)) ;; Create session ID - session-id (UUID/randomUUID)] + session-id (random-uuid)] ;; Store the new session in session storage (add! session-storage session-id (assoc user :session-id session-id)) ;; Make sure session-id is part of the response diff --git a/doc/tutorials.md b/doc/tutorials.md index 99881d86..1194fb33 100644 --- a/doc/tutorials.md +++ b/doc/tutorials.md @@ -368,7 +368,7 @@ Adding to the previous examples: After the session addition, it updates the user's last-login value in the database." [state] (if (valid-credentials? state) - (let [new-session-id (str (UUID/randomUUID)) + (let [new-session-id (str (random-uuid)) session-backend (-> state :deps :session-backend) {:users/keys [id] :as user} (-> state :response-data :db-data first)] (remove-from-session-store! session-backend id) @@ -584,7 +584,7 @@ ping: (defn ping [deps] (let [channel (get-in deps [:events-channel :channel])] (async/>!! channel {:type :ping - :id (str (UUID/randomUUID)) + :id (str (random-uuid)) :timestamp (.getTime (Date.))}))) (defn ->system diff --git a/docs/0.3.0/How-To.html b/docs/0.3.0/How-To.html index 7e35654c..31bff972 100644 --- a/docs/0.3.0/How-To.html +++ b/docs/0.3.0/How-To.html @@ -22,7 +22,7 @@

Login implem

To implement login, you need to use the session interceptor in

(let [;; Create a unique ID
-      session-id (UUID/randomUUID)]
+      session-id (random-uuid)]
   ;; Store a new session in session storage
   (add! session-storage session-id {:session-id session-id})
   ;; Make sure session-id is part of the response
@@ -45,7 +45,7 @@ 

Login implem
(let [;; Get user from database result
       user (-> state :response-data :db-data first)
       ;; Create session
-      session-id (UUID/randomUUID)]
+      session-id (random-uuid)]
   ;; Store the new session in session storage. Notice the addition of user. 
   (add! session-storage session-id (assoc user :session-id session-id))
   ;; Make sure session-id is part of the response
@@ -60,7 +60,7 @@ 

Login implem ;; Remove password for session storage (dissoc :users/password)) ;; Create session id - session-id (UUID/randomUUID)] + session-id (random-uuid)] ;; Store the new session in session storage (add! session-storage session-id (assoc user :session-id session-id)) ;; Make sure session-id is part of the response @@ -76,7 +76,7 @@

Login implem ;; Remove password for session storage (dissoc :users/password)) ;; Create session ID - session-id (UUID/randomUUID)] + session-id (random-uuid)] ;; Store the new session in session storage (add! session-storage session-id (assoc user :session-id session-id)) ;; Make sure session-id is part of the response @@ -282,4 +282,4 @@

Data ownership

(-> state (assoc :query (delete-query state)) (assoc-in [:request-data :restriction-fn] restriction-fn)))) -
\ No newline at end of file +

diff --git a/examples/acl/src/backend/app/interceptors/load_user.clj b/examples/acl/src/backend/app/interceptors/load_user.clj index 870f669b..f97c3984 100644 --- a/examples/acl/src/backend/app/interceptors/load_user.clj +++ b/examples/acl/src/backend/app/interceptors/load_user.clj @@ -1,10 +1,7 @@ (ns interceptors.load-user (:require [honeysql.helpers :refer [select from where]] - [xiana.db :as db]) - (:import - (java.util - UUID))) + [xiana.db :as db])) (defn ->role [user] @@ -18,7 +15,7 @@ (defn valid-user? [{:keys [request] :as state}] - (let [user-id (UUID/fromString (get-in request [:headers :authorization])) + (let [user-id (parse-uuid (get-in request [:headers :authorization])) datasource (get-in state [:deps :db :datasource]) query (-> {} (select :*) @@ -31,8 +28,8 @@ (def load-user! {:enter (fn [{:keys [request] :as state}] (let [guest-user {:users/role :guest - :users/id (UUID/randomUUID)} - session-id (get-in request [:headers :session-id] (UUID/randomUUID)) + :users/id (random-uuid)} + session-id (get-in request [:headers :session-id] (random-uuid)) user (try (let [valid-user (valid-user? state)] (if (empty? valid-user) guest-user diff --git a/examples/acl/src/backend/app/models/comments.clj b/examples/acl/src/backend/app/models/comments.clj index a9048a40..0fc0e070 100644 --- a/examples/acl/src/backend/app/models/comments.clj +++ b/examples/acl/src/backend/app/models/comments.clj @@ -8,24 +8,21 @@ columns values sset] - :as helpers]) - (:import - (java.util - UUID))) + :as helpers])) (defn fetch-query [{{{id :id} :query-params} :request :as state}] (assoc state :query (cond-> (from (select :*) :comments) - id (where [:= :id (UUID/fromString id)])))) + id (where [:= :id (parse-uuid id)])))) (defn add-query [{{user-id :users/id} :session-data {{content :content post-id :post_id} :body-params} :request :as state}] - (let [pid (try (UUID/fromString post-id) - (catch Exception _ (UUID/randomUUID)))] + (let [pid (try (parse-uuid post-id) + (catch Exception _ (random-uuid)))] (assoc state :query (-> (insert-into :comments) (columns :content :post_id :user_id) (values [[content pid user-id]]))))) @@ -35,7 +32,7 @@ {{content :content} :body-params} :request :as state}] (assoc state :query (-> (helpers/update :comments) - (where [:= :id (UUID/fromString id)]) + (where [:= :id (parse-uuid id)]) (sset {:content content})))) (defn delete-query @@ -43,4 +40,4 @@ :as state}] (assoc state :query (cond-> (delete-from :comments) - id (where [:= :id (UUID/fromString id)])))) + id (where [:= :id (parse-uuid id)])))) diff --git a/examples/acl/src/backend/app/models/posts.clj b/examples/acl/src/backend/app/models/posts.clj index b8f28b59..1a1899e4 100644 --- a/examples/acl/src/backend/app/models/posts.clj +++ b/examples/acl/src/backend/app/models/posts.clj @@ -8,17 +8,14 @@ left-join sset delete-from] - :as helpers]) - (:import - (java.util - UUID))) + :as helpers])) (defn fetch-query [{{{id :id} :query-params} :request :as state}] (assoc state :query (cond-> (from (select :*) :posts) - id (where [:= :id (UUID/fromString id)])))) + id (where [:= :id (parse-uuid id)])))) (defn add-query [{{user-id :users/id} :session-data @@ -35,7 +32,7 @@ (let [content (or (get-in state [:request :params :content]) (get-in state [:request :body-params :content]))] (assoc state :query (-> (helpers/update :posts) - (where [:= :id (UUID/fromString id)]) + (where [:= :id (parse-uuid id)]) (sset {:content content}))))) (defn delete-query @@ -43,15 +40,15 @@ :as state}] (assoc state :query (cond-> (delete-from :posts) - id (where [:= :id (UUID/fromString id)])))) + id (where [:= :id (parse-uuid id)])))) (defn fetch-by-ids-query [{{{ids :ids} :body-params} :request :as state}] (assoc state :query (cond-> (from (select :*) :posts) - ids (where [:in :id (map #(UUID/fromString %) [ids])]) - (coll? ids) (where [:in :id (map #(UUID/fromString %) ids)])))) + ids (where [:in :id (map #(parse-uuid %) [ids])]) + (coll? ids) (where [:in :id (map #(parse-uuid %) ids)])))) (defn fetch-with-comments-query [{{{id :id} :query-params} :request @@ -59,4 +56,4 @@ (assoc state :query (cond-> (-> (select :*) (from :posts) (left-join :comments [:= :posts.id :comments.post_id])) - id (where [:= :posts.id (UUID/fromString id)])))) + id (where [:= :posts.id (parse-uuid id)])))) diff --git a/examples/acl/src/backend/app/models/users.clj b/examples/acl/src/backend/app/models/users.clj index b164f730..c37258c5 100644 --- a/examples/acl/src/backend/app/models/users.clj +++ b/examples/acl/src/backend/app/models/users.clj @@ -10,10 +10,7 @@ left-join values sset] - :as helpers]) - (:import - (java.util - UUID))) + :as helpers])) (defn ->store-user [m] @@ -28,7 +25,7 @@ :as state}] (assoc state :query (cond-> (from (select :*) :users) - id (where [:= :id (UUID/fromString id)])))) + id (where [:= :id (parse-uuid id)])))) (defn add-query [{{body :body-params} :request @@ -42,15 +39,15 @@ {body :body-params} :request :as state}] (assoc state :query (-> (helpers/update :users) - (where [:= :id (UUID/fromString id)]) - (sset (core/update (->store-user body) :id #(UUID/fromString %)))))) + (where [:= :id (parse-uuid id)]) + (sset (core/update (->store-user body) :id #(parse-uuid %)))))) (defn delete-query [{{{id :id} :query-params} :request :as state}] (assoc state :query (cond-> (delete-from :users) - id (where [:= :id (UUID/fromString id)])))) + id (where [:= :id (parse-uuid id)])))) (defn fetch-with-post-comments-query [{{{id :id} :query-params} :request @@ -59,7 +56,7 @@ (from :users) (left-join :posts [:= :posts.user_id :users.id]) (merge-left-join :comments [:= :posts.id :comments.post_id])) - id (where [:= :users.id (UUID/fromString id)])))) + id (where [:= :users.id (parse-uuid id)])))) (defn fetch-with-post-query [{{{id :id} :query-params} :request @@ -67,4 +64,4 @@ (assoc state :query (cond-> (-> (select :*) (from :users) (left-join :posts [:= :posts.user_id :users.id])) - id (where [:= :users.id (UUID/fromString id)])))) + id (where [:= :users.id (parse-uuid id)])))) diff --git a/examples/sessions/src/backend/app/controllers/login.clj b/examples/sessions/src/backend/app/controllers/login.clj index 0b392fb1..4778f798 100644 --- a/examples/sessions/src/backend/app/controllers/login.clj +++ b/examples/sessions/src/backend/app/controllers/login.clj @@ -2,10 +2,7 @@ (:require [clojure.data.json :as json] [ring.util.request :refer [body-string]] - [xiana.session :as session]) - (:import - (java.util - UUID))) + [xiana.session :as session])) (def db [{:id 1 @@ -31,7 +28,7 @@ (json/read-str :key-fn keyword)) (throw (ex-message "Missing body"))) user (find-user (:email rbody)) - session-id (UUID/randomUUID) + session-id (random-uuid) session-data {:session-id session-id :user (dissoc user :password)}] (if (and user (= (:password user) (:password rbody))) diff --git a/examples/sessions/src/backend/app/interceptors.clj b/examples/sessions/src/backend/app/interceptors.clj index 48bca700..77801613 100644 --- a/examples/sessions/src/backend/app/interceptors.clj +++ b/examples/sessions/src/backend/app/interceptors.clj @@ -1,9 +1,6 @@ (ns app.interceptors (:require - [xiana.session :refer [delete! fetch]]) - (:import - (java.util - UUID))) + [xiana.session :refer [delete! fetch]])) (def require-logged-in {:name ::require-logged-in @@ -32,13 +29,13 @@ query-params :query-params} :request :as state}] (try (let [session-backend (-> state :deps :session-backend) - session-id (UUID/fromString (or (some->> headers - :session-id) - (some->> cookies - :session-id - :value) - (some->> query-params - :SESSIONID))) + session-id (parse-uuid (or (some->> headers + :session-id) + (some->> cookies + :session-id + :value) + (some->> query-params + :SESSIONID))) session-data (fetch session-backend session-id)] (assoc state :session-data (assoc session-data :session-id session-id))) (catch Exception _ ; TODO: catch more specific exception or rethink that diff --git a/examples/sessions/test/integration_test.clj b/examples/sessions/test/integration_test.clj index 25ae4537..25018088 100644 --- a/examples/sessions/test/integration_test.clj +++ b/examples/sessions/test/integration_test.clj @@ -7,10 +7,7 @@ [next.jdbc :as jdbc] [xiana.commons :as commons] [xiana.config :as config] - [xiana.db :as db]) - (:import - (java.util - UUID))) + [xiana.db :as db])) (defn merge-connection [config] @@ -85,7 +82,7 @@ (is (= {"first-name" "Piotr", "id" 1, "email" "piotr@example.com", "last-name" "Developer"} user) "User has been logged in") - (is (true? (try (UUID/fromString body-session-id) + (is (true? (try (parse-uuid body-session-id) true (catch Exception _ false))) "and has UUID session id") @@ -132,7 +129,7 @@ (is (= {"first-name" "Piotr", "id" 1, "email" "piotr@example.com", "last-name" "Developer"} user) "User is logged in") - (is (true? (try (UUID/fromString session-id) + (is (true? (try (parse-uuid session-id) true (catch Exception _ false))) "and has UUID session id") diff --git a/examples/state-events/src/backend/state_events/interceptors/event_process.clj b/examples/state-events/src/backend/state_events/interceptors/event_process.clj index eede6485..1ccbc779 100644 --- a/examples/state-events/src/backend/state_events/interceptors/event_process.clj +++ b/examples/state-events/src/backend/state_events/interceptors/event_process.clj @@ -4,9 +4,7 @@ [tick.core :as t]) (:import (java.sql - Timestamp) - (java.util - UUID))) + Timestamp))) (defn- clean-pg [obj] @@ -36,7 +34,7 @@ creator (-> state :session-data :users/id) event {:payload p :resource (name (:resource params)) - :resource-id (UUID/fromString (:id params)) + :resource-id (parse-uuid (:id params)) :modified-at (Timestamp/from (t/now)) :action action :creator creator}] diff --git a/examples/state-events/test/integration/state_events/integration_test.clj b/examples/state-events/test/integration/state_events/integration_test.clj index 48c15f60..396bcde1 100644 --- a/examples/state-events/test/integration/state_events/integration_test.clj +++ b/examples/state-events/test/integration/state_events/integration_test.clj @@ -3,15 +3,12 @@ [clj-http.client :as client] [clojure.test :refer :all] [jsonista.core :as json] - [state-events-fixture :as fixture]) - (:import - (java.util - UUID))) + [state-events-fixture :as fixture])) (use-fixtures :once fixture/std-system-fixture) (deftest new-event - (let [resource-uuid (UUID/randomUUID) + (let [resource-uuid (random-uuid) response (client/request {:method :put :url "http://localhost:3333/person" @@ -23,7 +20,7 @@ (is (= 200 (:status response))))) (deftest modify-event - (let [resource-uuid (UUID/randomUUID) + (let [resource-uuid (random-uuid) create (client/request {:method :put :url "http://localhost:3333/person" @@ -53,7 +50,7 @@ (get-in modify [:body :data :events/payload]))))) (deftest cannot-create-already-existing-resource - (let [resource-uuid (UUID/randomUUID) + (let [resource-uuid (random-uuid) create (client/request {:method :put :url "http://localhost:3333/person" diff --git a/examples/state-events/test/unit/state_events/event_process_test.clj b/examples/state-events/test/unit/state_events/event_process_test.clj index 799f578a..2d5a0b5b 100644 --- a/examples/state-events/test/unit/state_events/event_process_test.clj +++ b/examples/state-events/test/unit/state_events/event_process_test.clj @@ -1,10 +1,7 @@ (ns unit.state-events.event-process-test (:require [clojure.test :refer :all] - [state-events.interceptors.event-process :as pr]) - (:import - (java.util - UUID))) + [state-events.interceptors.event-process :as pr])) (defn- <-db "Mimics database store and query" @@ -14,8 +11,8 @@ event))) (deftest event-interceptor-handles-one-event - (let [resource-uuid (UUID/fromString "68849768-fc9f-4602-814e-8b6cbeedd4b3") - user-id (UUID/fromString "54749a36-8305-4adb-a69c-d447ea19de45") + (let [resource-uuid (parse-uuid "68849768-fc9f-4602-814e-8b6cbeedd4b3") + user-id (parse-uuid "54749a36-8305-4adb-a69c-d447ea19de45") state {:request {:params {:id (str resource-uuid) :action :create :resource :persons} @@ -40,7 +37,7 @@ (deftest event-interceptor-aggregates-events (let [resource-uuid "68849768-fc9f-4602-814e-8b6cbeedd4b3" - user-id (UUID/fromString "54749a36-8305-4adb-a69c-d447ea19de45") + user-id (parse-uuid "54749a36-8305-4adb-a69c-d447ea19de45") event-requests [{:params {:id resource-uuid :action :create :resource :persons} @@ -96,7 +93,7 @@ (deftest event-interceptor-one-undo-events (let [resource-uuid "68849768-fc9f-4602-814e-8b6cbeedd4b3" - user-id (UUID/fromString "54749a36-8305-4adb-a69c-d447ea19de45") + user-id (parse-uuid "54749a36-8305-4adb-a69c-d447ea19de45") event-requests [{:params {:action :create :id resource-uuid :resource :persons} @@ -137,7 +134,7 @@ (deftest event-interceptor-two-undo-events (let [resource-uuid "68849768-fc9f-4602-814e-8b6cbeedd4b3" - user-id (UUID/fromString "54749a36-8305-4adb-a69c-d447ea19de45") + user-id (parse-uuid "54749a36-8305-4adb-a69c-d447ea19de45") event-requests [{:params {:action :create :id resource-uuid :resource :persons} @@ -187,7 +184,7 @@ (deftest event-interceptor-modify-after-undo (let [resource-uuid "68849768-fc9f-4602-814e-8b6cbeedd4b3" - user-id (UUID/fromString "54749a36-8305-4adb-a69c-d447ea19de45") + user-id (parse-uuid "54749a36-8305-4adb-a69c-d447ea19de45") event-requests [{:params {:action :create :id resource-uuid :resource :persons} @@ -235,7 +232,7 @@ (deftest event-interceptor-clean (let [resource-uuid "68849768-fc9f-4602-814e-8b6cbeedd4b3" - user-id (UUID/fromString "54749a36-8305-4adb-a69c-d447ea19de45") + user-id (parse-uuid "54749a36-8305-4adb-a69c-d447ea19de45") event-requests [{:params {:action :create :id resource-uuid :resource :persons} @@ -276,7 +273,7 @@ (deftest event-interceptor-clean-and-modify (let [resource-uuid "68849768-fc9f-4602-814e-8b6cbeedd4b3" - user-id (UUID/fromString "54749a36-8305-4adb-a69c-d447ea19de45") + user-id (parse-uuid "54749a36-8305-4adb-a69c-d447ea19de45") event-requests [{:params {:id resource-uuid :action :create :resource :persons} @@ -333,7 +330,7 @@ (deftest event-interceptor-one-undo-and-redo (let [resource-uuid "68849768-fc9f-4602-814e-8b6cbeedd4b3" - user-id (UUID/fromString "54749a36-8305-4adb-a69c-d447ea19de45") + user-id (parse-uuid "54749a36-8305-4adb-a69c-d447ea19de45") event-requests [{:params {:action :create :id resource-uuid :resource :persons} @@ -379,7 +376,7 @@ (deftest event-interceptor-clean-and-undo (let [resource-uuid "68849768-fc9f-4602-814e-8b6cbeedd4b3" - user-id (UUID/fromString "54749a36-8305-4adb-a69c-d447ea19de45") + user-id (parse-uuid "54749a36-8305-4adb-a69c-d447ea19de45") event-requests [{:params {:action :create :id resource-uuid :resource :persons} diff --git a/src/xiana/coercion.clj b/src/xiana/coercion.clj index bbd8a2dc..fc385629 100644 --- a/src/xiana/coercion.clj +++ b/src/xiana/coercion.clj @@ -48,7 +48,8 @@ :headers :body-params :query-params - :multipart-params])) + :multipart-params + :path-params])) cc (coercion/coerce! (get-in state [:request-data :match]))] (update-in state [:request :params] merge cc))) :error (fn [{exception :error :as state}] diff --git a/src/xiana/interceptor.clj b/src/xiana/interceptor.clj index b37c3664..54b6abd5 100644 --- a/src/xiana/interceptor.clj +++ b/src/xiana/interceptor.clj @@ -9,10 +9,7 @@ [ring.middleware.multipart-params :refer [multipart-params-request]] [ring.middleware.params :as middleware.params] [xiana.interceptor.muuntaja :as muuntaja] - [xiana.session :as session]) - (:import - (java.util - UUID))) + [xiana.session :as session])) (def log "Log interceptor. @@ -80,7 +77,7 @@ {:enter (fn [{request :request :as state}] (let [session-backend (-> state :deps :session-backend) - session-id (try (UUID/fromString + session-id (try (parse-uuid (get-in request [:headers :session-id])) (catch Exception _ nil)) session-data (when session-id @@ -91,7 +88,7 @@ (assoc state :session-data session-data) ;; else, associate a new session (assoc-in - (assoc-in state [:session-data :session-id] (UUID/randomUUID)) + (assoc-in state [:session-data :session-id] (random-uuid)) [:session-data :new-session] true)))) :leave (fn [state] diff --git a/src/xiana/session.clj b/src/xiana/session.clj index 74529a08..0a7a2545 100644 --- a/src/xiana/session.clj +++ b/src/xiana/session.clj @@ -3,10 +3,7 @@ (:require [honeysql.format :as sqlf] [next.jdbc.result-set :refer [as-kebab-maps]] - [xiana.db :as db]) - (:import - (java.util - UUID))) + [xiana.db :as db])) ;; define session protocol (defprotocol Session @@ -73,7 +70,7 @@ ;; add session key:element (add! [_ k v] - (let [k (or k (UUID/randomUUID))] + (let [k (or k (random-uuid))] (when v (first (map unpack (db/execute ds (insert-session k v))))))) ;; delete session key:element (delete! [_ k] (first (map unpack (db/execute ds (delete-session k))))) @@ -95,7 +92,7 @@ ;; add session key:element (add! [_ k v] - (let [k (or k (UUID/randomUUID))] + (let [k (or k (random-uuid))] (swap! m assoc k v))) ;; delete session key:element (delete! [_ k] (swap! m dissoc k)) @@ -113,7 +110,7 @@ :value) (some->> query-params :SESSIONID))] - (and (seq uuid) (UUID/fromString uuid)))) + (and (seq uuid) (parse-uuid uuid)))) (defn- fetch-session [state] @@ -148,8 +145,8 @@ (defn add-guest-user [state] (let [session-backend (-> state :deps :session-backend) - session-id (UUID/randomUUID) - user-id (UUID/randomUUID) + session-id (random-uuid) + user-id (random-uuid) session-data {:session-id session-id :users/role :guest :users/id user-id}] @@ -164,8 +161,8 @@ (try (fetch-session state) (catch Exception _ ; TODO: more specific exception, it might be better to return nil when session is missing (let [session-backend (-> state :deps :session-backend) - session-id (UUID/randomUUID) - user-id (UUID/randomUUID) + session-id (random-uuid) + user-id (random-uuid) session-data {:session-id session-id :users/role :guest :users/id user-id}] diff --git a/test/xiana/rbac/integration_test.clj b/test/xiana/rbac/integration_test.clj index fff40285..3cd74dd7 100644 --- a/test/xiana/rbac/integration_test.clj +++ b/test/xiana/rbac/integration_test.clj @@ -9,10 +9,7 @@ [xiana.interceptor :as interceptors] [xiana.interceptor.error :as error] [xiana.rbac :as rbac] - [xiana.session :as session]) - (:import - (java.util - UUID))) + [xiana.session :as session])) (defn restriction-fn [state] @@ -61,14 +58,14 @@ (def guest {:users/role :guest - :users/id (str (UUID/randomUUID))}) + :users/id (str (random-uuid))}) (def member {:users/role :member - :users/id (str (UUID/randomUUID))}) + :users/id (str (random-uuid))}) (deftest delete-request-by-member - (let [session-id (UUID/randomUUID) + (let [session-id (random-uuid) _ (session/add! backend session-id (assoc member :session-id session-id)) response (http/delete "http://localhost:3333/api/image" {:throw-exceptions false @@ -76,7 +73,7 @@ (is (= 200 (:status response))))) (deftest delete-request-by-guest - (let [session-id (UUID/randomUUID) + (let [session-id (random-uuid) _ (session/add! backend session-id (assoc guest :session-id session-id)) response (http/delete "http://localhost:3333/api/image" {:throw-exceptions false diff --git a/test/xiana/rbac/interceptor_test.clj b/test/xiana/rbac/interceptor_test.clj index 011e9d02..86880c28 100644 --- a/test/xiana/rbac/interceptor_test.clj +++ b/test/xiana/rbac/interceptor_test.clj @@ -4,10 +4,7 @@ [honeysql.helpers :as sql] [tiny-rbac.builder :as b] [xiana.rbac :refer [interceptor]] - [xiana.session :as session]) - (:import - (java.util - UUID))) + [xiana.session :as session])) (def role-set (-> (b/add-resource {} :image) @@ -22,19 +19,19 @@ (def guest {:users/role :guest - :users/id (str (UUID/randomUUID))}) + :users/id (str (random-uuid))}) (def member {:users/role :member - :users/id (str (UUID/randomUUID))}) + :users/id (str (random-uuid))}) (def mixed {:users/role :mixed - :users/id (str (UUID/randomUUID))}) + :users/id (str (random-uuid))}) (defn state [user permission] - (let [session-id (str (UUID/randomUUID)) + (let [session-id (str (random-uuid)) session-backend (:session-backend (session/init-backend {}))] (session/add! session-backend session-id user) (-> (assoc-in {} [:request-data :permission] permission) @@ -86,7 +83,7 @@ (deftest restrictions (let [user member - image-id (str (UUID/randomUUID))] + image-id (str (random-uuid))] (is (= {:delete [:*], :from [:images], :where [:and @@ -99,7 +96,7 @@ :query)) "Add filter if user has restricted to ':own'")) (let [user guest - image-id (str (UUID/randomUUID))] + image-id (str (random-uuid))] (is (thrown-with-msg? Exception #"Forbidden" (-> (state user :image/delete) ((:enter interceptor)) @@ -108,7 +105,7 @@ :response) "Returns 403: Forbidden if action is forbidden")) (let [user mixed - image-id (str (UUID/randomUUID))] + image-id (str (random-uuid))] (is (= {:delete [:*], :from [:images], :where [:= :id image-id]} diff --git a/test/xiana/session_test.clj b/test/xiana/session_test.clj index 4ad86a28..dca7fd0d 100644 --- a/test/xiana/session_test.clj +++ b/test/xiana/session_test.clj @@ -1,17 +1,14 @@ (ns xiana.session-test (:require [clojure.test :refer [deftest is]] - [xiana.session :as session]) - (:import - (java.util - UUID))) + [xiana.session :as session])) ;; initial session-instance instance (def session-instance (:session-backend (session/init-backend {}))) ;; test add and fetch reify implementations (deftest session-protocol-add!-fetch - (let [user-id (UUID/randomUUID)] + (let [user-id (random-uuid)] ;; add user id (session/add! session-instance :user-id {:id user-id}) ;; verify if user ids are equal @@ -29,8 +26,8 @@ ;; test erase reify implementation (deftest session-protocol-add!-erase! - (let [user-id (UUID/randomUUID) - session-id (UUID/randomUUID)] + (let [user-id (random-uuid) + session-id (random-uuid)] ;; add session instance values (session/add! session-instance :user-id {:id user-id}) (session/add! session-instance :session-id {:id session-id}) diff --git a/test/xiana/web_socket/integration_test.clj b/test/xiana/web_socket/integration_test.clj index 349a9e28..9da9cdc3 100644 --- a/test/xiana/web_socket/integration_test.clj +++ b/test/xiana/web_socket/integration_test.clj @@ -7,10 +7,7 @@ [xiana-fixture :as fixture] [xiana.interceptor :as interceptors] [xiana.rbac :as rbac] - [xiana.websockets :as ws]) - (:import - (java.util - UUID))) + [xiana.websockets :as ws])) (defn echo [{req :request :as state}] (assoc-in state [:response-data :channel] @@ -47,7 +44,7 @@ (deftest http-async (with-open [client (a-client/create-client)] (let [latch (promise) - session-id (str (UUID/randomUUID)) + session-id (str (random-uuid)) ws (a-client/websocket client "ws://localhost:3333/ws" :headers {:session-id session-id} :text (fn [_con mesg]