|
9 | 9 | import com.hubspot.jinjava.JinjavaConfig; |
10 | 10 | import com.hubspot.jinjava.LegacyOverrides; |
11 | 11 | import com.hubspot.jinjava.interpret.JinjavaInterpreter; |
| 12 | +import com.hubspot.jinjava.interpret.OutputTooBigException; |
12 | 13 | import com.hubspot.jinjava.objects.collections.SizeLimitingPyMap; |
13 | 14 | import java.util.AbstractMap; |
14 | 15 | import java.util.ArrayList; |
15 | 16 | import java.util.HashMap; |
16 | 17 | import java.util.List; |
17 | 18 | import java.util.Map; |
| 19 | +import org.apache.commons.lang3.RandomStringUtils; |
18 | 20 | import org.junit.Test; |
19 | 21 |
|
20 | 22 | public class PyishObjectMapperTest { |
@@ -87,6 +89,25 @@ public void itLimitsDepth() { |
87 | 89 | .as("The string to be serialized is larger than the max output size") |
88 | 90 | .isInstanceOf(JsonMappingException.class) |
89 | 91 | .hasMessageContaining("Max length of 10000 chars reached"); |
| 92 | + |
| 93 | + assertThatThrownBy(() -> PyishObjectMapper.getAsPyishString(original)) |
| 94 | + .isInstanceOf(OutputTooBigException.class); |
| 95 | + } finally { |
| 96 | + JinjavaInterpreter.popCurrent(); |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + @Test |
| 101 | + public void itLimitsOutputSize() { |
| 102 | + String input = RandomStringUtils.random(10002); |
| 103 | + try { |
| 104 | + Jinjava jinjava = new Jinjava( |
| 105 | + JinjavaConfig.newBuilder().withMaxOutputSize(10000).build() |
| 106 | + ); |
| 107 | + JinjavaInterpreter.pushCurrent(jinjava.newInterpreter()); |
| 108 | + assertThatThrownBy(() -> PyishObjectMapper.getAsPyishString(input)) |
| 109 | + .isInstanceOf(OutputTooBigException.class) |
| 110 | + .hasMessageContaining("over limit of 10000 bytes"); |
90 | 111 | } finally { |
91 | 112 | JinjavaInterpreter.popCurrent(); |
92 | 113 | } |
|
0 commit comments