@@ -26,6 +26,10 @@ public class StreamReadConstraintsUtilTest {
26
26
private ListAppender listAppender ;
27
27
private Logger observedLogger ;
28
28
29
+ private static final int DEFAULT_MAX_STRING_LENGTH = 200_000_000 ;
30
+ private static final int DEFAULT_MAX_NUMBER_LENGTH = 10_000 ;
31
+ private static final int DEFAULT_MAX_NESTING_DEPTH = 1_000 ;
32
+
29
33
@ Before
30
34
public void setUpLoggingListAppender () {
31
35
int i = 1 +16 ;
@@ -51,8 +55,8 @@ public void configuresMaxStringLength() {
51
55
assertThat (configuredConstraints ).as ("inherited defaults" )
52
56
.returns (defaults .getMaxDocumentLength (), from (StreamReadConstraints ::getMaxDocumentLength ))
53
57
.returns (defaults .getMaxNameLength (), from (StreamReadConstraints ::getMaxNameLength ))
54
- .returns (defaults . getMaxNestingDepth () , from (StreamReadConstraints ::getMaxNestingDepth ))
55
- .returns (defaults . getMaxNumberLength () , from (StreamReadConstraints ::getMaxNumberLength ));
58
+ .returns (DEFAULT_MAX_NESTING_DEPTH , from (StreamReadConstraints ::getMaxNestingDepth ))
59
+ .returns (DEFAULT_MAX_NUMBER_LENGTH , from (StreamReadConstraints ::getMaxNumberLength ));
56
60
57
61
assertThatThrownBy (configuredUtil ::validateIsGlobalDefault ).isInstanceOf (IllegalStateException .class ).hasMessageContaining (MAX_STRING_LENGTH .propertyName );
58
62
@@ -94,8 +98,8 @@ public void configuresMaxNumberLength() {
94
98
assertThat (configuredConstraints ).as ("inherited defaults" )
95
99
.returns (defaults .getMaxDocumentLength (), from (StreamReadConstraints ::getMaxDocumentLength ))
96
100
.returns (defaults .getMaxNameLength (), from (StreamReadConstraints ::getMaxNameLength ))
97
- .returns (defaults . getMaxNestingDepth () , from (StreamReadConstraints ::getMaxNestingDepth ))
98
- .returns (defaults . getMaxStringLength () , from (StreamReadConstraints ::getMaxStringLength ));
101
+ .returns (DEFAULT_MAX_NESTING_DEPTH , from (StreamReadConstraints ::getMaxNestingDepth ))
102
+ .returns (DEFAULT_MAX_STRING_LENGTH , from (StreamReadConstraints ::getMaxStringLength ));
99
103
100
104
assertThatThrownBy (configuredUtil ::validateIsGlobalDefault ).isInstanceOf (IllegalStateException .class ).hasMessageContaining (MAX_NUMBER_LENGTH .propertyName );
101
105
@@ -137,8 +141,8 @@ public void configuresMaxNestingDepth() {
137
141
assertThat (configuredConstraints ).as ("inherited defaults" )
138
142
.returns (defaults .getMaxDocumentLength (), from (StreamReadConstraints ::getMaxDocumentLength ))
139
143
.returns (defaults .getMaxNameLength (), from (StreamReadConstraints ::getMaxNameLength ))
140
- .returns (defaults . getMaxStringLength () , from (StreamReadConstraints ::getMaxStringLength ))
141
- .returns (defaults . getMaxNumberLength () , from (StreamReadConstraints ::getMaxNumberLength ));
144
+ .returns (DEFAULT_MAX_STRING_LENGTH , from (StreamReadConstraints ::getMaxStringLength ))
145
+ .returns (DEFAULT_MAX_NUMBER_LENGTH , from (StreamReadConstraints ::getMaxNumberLength ));
142
146
143
147
assertThatThrownBy (configuredUtil ::validateIsGlobalDefault ).isInstanceOf (IllegalStateException .class ).hasMessageContaining (MAX_NESTING_DEPTH .propertyName );
144
148
@@ -193,6 +197,31 @@ public void validatesApplication() {
193
197
assertLogObserved (Level .WARN , "override `" + PROP_PREFIX + "unsupported-option1` is unknown and has been ignored" );
194
198
}
195
199
200
+ @ Test
201
+ public void usesJacksonDefaultsWhenNoConfig () {
202
+ StreamReadConstraintsUtil util = new StreamReadConstraintsUtil (new Properties (), this .observedLogger );
203
+ StreamReadConstraints constraints = util .get ();
204
+
205
+ assertThat (constraints )
206
+ .returns (DEFAULT_MAX_STRING_LENGTH , from (StreamReadConstraints ::getMaxStringLength ))
207
+ .returns (DEFAULT_MAX_NUMBER_LENGTH , from (StreamReadConstraints ::getMaxNumberLength ))
208
+ .returns (DEFAULT_MAX_NESTING_DEPTH , from (StreamReadConstraints ::getMaxNestingDepth ));
209
+ }
210
+
211
+ @ Test
212
+ public void configOverridesDefault () {
213
+ Properties props = new Properties ();
214
+ props .setProperty ("logstash.jackson.stream-read-constraints.max-string-length" , "100" );
215
+
216
+ StreamReadConstraintsUtil util = new StreamReadConstraintsUtil (props , this .observedLogger );
217
+ StreamReadConstraints constraints = util .get ();
218
+
219
+ assertThat (constraints )
220
+ .returns (100 , from (StreamReadConstraints ::getMaxStringLength ))
221
+ .returns (DEFAULT_MAX_NUMBER_LENGTH , from (StreamReadConstraints ::getMaxNumberLength ))
222
+ .returns (DEFAULT_MAX_NESTING_DEPTH , from (StreamReadConstraints ::getMaxNestingDepth ));
223
+ }
224
+
196
225
private void assertLogObserved (final Level level , final String ... messageFragments ) {
197
226
List <LogEvent > logEvents = listAppender .getEvents ();
198
227
assertThat (logEvents )
0 commit comments