18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.io.IOException; 25 import java.io.Serializable; 26 27 import java.rmi.AlreadyBoundException; 28 import java.rmi.MarshalledObject; 29 import java.rmi.NotBoundException; 30 import java.rmi.Remote; 31 import java.rmi.RemoteException; 32 import java.rmi.registry.LocateRegistry; 33 import java.rmi.registry.Registry; 34 import java.security.Security; 35 import java.util.Objects; 36 37 import org.testng.Assert; 38 import org.testng.TestNG; 39 import org.testng.annotations.BeforeSuite; 40 import org.testng.annotations.DataProvider; 41 import org.testng.annotations.Test; 42 43 /* 44 * @test 45 * @library /java/rmi/testlibrary 46 * @modules java.rmi/sun.rmi.registry 47 * java.rmi/sun.rmi.server 48 * java.rmi/sun.rmi.transport 49 * java.rmi/sun.rmi.transport.tcp 50 * @build TestLibrary 51 * @summary Test filters for the RMI Registry 52 * @run testng/othervm RegistryFilterTest 53 * @run testng/othervm 54 * -Dsun.rmi.registry.registryFilter=!java.lang.Long;!RegistryFilterTest$RejectableClass;maxdepth=19 55 * -Dtest.maxdepth=19 56 * RegistryFilterTest 57 * @run testng/othervm/policy=security.policy 58 * -Djava.security.properties=${test.src}/java.security-extra1 59 * RegistryFilterTest 60 */ 61 public class RegistryFilterTest { 62 private static Registry impl; 63 private static int port; 64 private static Registry registry; 65 66 static final int REGISTRY_MAX_DEPTH = 20; 67 68 static final int REGISTRY_MAX_ARRAY = 10000; 69 70 static final String registryFilter = 71 System.getProperty("sun.rmi.registry.registryFilter", 72 Security.getProperty("sun.rmi.registry.registryFilter")); 73 74 @DataProvider(name = "bindAllowed") 75 static Object[][] bindAllowedObjects() { 76 Object[][] objects = { 77 }; 78 return objects; 79 } 80 81 /** 82 * Data RMI Regiry bind test. 83 * - name 84 * - Object 85 * - true/false if object is blacklisted by a filter (implicit or explicit) 86 * @return array of test data 87 */ 88 @DataProvider(name = "bindData") 89 static Object[][] bindObjects() { 90 Object[][] data = { 91 { "byte[max]", new XX(new byte[REGISTRY_MAX_ARRAY]), false }, 92 { "String", new XX("now is the time"), false}, 93 { "String[]", new XX(new String[3]), false}, 94 { "Long[4]", new XX(new Long[4]), registryFilter != null }, 95 { "rej-byte[toobig]", new XX(new byte[REGISTRY_MAX_ARRAY + 1]), true }, 96 { "rej-MarshalledObject", createMarshalledObject(), true }, 97 { "rej-RejectableClass", new RejectableClass(), registryFilter != null}, 98 }; 99 return data; 100 } 101 102 static XX createMarshalledObject() { 103 try { 104 return new XX(new MarshalledObject<>(null)); 105 } catch (IOException ioe) { 106 return new XX(ioe); 107 } 108 } 109 110 @BeforeSuite 111 static void setupRegistry() { 112 try { 113 impl = TestLibrary.createRegistryOnEphemeralPort(); 114 port = TestLibrary.getRegistryPort(impl); 115 registry = LocateRegistry.getRegistry("localhost", port); | 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.io.IOException; 25 import java.io.Serializable; 26 27 import java.rmi.AlreadyBoundException; 28 import java.rmi.MarshalledObject; 29 import java.rmi.NotBoundException; 30 import java.rmi.Remote; 31 import java.rmi.RemoteException; 32 import java.rmi.registry.LocateRegistry; 33 import java.rmi.registry.Registry; 34 import java.security.Security; 35 import java.util.Objects; 36 37 import org.testng.Assert; 38 import org.testng.annotations.BeforeSuite; 39 import org.testng.annotations.DataProvider; 40 import org.testng.annotations.Test; 41 42 /* 43 * @test 44 * @library /java/rmi/testlibrary 45 * @build TestLibrary 46 * @summary Test filters for the RMI Registry 47 * @run testng/othervm RegistryFilterTest 48 * @run testng/othervm 49 * -Dsun.rmi.registry.registryFilter=!java.lang.Long;!RegistryFilterTest$RejectableClass;maxdepth=19 50 * -Dtest.maxdepth=19 51 * RegistryFilterTest 52 * @run testng/othervm/policy=security.policy 53 * -Djava.security.properties=${test.src}/java.security-extra1 54 * RegistryFilterTest 55 */ 56 public class RegistryFilterTest { 57 private static Registry impl; 58 private static int port; 59 private static Registry registry; 60 61 static final int REGISTRY_MAX_DEPTH = 20; 62 63 static final int REGISTRY_MAX_ARRAY = 1_000_000; 64 65 static final String registryFilter = 66 System.getProperty("sun.rmi.registry.registryFilter", 67 Security.getProperty("sun.rmi.registry.registryFilter")); 68 69 /** 70 * Data RMI Registry bind test. 71 * - name 72 * - Object 73 * - true/false if object is blacklisted by a filter (implicit or explicit) 74 * @return array of test data 75 */ 76 @DataProvider(name = "bindData") 77 static Object[][] bindObjects() { 78 Object[][] data = { 79 { "byte[max]", new XX(new byte[REGISTRY_MAX_ARRAY]), false }, 80 { "String", new XX("now is the time"), false}, 81 { "String[3]", new XX(new String[3]), false}, 82 { "Long[4]", new XX(new Long[4]), false }, 83 { "Object[REGISTRY_MAX_ARRAY]", new XX(new Object[REGISTRY_MAX_ARRAY]), false }, 84 { "rej-byte[toobig]", new XX(new byte[REGISTRY_MAX_ARRAY + 1]), true }, 85 { "rej-Object[toobig]", new XX(new Object[REGISTRY_MAX_ARRAY + 1]), true }, 86 { "rej-MarshalledObject", createMarshalledObject(), true }, 87 { "rej-RejectableClass", new RejectableClass(), registryFilter != null}, 88 }; 89 return data; 90 } 91 92 static XX createMarshalledObject() { 93 try { 94 return new XX(new MarshalledObject<>(null)); 95 } catch (IOException ioe) { 96 return new XX(ioe); 97 } 98 } 99 100 @BeforeSuite 101 static void setupRegistry() { 102 try { 103 impl = TestLibrary.createRegistryOnEphemeralPort(); 104 port = TestLibrary.getRegistryPort(impl); 105 registry = LocateRegistry.getRegistry("localhost", port); |