use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class ClientUserCodeDeploymentExceptionTest method testUserCodeDeploymentIsDisabledByDefaultOnClient.
@Test
public void testUserCodeDeploymentIsDisabledByDefaultOnClient() {
// this test also validate the EP is filtered locally and has to be loaded from the other member
ClientConfig clientConfig = new ClientConfig();
Config config = createNodeConfig();
config.getUserCodeDeploymentConfig().setEnabled(true);
IncrementingEntryProcessor incrementingEntryProcessor = new IncrementingEntryProcessor();
factory.newHazelcastInstance(config);
HazelcastInstance client = factory.newHazelcastClient(clientConfig);
IMap<Integer, Integer> map = client.getMap(randomName());
try {
map.executeOnEntries(incrementingEntryProcessor);
fail();
} catch (HazelcastSerializationException e) {
assertEquals(ClassNotFoundException.class, e.getCause().getClass());
}
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException 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);
}
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException 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);
}
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class AbstractNearCacheSerializationCountTest method getStackTrace.
private static String getStackTrace(String message) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
new HazelcastSerializationException(message).printStackTrace(pw);
return sw.toString();
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class DataSerializableSerializationTest method testClarifiedExceptionsForUnsupportedClassTypes.
@Test
public void testClarifiedExceptionsForUnsupportedClassTypes() {
class LocalClass implements DataSerializable {
@Override
public void writeData(ObjectDataOutput out) {
}
@Override
public void readData(ObjectDataInput in) {
}
}
DataSerializable anonymousInstance = new DataSerializable() {
@Override
public void writeData(ObjectDataOutput out) {
}
@Override
public void readData(ObjectDataInput in) {
}
};
DataSerializable[] throwingInstances = { new LocalClass(), anonymousInstance, new NonStaticMemberClass() };
for (DataSerializable throwingInstance : throwingInstances) {
try {
ss.toObject(ss.toData(throwingInstance));
} catch (HazelcastSerializationException e) {
assertInstanceOf(NoSuchMethodException.class, e.getCause());
assertContains(e.getCause().getMessage(), "can't conform to DataSerializable");
assertInstanceOf(NoSuchMethodException.class, e.getCause().getCause());
continue;
}
fail("deserialization of '" + throwingInstance.getClass() + "' is expected to fail");
}
for (DataSerializable throwingInstance : throwingInstances) {
try {
ss.toObject(ss.toData(throwingInstance), throwingInstance.getClass());
} catch (HazelcastSerializationException e) {
assertInstanceOf(InstantiationException.class, e.getCause());
assertContains(e.getCause().getMessage(), "can't conform to DataSerializable");
assertInstanceOf(InstantiationException.class, e.getCause().getCause());
continue;
}
fail("deserialization of '" + throwingInstance.getClass() + "' is expected to fail");
}
}
Aggregations