Skip to content

Commit

Permalink
Fix unit tests wrt new max-nesting-depth limit
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 2, 2024
1 parent a0d679f commit c7016e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

public class DeepJsonParsingTest extends BaseMapTest
{
private final static int TOO_DEEP_NESTING = 2_000;
private final static int DEFAULT_MAX_DEPTH = StreamReadConstraints.DEFAULT_MAX_DEPTH;
private final static int TOO_DEEP_NESTING = DEFAULT_MAX_DEPTH + 1;

private final JsonFactory unconstrainedFactory = JsonFactory.builder()
.streamReadConstraints(StreamReadConstraints.builder().maxNestingDepth(Integer.MAX_VALUE).build())
Expand All @@ -31,7 +32,8 @@ public void testParseWithArrayWithDefaultConfig() throws Exception

} catch (StreamConstraintsException e) {
assertThat(e.getMessage())
.startsWith("Document nesting depth (1001) exceeds the maximum allowed (1000");
.startsWith("Document nesting depth ("+(DEFAULT_MAX_DEPTH+1)
+") exceeds the maximum allowed ("+DEFAULT_MAX_DEPTH);
}
}

Expand All @@ -43,7 +45,8 @@ public void testParseWithObjectWithDefaultConfig() throws Exception
fail("expected StreamConstraintsException");
} catch (StreamConstraintsException e) {
assertThat(e.getMessage())
.startsWith("Document nesting depth (1001) exceeds the maximum allowed (1000");
.startsWith("Document nesting depth ("+(DEFAULT_MAX_DEPTH+1)
+") exceeds the maximum allowed ("+DEFAULT_MAX_DEPTH);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

public class DeepJsonTreeTraversingTest extends BaseMapTest
{
private final static int TOO_DEEP_NESTING = 2_000;
private final static int DEFAULT_MAX_DEPTH = StreamReadConstraints.DEFAULT_MAX_DEPTH;
private final static int TOO_DEEP_NESTING = DEFAULT_MAX_DEPTH + 1;

private final JsonFactory unconstrainedFactory = JsonFactory.builder()
.streamReadConstraints(StreamReadConstraints.builder().maxNestingDepth(Integer.MAX_VALUE).build())
Expand All @@ -25,7 +26,8 @@ public void testTreeWithArrayWithDefaultConfig() throws Exception
defaultMapper.readTree(doc);
} catch (StreamConstraintsException e) {
assertThat(e.getMessage())
.startsWith("Document nesting depth (1001) exceeds the maximum allowed (1000");
.startsWith("Document nesting depth ("+(DEFAULT_MAX_DEPTH+1)
+") exceeds the maximum allowed ("+DEFAULT_MAX_DEPTH);
}
}

Expand All @@ -36,7 +38,8 @@ public void testTreeWithObjectWithDefaultConfig() throws Exception
defaultMapper.readTree(doc);
} catch (StreamConstraintsException e) {
assertThat(e.getMessage())
.startsWith("Document nesting depth (1001) exceeds the maximum allowed (1000");
.startsWith("Document nesting depth ("+(DEFAULT_MAX_DEPTH+1)
+") exceeds the maximum allowed ("+DEFAULT_MAX_DEPTH);
}
}

Expand All @@ -53,8 +56,8 @@ public void testTreeWithObjectWithUnconstrainedConfig() throws Exception
{
final String doc = "{"+_nestedDoc(TOO_DEEP_NESTING, "\"x\":{", "} ") + "}";
JsonNode tree = unconstrainedMapper.readTree(doc);
try (JsonParser jp = tree.traverse(ObjectReadContext.empty())) {
while (jp.nextToken() != null) { }
try (JsonParser p = tree.traverse(ObjectReadContext.empty())) {
while (p.nextToken() != null) { }
}
}

Expand Down

0 comments on commit c7016e7

Please sign in to comment.