Search in sources :

Example 6 with TestDeserialized

use of example.serialization.TestDeserialized in project hazelcast by hazelcast.

the class ClientDeserializationProtectionTest method testNoDeserializationFilter.

/**
 * <pre>
 * When: Deserialization filtering is not explicitly enabled and object is read from client.
 * Then: Untrusted deserialization is possible.
 * </pre>
 */
@Test
public void testNoDeserializationFilter() {
    Config config = new Config();
    HazelcastInstance member = hazelcastFactory.newInstances(config, 1)[0];
    ClientConfig clientConfig = new ClientConfig();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    member.getMap("test").put("key", new TestDeserialized());
    assertNotNull(client.getMap("test").get("key"));
    assertTrue(TestDeserialized.isDeserialized);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestDeserialized(example.serialization.TestDeserialized) Config(com.hazelcast.config.Config) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with TestDeserialized

use of example.serialization.TestDeserialized in project hazelcast by hazelcast.

the class ClientDeserializationProtectionTest method testDefaultDeserializationFilter_readOnClient.

/**
 * <pre>
 * When: An untrusted serialized object is stored by member and read from client, the default Whitelist is used.
 * Then: Deserialization fails.
 * </pre>
 */
@Test
public void testDefaultDeserializationFilter_readOnClient() {
    JavaSerializationFilterConfig filterConfig = new JavaSerializationFilterConfig();
    Config config = new Config();
    config.getSerializationConfig().setJavaSerializationFilterConfig(filterConfig);
    HazelcastInstance member = hazelcastFactory.newInstances(config, 1)[0];
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getSerializationConfig().setJavaSerializationFilterConfig(filterConfig);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    member.getMap("test").put("key", new TestDeserialized());
    try {
        client.getMap("test").get("key");
        fail("Deserialization should have failed");
    } catch (HazelcastSerializationException e) {
        assertFalse(TestDeserialized.isDeserialized);
    }
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestDeserialized(example.serialization.TestDeserialized) Config(com.hazelcast.config.Config) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with TestDeserialized

use of example.serialization.TestDeserialized in project hazelcast by hazelcast.

the class ClientDeserializationProtectionTest method testClassWhitelisted.

/**
 * <pre>
 * When: Deserialization filtering is enabled and classname of test object is whitelisted.
 * Then: The deserialization is possible.
 * </pre>
 */
@Test
public void testClassWhitelisted() {
    JavaSerializationFilterConfig filterConfig = new JavaSerializationFilterConfig();
    filterConfig.getWhitelist().addClasses(TestDeserialized.class.getName());
    Config config = new Config();
    config.getSerializationConfig().setJavaSerializationFilterConfig(filterConfig);
    HazelcastInstance member = hazelcastFactory.newInstances(config, 1)[0];
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getSerializationConfig().setJavaSerializationFilterConfig(filterConfig);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    member.getMap("test").put("key", new TestDeserialized());
    assertNotNull(client.getMap("test").get("key"));
    assertTrue(TestDeserialized.isDeserialized);
}
Also used : TestDeserialized(example.serialization.TestDeserialized) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with TestDeserialized

use of example.serialization.TestDeserialized in project hazelcast by hazelcast.

the class ClientDeserializationProtectionTest method testDefaultDeserializationFilter_readOnMember.

/**
 * <pre>
 * When: An untrusted serialized object is stored from client and read from member, the default Whitelist is used.
 * Then: Deserialization fails.
 * </pre>
 */
@Test
public void testDefaultDeserializationFilter_readOnMember() {
    JavaSerializationFilterConfig filterConfig = new JavaSerializationFilterConfig();
    Config config = new Config();
    config.getSerializationConfig().setJavaSerializationFilterConfig(filterConfig);
    HazelcastInstance member = hazelcastFactory.newInstances(config, 1)[0];
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getSerializationConfig().setJavaSerializationFilterConfig(filterConfig);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    client.getMap("test").put("key", new TestDeserialized());
    try {
        member.getMap("test").get("key");
        fail("Deserialization should have failed");
    } catch (HazelcastSerializationException e) {
        assertFalse(TestDeserialized.isDeserialized);
    }
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestDeserialized(example.serialization.TestDeserialized) Config(com.hazelcast.config.Config) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with TestDeserialized

use of example.serialization.TestDeserialized in project hazelcast by hazelcast.

the class DeserializationProtectionTest method assertDeserializationPass.

private void assertDeserializationPass(JavaSerializationFilterConfig filterConfig) {
    Config config = new Config();
    config.getSerializationConfig().setJavaSerializationFilterConfig(filterConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance[] instances = factory.newInstances(config);
    instances[0].getMap("test").put("a", new TestDeserialized());
    assertNotNull(instances[1].getMap("test").get("a"));
    assertTrue(TestDeserialized.isDeserialized);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestDeserialized(example.serialization.TestDeserialized) Config(com.hazelcast.config.Config) JavaSerializationFilterConfig(com.hazelcast.config.JavaSerializationFilterConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Aggregations

TestDeserialized (example.serialization.TestDeserialized)10 Config (com.hazelcast.config.Config)9 JavaSerializationFilterConfig (com.hazelcast.config.JavaSerializationFilterConfig)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 ClientConfig (com.hazelcast.client.config.ClientConfig)5 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)4 JoinConfig (com.hazelcast.config.JoinConfig)2 HazelcastTestSupport.smallInstanceConfig (com.hazelcast.test.HazelcastTestSupport.smallInstanceConfig)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 ClassFilter (com.hazelcast.config.ClassFilter)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 DatagramPacket (java.net.DatagramPacket)1 InetAddress (java.net.InetAddress)1 MulticastSocket (java.net.MulticastSocket)1