use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project eap-additional-testsuite by jboss-set.
the class JaxbProviderDeserializationSecurityCheck6TestCase method testMyBatisJndiDataSourceFactory.
@Test
public void testMyBatisJndiDataSourceFactory() throws Exception {
String result = performCall("rest/jaxb/datasource");
try {
JndiDataSourceFactory jaxbModel = new ObjectMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false).readValue(result, JndiDataSourceFactory.class);
Assert.fail("Should prevente json deserialization because of security reasons.");
} catch (JsonMappingException e) {
Assert.assertTrue("Should prevente json deserialization because of security reasons.", e.getMessage().contains("Illegal type"));
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project eap-additional-testsuite by jboss-set.
the class SecurityDeserializationTestCase method testSecuirtyDatabind9.
@ATTest({ "modules/testcases/jdkAll/Wildfly/security/src/main/java#17.0.0.Final", "modules/testcases/jdkAll/Eap72x-Proposed/security/src/main/java#7.2.4", "modules/testcases/jdkAll/Eap72x/security/src/main/java#7.2.4", "modules/testcases/jdkAll/Eap7/security/src/main/java#7.3.0.CD17" })
public void testSecuirtyDatabind9() throws Exception {
final String JSON = aposToQuotes("{'v':['com.mysql.cj.jdbc.admin.MiniAdmin']}");
ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTyping();
try {
PolyWrapper sc = mapper.readValue(JSON, PolyWrapper.class);
fail("Should not be able to deserialize because of security prevention.");
} catch (JsonMappingException e) {
assertTrue("Fail because of security issues...", e.getMessage().contains("prevented for security reasons"));
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project qpid-broker-j by apache.
the class CompressedResponsesTest method doCompressionTest.
private void doCompressionTest(final boolean allowCompression, final boolean acceptCompressed) throws Exception {
final boolean expectCompression = allowCompression && acceptCompressed;
getHelper().submitRequest("plugin/httpManagement", "POST", Collections.singletonMap("compressResponses", expectCompression), SC_OK);
HttpURLConnection conn = getHelper().openManagementConnection("/service/metadata", "GET");
try {
if (acceptCompressed) {
conn.setRequestProperty("Accept-Encoding", "gzip");
}
conn.connect();
String contentEncoding = conn.getHeaderField("Content-Encoding");
if (expectCompression) {
assertEquals("gzip", contentEncoding);
} else {
if (contentEncoding != null) {
assertEquals("identity", contentEncoding);
}
}
byte[] bytes;
try (ByteArrayOutputStream contentBuffer = new ByteArrayOutputStream()) {
ByteStreams.copy(conn.getInputStream(), contentBuffer);
bytes = contentBuffer.toByteArray();
}
try (InputStream jsonStream = expectCompression ? new GZIPInputStream(new ByteArrayInputStream(bytes)) : new ByteArrayInputStream(bytes)) {
ObjectMapper mapper = new ObjectMapper();
try {
mapper.readValue(jsonStream, LinkedHashMap.class);
} catch (JsonParseException | JsonMappingException e) {
fail("Message was not in correct format");
}
}
} finally {
conn.disconnect();
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project druid by druid-io.
the class QueryGranularityTest method testSerializePeriod.
@Test
public void testSerializePeriod() throws Exception {
ObjectMapper mapper = new DefaultObjectMapper();
String json = "{ \"type\": \"period\", \"period\": \"P1D\" }";
Granularity gran = mapper.readValue(json, Granularity.class);
Assert.assertEquals(new PeriodGranularity(new Period("P1D"), null, null), gran);
json = "{ \"type\": \"period\", \"period\": \"P1D\"," + "\"timeZone\": \"America/Los_Angeles\", \"origin\": \"1970-01-01T00:00:00Z\"}";
gran = mapper.readValue(json, Granularity.class);
Assert.assertEquals(new PeriodGranularity(new Period("P1D"), new DateTime(0L), DateTimeZone.forID("America/Los_Angeles")), gran);
PeriodGranularity expected = new PeriodGranularity(new Period("P1D"), new DateTime("2012-01-01"), DateTimeZone.forID("America/Los_Angeles"));
String jsonOut = mapper.writeValueAsString(expected);
Assert.assertEquals(expected, mapper.readValue(jsonOut, Granularity.class));
String illegalJson = "{ \"type\": \"period\", \"period\": \"P0D\" }";
try {
mapper.readValue(illegalJson, Granularity.class);
Assert.fail();
} catch (JsonMappingException e) {
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException in project druid by druid-io.
the class CoordinatorDynamicConfigTest method testSerdeWithKillAllDataSources.
@Test
public void testSerdeWithKillAllDataSources() throws Exception {
String jsonStr = "{\n" + " \"millisToWaitBeforeDeleting\": 1,\n" + " \"mergeBytesLimit\": 1,\n" + " \"mergeSegmentsLimit\" : 1,\n" + " \"maxSegmentsToMove\": 1,\n" + " \"replicantLifetime\": 1,\n" + " \"replicationThrottleLimit\": 1,\n" + " \"balancerComputeThreads\": 2, \n" + " \"emitBalancingStats\": true,\n" + " \"killAllDataSources\": true\n" + "}\n";
ObjectMapper mapper = TestHelper.getObjectMapper();
CoordinatorDynamicConfig actual = mapper.readValue(mapper.writeValueAsString(mapper.readValue(jsonStr, CoordinatorDynamicConfig.class)), CoordinatorDynamicConfig.class);
Assert.assertEquals(new CoordinatorDynamicConfig(1, 1, 1, 1, 1, 1, 2, true, ImmutableSet.of(), true), actual);
//ensure whitelist is empty when killAllDataSources is true
try {
jsonStr = "{\n" + " \"killDataSourceWhitelist\": [\"test1\",\"test2\"],\n" + " \"killAllDataSources\": true\n" + "}\n";
mapper.readValue(jsonStr, CoordinatorDynamicConfig.class);
Assert.fail("deserialization should fail.");
} catch (JsonMappingException e) {
Assert.assertTrue(e.getCause() instanceof IAE);
}
}
Aggregations