|
5 | 5 | import static org.mockito.Mockito.mock; |
6 | 6 | import static org.mockito.Mockito.when; |
7 | 7 |
|
| 8 | +import com.fasterxml.jackson.databind.ObjectMapper; |
8 | 9 | import com.google.common.collect.ImmutableSet; |
9 | 10 | import com.hubspot.jinjava.JinjavaConfig; |
10 | 11 | import com.hubspot.jinjava.el.JinjavaELContext; |
11 | 12 | import com.hubspot.jinjava.interpret.AutoCloseableSupplier; |
12 | 13 | import com.hubspot.jinjava.interpret.JinjavaInterpreter; |
| 14 | +import java.util.List; |
13 | 15 | import javax.el.ELContext; |
14 | 16 | import javax.el.MethodNotFoundException; |
15 | 17 | import javax.el.PropertyNotFoundException; |
@@ -186,4 +188,60 @@ public void itDoesNotAllowAccessingPropertiesOfInterpreter() { |
186 | 188 | .isNull(); |
187 | 189 | } |
188 | 190 | } |
| 191 | + |
| 192 | + @Test |
| 193 | + public void itDoesNotGettingFromObjectMapper() { |
| 194 | + try ( |
| 195 | + AutoCloseableSupplier.AutoCloseableImpl<JinjavaInterpreter> c = JinjavaInterpreter |
| 196 | + .closeablePushCurrent(interpreter) |
| 197 | + .get() |
| 198 | + ) { |
| 199 | + assertThat( |
| 200 | + jinjavaBeanELResolver.getValue(elContext, new ObjectMapper(), "dateFormat") |
| 201 | + ) |
| 202 | + .isNull(); |
| 203 | + } |
| 204 | + } |
| 205 | + |
| 206 | + @Test |
| 207 | + public void itDoesNotAllowInvokingFromObjectMapper() throws NoSuchMethodException { |
| 208 | + try ( |
| 209 | + AutoCloseableSupplier.AutoCloseableImpl<JinjavaInterpreter> c = JinjavaInterpreter |
| 210 | + .closeablePushCurrent(interpreter) |
| 211 | + .get() |
| 212 | + ) { |
| 213 | + ObjectMapper objectMapper = new ObjectMapper(); |
| 214 | + assertThatThrownBy(() -> |
| 215 | + jinjavaBeanELResolver.invoke( |
| 216 | + elContext, |
| 217 | + objectMapper, |
| 218 | + "getDateFormat", |
| 219 | + new Class[] {}, |
| 220 | + new Object[] {} |
| 221 | + ) |
| 222 | + ) |
| 223 | + .isInstanceOf(MethodNotFoundException.class); |
| 224 | + } |
| 225 | + } |
| 226 | + |
| 227 | + @Test |
| 228 | + public void itDoesNotAllowInvokingFromMethod() throws NoSuchMethodException { |
| 229 | + try ( |
| 230 | + AutoCloseableSupplier.AutoCloseableImpl<JinjavaInterpreter> c = JinjavaInterpreter |
| 231 | + .closeablePushCurrent(interpreter) |
| 232 | + .get() |
| 233 | + ) { |
| 234 | + List<String> list = List.of("foo"); |
| 235 | + assertThatThrownBy(() -> |
| 236 | + jinjavaBeanELResolver.invoke( |
| 237 | + elContext, |
| 238 | + list.getClass().getMethod("get", int.class), |
| 239 | + "invoke", |
| 240 | + new Class[] { Object.class, Object[].class }, |
| 241 | + new Object[] { list, 0 } |
| 242 | + ) |
| 243 | + ) |
| 244 | + .isInstanceOf(MethodNotFoundException.class); |
| 245 | + } |
| 246 | + } |
189 | 247 | } |
0 commit comments