88
99import com .fasterxml .jackson .core .*;
1010import com .fasterxml .jackson .core .exc .StreamConstraintsException ;
11- import com . fasterxml . jackson . databind . ObjectMapper ;
11+
1212import com .fasterxml .jackson .dataformat .cbor .CBORFactory ;
1313import com .fasterxml .jackson .dataformat .cbor .CBORTestBase ;
14+ import com .fasterxml .jackson .dataformat .cbor .databind .CBORMapper ;
1415
1516import static org .junit .jupiter .api .Assertions .assertTrue ;
1617import static org .junit .jupiter .api .Assertions .fail ;
1718
1819public class LongDocumentCBORReadTest extends CBORTestBase
1920{
20- private final ObjectMapper MAPPER_VANILLA = cborMapper ();
21+ private final CBORMapper MAPPER_VANILLA = cborMapper ();
2122
22- private final ObjectMapper MAPPER_CONSTRAINED = cborMapper (
23+ private final CBORMapper MAPPER_CONSTRAINED = cborMapper (
2324 CBORFactory .builder ()
2425 // limit to 100kB doc reads
2526 .streamReadConstraints (StreamReadConstraints .builder ()
@@ -32,13 +33,20 @@ public void testLongDocumentConstraint() throws Exception
3233 {
3334 // Need a bit longer than minimum since checking is approximate, not exact
3435 byte [] doc = createBigDoc (60_000 );
35- // Must read from `InputStream` as validation is during "loadMore()":
36- try (JsonParser p = MAPPER_CONSTRAINED .createParser (new ByteArrayInputStream (doc ))) {
36+ _testLongDocumentConstraint (doc , true );
37+ // [dataformats-binary#649] fixed buffer too
38+ _testLongDocumentConstraint (doc , false );
39+ }
40+
41+ private void _testLongDocumentConstraint (byte [] doc , boolean stream ) throws Exception
42+ {
43+ try (JsonParser p = stream
44+ ? MAPPER_CONSTRAINED .createParser (new ByteArrayInputStream (doc ))
45+ : MAPPER_CONSTRAINED .createParser (doc , 0 , doc .length )) {
3746 while (p .nextToken () != null ) { }
3847 fail ("expected StreamConstraintsException" );
3948 } catch (StreamConstraintsException e ) {
4049 final String msg = e .getMessage ();
41-
4250 assertTrue (msg .contains ("Document length (" ));
4351 assertTrue (msg .contains ("exceeds the maximum allowed (50000" ));
4452 }
0 commit comments