1
1
package com .fasterxml .jackson .databind .interop ;
2
2
3
+ import com .fasterxml .jackson .annotation .JsonTypeInfo ;
3
4
import com .fasterxml .jackson .databind .*;
4
5
5
6
/**
@@ -13,11 +14,28 @@ static class Bean1599 {
13
14
public Object obj ;
14
15
}
15
16
16
- public void testIssue1599 () throws Exception
17
+ static class PolyWrapper {
18
+ @ JsonTypeInfo (use = JsonTypeInfo .Id .CLASS ,
19
+ include = JsonTypeInfo .As .WRAPPER_ARRAY )
20
+ public Object v ;
21
+ }
22
+
23
+ /*
24
+ /**********************************************************
25
+ /* Unit tests
26
+ /**********************************************************
27
+ */
28
+
29
+ private final ObjectMapper MAPPER = objectMapper ();
30
+
31
+ // // // Tests for [databind#1599]
32
+
33
+ public void testXalanTypes1599 () throws Exception
17
34
{
35
+ final String clsName = "com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl" ;
18
36
final String JSON = aposToQuotes (
19
37
"{'id': 124,\n "
20
- +" 'obj':[ 'com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl ',\n "
38
+ +" 'obj':[ '" + clsName + " ',\n "
21
39
+" {\n "
22
40
+" 'transletBytecodes' : [ 'AAIAZQ==' ],\n "
23
41
+" 'transletName' : 'a.b',\n "
@@ -32,9 +50,75 @@ public void testIssue1599() throws Exception
32
50
mapper .readValue (JSON , Bean1599 .class );
33
51
fail ("Should not pass" );
34
52
} catch (JsonMappingException e ) {
35
- verifyException (e , "Illegal type" );
36
- verifyException (e , "to deserialize" );
37
- verifyException (e , "prevented for security reasons" );
53
+ _verifySecurityException (e , clsName );
54
+ }
55
+ }
56
+
57
+ // // // Tests for [databind#1737]
58
+
59
+ public void testJDKTypes1737 () throws Exception
60
+ {
61
+ _testTypes1737 (java .util .logging .FileHandler .class );
62
+ _testTypes1737 (java .rmi .server .UnicastRemoteObject .class );
63
+ }
64
+
65
+ // 17-Aug-2017, tatu: Ideally would test handling of 3rd party types, too,
66
+ // but would require adding dependencies. This may be practical when
67
+ // checking done by module, but for now let's not do that for databind.
68
+
69
+ /*
70
+ public void testSpringTypes1737() throws Exception
71
+ {
72
+ _testTypes1737("org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor");
73
+ _testTypes1737("org.springframework.beans.factory.config.PropertyPathFactoryBean");
74
+ }
75
+
76
+ public void testC3P0Types1737() throws Exception
77
+ {
78
+ _testTypes1737("com.mchange.v2.c3p0.JndiRefForwardingDataSource");
79
+ _testTypes1737("com.mchange.v2.c3p0.WrapperConnectionPoolDataSource");
80
+ }
81
+ */
82
+
83
+ private void _testTypes1737 (Class <?> nasty ) throws Exception {
84
+ _testTypes1737 (nasty .getName ());
85
+ }
86
+
87
+ private void _testTypes1737 (String clsName ) throws Exception
88
+ {
89
+ // While usually exploited via default typing let's not require
90
+ // it here; mechanism still the same
91
+ String json = aposToQuotes (
92
+ "{'v':['" +clsName +"','/tmp/foobar.txt']}"
93
+ );
94
+ try {
95
+ MAPPER .readValue (json , PolyWrapper .class );
96
+ fail ("Should not pass" );
97
+ } catch (JsonMappingException e ) {
98
+ _verifySecurityException (e , clsName );
99
+ }
100
+ }
101
+
102
+ protected void _verifySecurityException (Throwable t , String clsName ) throws Exception
103
+ {
104
+ // 17-Aug-2017, tatu: Expected type more granular in 2.9 (over 2.8)
105
+ _verifyException (t , JsonMappingException .class ,
106
+ "Illegal type" ,
107
+ "to deserialize" ,
108
+ "prevented for security reasons" );
109
+ verifyException (t , clsName );
110
+ }
111
+
112
+ protected void _verifyException (Throwable t , Class <?> expExcType ,
113
+ String ... patterns ) throws Exception
114
+ {
115
+ Class <?> actExc = t .getClass ();
116
+ if (!expExcType .isAssignableFrom (actExc )) {
117
+ fail ("Expected Exception of type '" +expExcType .getName ()+"', got '"
118
+ +actExc .getName ()+"', message: " +t .getMessage ());
119
+ }
120
+ for (String pattern : patterns ) {
121
+ verifyException (t , pattern );
38
122
}
39
123
}
40
124
}
0 commit comments