diff --git a/src/monger/util.clj b/src/monger/util.clj index 9749a94..1588353 100644 --- a/src/monger/util.clj +++ b/src/monger/util.clj @@ -8,12 +8,17 @@ ;; You must not remove this notice, or any other, from this software. (ns monger.util - (:import (java.security SecureRandom) (java.math.BigInteger))) + (:import (java.security SecureRandom) (java.math BigInteger))) ;; ;; API ;; +(defn ^String random-uuid + "Generates a secure random UUID string" + [] + (.toString (java.util.UUID/randomUUID))) + (defn ^String random-str "Generates a secure random string" [^long n, ^long num-base] diff --git a/test/monger/test/collection.clj b/test/monger/test/collection.clj index b296ff0..2f736ec 100644 --- a/test/monger/test/collection.clj +++ b/test/monger/test/collection.clj @@ -103,14 +103,14 @@ (deftest find-full-document-by-id-when-document-does-not-exist (let [collection "libraries" - doc-id (monger.util/random-str 140 16)] + doc-id (monger.util/random-uuid)] (monger.collection/remove collection) (is (nil? (monger.collection/find-by-id collection doc-id))))) (deftest find-full-document-by-id-when-document-exists (let [collection "libraries" - doc-id (monger.util/random-str 140 16) + doc-id (monger.util/random-uuid) doc { :data-store "MongoDB", :language "Clojure", :_id doc-id }] (monger.collection/remove collection) (monger.collection/insert collection doc) @@ -118,7 +118,7 @@ (deftest find-partial-document-by-id-when-document-exists (let [collection "libraries" - doc-id (monger.util/random-str 140 16) + doc-id (monger.util/random-uuid) doc { :data-store "MongoDB", :language "Clojure", :_id doc-id }] (monger.collection/remove collection) (monger.collection/insert collection doc)