use of example.serialization.TestDeserialized in project hazelcast by hazelcast.
the class ClientDeserializationProtectionTest method testClassBlacklisted.
/**
* <pre>
* When: Default Whitelist is disabled and classname of the test serialized object is blacklisted. The object is read from client.
* Then: Deserialization fails.
* </pre>
*/
@Test
public void testClassBlacklisted() {
ClassFilter blacklist = new ClassFilter().addClasses(TestDeserialized.class.getName());
JavaSerializationFilterConfig filterConfig = new JavaSerializationFilterConfig().setDefaultsDisabled(true).setBlacklist(blacklist);
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 example.serialization.TestDeserialized in project hazelcast by hazelcast.
the class MulticastDeserializationTest method testWithoutFilter.
@Test
public void testWithoutFilter() throws Exception {
Config config = createConfig(false);
Hazelcast.newHazelcastInstance(config);
sendJoinDatagram(new TestDeserialized());
assertTrueEventually(() -> assertTrue("Object was not deserialized", TestDeserialized.isDeserialized));
}
use of example.serialization.TestDeserialized in project hazelcast by hazelcast.
the class MulticastDiscoveryStrategyDeserializationTest method sendDatagrams.
private void sendDatagrams() {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
MulticastSocket multicastSocket = null;
try {
try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
oos.writeObject(new TestDeserialized());
}
byte[] data = bos.toByteArray();
multicastSocket = new MulticastSocket(PORT);
multicastSocket.setTimeToLive(0);
if (OsHelper.isMac()) {
multicastSocket.setInterface(InetAddress.getByName("127.0.0.1"));
}
InetAddress group = InetAddress.getByName(GROUP);
multicastSocket.joinGroup(group);
DatagramPacket packet = new DatagramPacket(data, data.length, group, PORT);
while (!stop) {
try {
multicastSocket.send(packet);
TimeUnit.SECONDS.sleep(1);
} catch (Exception e) {
}
}
multicastSocket.leaveGroup(group);
} catch (Exception e) {
datagramsThreadException = e;
e.printStackTrace();
} finally {
if (multicastSocket != null) {
multicastSocket.close();
}
}
}
use of example.serialization.TestDeserialized in project hazelcast by hazelcast.
the class DeserializationProtectionTest method assertDeserializationFails.
private void assertDeserializationFails(JavaSerializationFilterConfig javaSerializationFilterConfig, boolean keyOwnedByTarget) {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
Config config = new Config();
config.getSerializationConfig().setJavaSerializationFilterConfig(javaSerializationFilterConfig);
HazelcastInstance[] instances = factory.newInstances(config);
String key = generateKeyOwnedBy(instances[keyOwnedByTarget ? 1 : 0]);
instances[0].getMap("test").put(key, new TestDeserialized());
try {
instances[1].getMap("test").get(key);
fail("Deserialization should have failed");
} catch (HazelcastSerializationException e) {
assertFalse(TestDeserialized.isDeserialized);
}
}
use of example.serialization.TestDeserialized in project hazelcast by hazelcast.
the class MulticastDeserializationTest method test.
/**
* Given: Multicast is configured.
* When: DatagramPacket with a correct Packet comes. The Packet references
* Java serializer and the serialized object is not a Join message.
* Then: The object from the Packet is not deserialized.
*/
@Test
public void test() throws Exception {
Config config = createConfig(true);
Hazelcast.newHazelcastInstance(config);
sendJoinDatagram(new TestDeserialized());
Thread.sleep(500L);
assertFalse("Untrusted deserialization is possible", TestDeserialized.isDeserialized);
}
Aggregations