Search in sources :

Example 71 with JsonMappingException

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"));
    }
}
Also used : JndiDataSourceFactory(org.apache.ibatis.datasource.jndi.JndiDataSourceFactory) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ATTest(org.jboss.eap.additional.testsuite.annotations.ATTest) Test(org.junit.Test)

Example 72 with JsonMappingException

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"));
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ATTest(org.jboss.eap.additional.testsuite.annotations.ATTest)

Example 73 with JsonMappingException

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();
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) HttpURLConnection(java.net.HttpURLConnection) ByteArrayInputStream(java.io.ByteArrayInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 74 with JsonMappingException

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) {
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Granularity(io.druid.java.util.common.granularity.Granularity) DurationGranularity(io.druid.java.util.common.granularity.DurationGranularity) PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 75 with JsonMappingException

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);
    }
}
Also used : CoordinatorDynamicConfig(io.druid.server.coordinator.CoordinatorDynamicConfig) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IAE(io.druid.java.util.common.IAE) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)185 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)93 IOException (java.io.IOException)80 JsonParseException (com.fasterxml.jackson.core.JsonParseException)57 Test (org.junit.Test)45 ATTest (org.jboss.eap.additional.testsuite.annotations.ATTest)33 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)24 ArrayList (java.util.ArrayList)16 Map (java.util.Map)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 File (java.io.File)15 HashMap (java.util.HashMap)15 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)13 InputStream (java.io.InputStream)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 List (java.util.List)8 Writer (org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer)7 Test (org.junit.jupiter.api.Test)6