@@ -55,22 +55,36 @@ private void assertSerialization(ObjectInputStream ois) throws ClassNotFoundExce
5555 assertEquals ("Expecting same data after deserializing" , original .toString (), copy .toString ());
5656 }
5757
58- /** Having to specify all the MoreComplexObject member classes like
59- * this is a bit painful - we might need a utility that analyzes the
60- * class members and accepts their classes. On the other hand this gives
61- * a precise view of what's accepted (assuming we trust java.lang.*).
58+ /** Trusting java.lang.* and the array variants of that means we have
59+ * to define a number of accept classes explicitly. Quite safe but
60+ * might become a bit verbose.
6261 */
6362 @ Test
64- public void specifyAllAccepts () throws IOException , ClassNotFoundException {
63+ public void trustJavaLang () throws IOException , ClassNotFoundException {
6564 assertSerialization (willClose (
6665 new ValidatingObjectInputStream (inputStream )
67- .accept (MoreComplexObject .class , ArrayList .class , Integer []. class , Random .class )
68- .accept ("java.lang.*" )
66+ .accept (MoreComplexObject .class , ArrayList .class , Random .class )
67+ .accept ("java.lang.*" , "[Ljava.lang.*" )
6968 ));
7069 }
7170
72- /** An alternative is to accept everything but reject specific classes.
73- * That's not as safe as it's hard to get an exhaustive blacklist.
71+ /** Trusting java.* is probably reasonable and avoids having to be too
72+ * detailed in the accepts.
73+ */
74+ @ Test
75+ public void trustJavaIncludingArrays () throws IOException , ClassNotFoundException {
76+ assertSerialization (willClose (
77+ new ValidatingObjectInputStream (inputStream )
78+ .accept (MoreComplexObject .class )
79+ .accept ("java.*" ,"[Ljava.*" )
80+ ));
81+ }
82+
83+ /** Here we accept everything but reject specific classes, using a pure
84+ * blacklist mode.
85+ *
86+ * That's not as safe as it's hard to get an exhaustive blacklist, but
87+ * might be ok in controlled environments.
7488 */
7589 @ Test
7690 public void useBlacklist () throws IOException , ClassNotFoundException {
0 commit comments