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