Skip to content

Commit

Permalink
Serializable: refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Sep 10, 2020
1 parent 057e2f1 commit 8244f57
Showing 1 changed file with 24 additions and 47 deletions.
71 changes: 24 additions & 47 deletions test/taoensso/nippy/tests/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -248,65 +248,42 @@

;;;; Serializable

(deftest _serializable

(is
(thrown? Exception
(nippy/freeze (java.util.concurrent.Semaphore. 1)
{:serializable-whitelist #{}}))
(def ^:private sem (java.util.concurrent.Semaphore. 1))
(defn- sem? [x] (instance? java.util.concurrent.Semaphore x))

"Can't freeze Serializable object unless approved by whitelist")

(is
(:nippy/unthawable
(deftest _serializable
(is (= nippy/*serializable-whitelist* #{"base.1" "base.2" "add.1" "add.2"})
"JVM properties override initial serializable-whitelist value")

(let [ba (nippy/freeze (java.util.concurrent.Semaphore. 1)
{:serializable-whitelist #{"java.util.concurrent.Semaphore"}})]
(is (thrown? Exception (nippy/freeze sem {:serializable-whitelist #{}}))
"Can't freeze Serializable objects unless approved by whitelist")

(nippy/thaw ba {:serializable-whitelist #{}})))
(is (sem?
(nippy/thaw
(nippy/freeze sem {:serializable-whitelist #{"java.util.concurrent.Semaphore"}})
{:serializable-whitelist #{"java.util.concurrent.Semaphore"}}))

"Can't thaw Serializable object unless approved by whitelist")
"Can freeze and thaw Serializable objects if approved by whitelist")

(is
(instance? java.util.concurrent.Semaphore
(nippy/thaw
(nippy/freeze (java.util.concurrent.Semaphore. 1)
{:serializable-whitelist #{"java.util.concurrent.Semaphore"}})
{:serializable-whitelist #{"java.util.concurrent.Semaphore"}}))
(is (sem?
(nippy/thaw
(nippy/freeze sem {:serializable-whitelist #{"java.util.concurrent.*"}})
{:serializable-whitelist #{"java.util.concurrent.*"}}))

"Can freeze and thaw Serializable object if approved by whitelist")
"Strings in whitelist sets may contain \"*\" wildcards")

(let [sem (java.util.concurrent.Semaphore. 1)
ba (nippy/freeze sem #_{:serializable-whitelist "*"})
(let [ba (nippy/freeze sem #_{:serializable-whitelist "*"})
thawed (nippy/thaw ba {:serializable-whitelist #{}})]

(is
(= :quarantined (get-in thawed [:nippy/unthawable :cause]))
(is (= :quarantined (get-in thawed [:nippy/unthawable :cause]))
"Serializable objects will be quarantined when approved for freezing but not thawing.")

(is
(instance? java.util.concurrent.Semaphore
(nippy/read-quarantined-serializable-object-unsafe! thawed))
"Quarantined Serializable objects may still be manually force-read.")

(is
(instance? java.util.concurrent.Semaphore
(nippy/read-quarantined-serializable-object-unsafe!
(nippy/thaw (nippy/freeze thawed))))
"Quarantined Serializable objects are themselves safely transportable."))

(is
(instance? java.util.concurrent.Semaphore
(nippy/thaw
(nippy/freeze (java.util.concurrent.Semaphore. 1)
{:serializable-whitelist #{"java.util.concurrent.*"}})
{:serializable-whitelist #{"java.util.concurrent.*"}}))

"Strings in whitelist sets may contain \"*\" wildcards")

(is (= nippy/*serializable-whitelist* #{"base.1" "base.2" "add.1" "add.2"})
"JVM properties override initial serializable-whitelist value"))
(is (sem? (nippy/read-quarantined-serializable-object-unsafe! thawed))
"Quarantined Serializable objects can still be manually force-read.")

(is (sem? (nippy/read-quarantined-serializable-object-unsafe!
(nippy/thaw (nippy/freeze thawed))))
"Quarantined Serializable objects are themselves safely transportable.")) )

;;;; Metadata

Expand Down

0 comments on commit 8244f57

Please sign in to comment.