|
12 | 12 | (ns clojure.test-clojure.serialization |
13 | 13 | (:use clojure.test) |
14 | 14 | (:import (System.IO MemoryStream) ;;;(java.io ObjectOutputStream ObjectInputStream |
15 | | - (System.Runtime.Serialization.Formatters.Binary BinaryFormatter))) ;;; ByteArrayOutputStream ByteArrayInputStream))) |
| 15 | + #_(System.Runtime.Serialization.Formatters.Binary BinaryFormatter))) ;;; ByteArrayOutputStream ByteArrayInputStream))) -- defer import until after load |
| 16 | + |
| 17 | +(compile-when (>= (:major clojure-version) 9) |
| 18 | + |
| 19 | +(assembly-load-from "System.Runtime.Serialization.Formatters.dll") |
| 20 | + |
| 21 | +) |
| 22 | + |
| 23 | +(import '(System.Runtime.Serialization.Formatters.Binary BinaryFormatter)) |
16 | 24 |
|
17 | 25 | (defn- serialize |
18 | 26 | "Serializes a single object, returning a byte array." |
|
48 | 56 | (= (hash v) (hash rt)) |
49 | 57 | (= (.GetHashCode v) (.GetHashCode rt))))) ;;; .hashCode .hashCode |
50 | 58 |
|
51 | | -#_(deftest sequable-serialization |
| 59 | +(deftest sequable-serialization |
52 | 60 | (are [val] (roundtrip val) |
53 | 61 | ; lists and related |
54 | 62 | ;;; (list) <--- We cannot handle seq of this, which is nil. Cannot serialize nil. |
|
123 | 131 | (nth r 35) |
124 | 132 | r))) |
125 | 133 |
|
126 | | -#_(deftest misc-serialization |
| 134 | +(deftest misc-serialization |
127 | 135 | (are [v] (= v (-> v serialize deserialize)) |
128 | 136 | 25/3 |
129 | 137 | :keyword |
130 | 138 | ::namespaced-keyword |
131 | 139 | 'symbol)) |
132 | 140 |
|
133 | | -#_(deftest tostringed-bytes |
| 141 | +(deftest tostringed-bytes |
134 | 142 | (let [rt #(-> % serialize seq) |
135 | 143 | s1 (rt 'sym123) |
136 | 144 | k1 (rt :kw123) |
|
141 | 149 | (is (= s1 s2)) |
142 | 150 | (is (= k1 k2)))) |
143 | 151 |
|
144 | | -#_(deftest interned-serializations |
| 152 | +(deftest interned-serializations |
145 | 153 | (are [v] (identical? v (-> v serialize deserialize)) |
146 | 154 | clojure.lang.RT/DefaultComparerInstance ;;; clojure.lang.RT/DEFAULT_COMPARATOR |
147 | 155 |
|
|
152 | 160 | ; vars get serialized back into the same var in the present runtime |
153 | 161 | #'clojure.core/conj)) |
154 | 162 |
|
155 | | - #_(deftest new-var-unbound-on-read |
| 163 | + (deftest new-var-unbound-on-read |
156 | 164 | (let [v (intern 'user 'foobarbaz 10) |
157 | 165 | sv (serialize v)] |
158 | 166 | (ns-unmap 'user 'foobarbaz) ;; unmap #'user.V |
|
170 | 178 | ;;; (fn [] capture) <--- TODO: unable to find assembly eval |
171 | 179 | ))) ;;; #(do capture)))) <--- TODO: unable to find assembly eval |
172 | 180 |
|
173 | | -#_(deftest check-unserializable-objects |
| 181 | +(deftest check-unserializable-objects |
174 | 182 | (are [t] (thrown? System.Runtime.Serialization.SerializationException (serialize t)) ;;; java.io.NotSerializableException |
175 | 183 | ;; transients |
176 | 184 | (transient []) |
|
187 | 195 | (iterator-seq (.GetEnumerator (range 50))))) ;;; (.iterator (range 50))))) |
188 | 196 |
|
189 | 197 | ;; necessary for CVE-2024-22871 |
190 | | -#_(deftest CLJ-2839 |
| 198 | +(deftest CLJ-2839 |
191 | 199 | (are [e] (thrown? Exception (.GetHashCode ^Object (-> e serialize deserialize))) ;;; .hashCode |
192 | 200 | (repeat 1) |
193 | 201 | (iterate identity nil) |
|
0 commit comments