diff --git a/test/jdk/java/lang/ProcessHandle/PermissionTest.java b/test/jdk/java/lang/ProcessHandle/PermissionTest.java index 055152ebcaa..9cfb351a916 100644 --- a/test/jdk/java/lang/ProcessHandle/PermissionTest.java +++ b/test/jdk/java/lang/ProcessHandle/PermissionTest.java @@ -21,6 +21,7 @@ * questions. */ +import java.lang.reflect.ReflectPermission; import java.io.FilePermission; import java.io.IOException; import java.security.CodeSource; @@ -35,7 +36,7 @@ import java.util.PropertyPermission; import org.testng.Assert; import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeGroups; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; /* @@ -44,7 +45,7 @@ import org.testng.annotations.Test; * @summary Test Permissions to access Info */ -public class PermissionTest { +public abstract class PermissionTest { /** * Backing up policy. */ @@ -53,12 +54,12 @@ public class PermissionTest { /** * Backing up security manager. */ - private static SecurityManager sm; + static SecurityManager sm; /** * Current process handle. */ - private final ProcessHandle currentHndl; + final ProcessHandle currentHndl; PermissionTest() { policy = Policy.getPolicy(); @@ -66,115 +67,117 @@ public class PermissionTest { currentHndl = ProcessHandle.current(); } - @Test - public void descendantsWithPermission() { - Policy.setPolicy(new TestPolicy(new RuntimePermission("manageProcess"))); - currentHndl.descendants(); + @AfterClass + public void tearDownClass() throws Exception { + System.setSecurityManager(sm); + Policy.setPolicy(policy); } - @Test - public void allProcessesWithPermission() { - Policy.setPolicy(new TestPolicy(new RuntimePermission("manageProcess"))); - ProcessHandle.allProcesses(); - } + public static class WithPermission extends PermissionTest { + @BeforeClass + public void setupClass() { + Policy.setPolicy(new TestPolicy(new RuntimePermission("manageProcess"))); + } - @Test - public void childrenWithPermission() { - Policy.setPolicy(new TestPolicy(new RuntimePermission("manageProcess"))); - currentHndl.children(); - } + @Test + public void descendantsWithPermission() { + currentHndl.descendants(); + } - @Test - public void currentWithPermission() { - Policy.setPolicy(new TestPolicy(new RuntimePermission("manageProcess"))); - ProcessHandle.current(); - } + @Test + public void allProcessesWithPermission() { + ProcessHandle.allProcesses(); + } - @Test - public void ofWithPermission() { - Policy.setPolicy(new TestPolicy(new RuntimePermission("manageProcess"))); - ProcessHandle.of(0); - } + @Test + public void childrenWithPermission() { + currentHndl.children(); + } - @Test - public void parentWithPermission() { - Policy.setPolicy(new TestPolicy(new RuntimePermission("manageProcess"))); - currentHndl.parent(); - } + @Test + public void currentWithPermission() { + ProcessHandle.current(); + } + + @Test + public void ofWithPermission() { + ProcessHandle.of(0); + } + + @Test + public void parentWithPermission() { + currentHndl.parent(); + } - @Test - public void processToHandleWithPermission() throws IOException { - Policy.setPolicy(new TestPolicy(new RuntimePermission("manageProcess"))); - Process p = null; - try { - ProcessBuilder pb = new ProcessBuilder("sleep", "30"); - p = pb.start(); - ProcessHandle ph = p.toHandle(); - Assert.assertNotNull(ph, "ProcessHandle expected from Process"); - } finally { - if (p != null) { - p.destroy(); + @Test + public void processToHandleWithPermission() throws IOException { + Process p = null; + try { + ProcessBuilder pb = new ProcessBuilder("sleep", "30"); + p = pb.start(); + ProcessHandle ph = p.toHandle(); + Assert.assertNotNull(ph, "ProcessHandle expected from Process"); + } finally { + if (p != null) { + p.destroy(); + } } } } - @BeforeGroups (groups = {"NoManageProcessPermission"}) - public void noPermissionsSetup(){ - Policy.setPolicy(new TestPolicy()); - SecurityManager sm = new SecurityManager(); - System.setSecurityManager(sm); - } + public static class NoManageProcessPermission extends PermissionTest { + @BeforeClass + public void setupClass(){ + Policy.setPolicy(new TestPolicy()); + SecurityManager sm = new SecurityManager(); + System.setSecurityManager(sm); + } - @Test(groups = { "NoManageProcessPermission" }, expectedExceptions = SecurityException.class) - public void noPermissionAllChildren() { - currentHndl.descendants(); - } + @Test(expectedExceptions = SecurityException.class) + public void noPermissionAllChildren() { + currentHndl.descendants(); + } - @Test(groups = { "NoManageProcessPermission" }, expectedExceptions = SecurityException.class) - public void noPermissionAllProcesses() { - ProcessHandle.allProcesses(); - } + @Test(expectedExceptions = SecurityException.class) + public void noPermissionAllProcesses() { + ProcessHandle.allProcesses(); + } - @Test(groups = { "NoManageProcessPermission" }, expectedExceptions = SecurityException.class) - public void noPermissionChildren() { - currentHndl.children(); - } + @Test(expectedExceptions = SecurityException.class) + public void noPermissionChildren() { + currentHndl.children(); + } - @Test(groups = { "NoManageProcessPermission" }, expectedExceptions = SecurityException.class) - public void noPermissionCurrent() { - ProcessHandle.current(); - } + @Test(expectedExceptions = SecurityException.class) + public void noPermissionCurrent() { + ProcessHandle.current(); + } - @Test(groups = { "NoManageProcessPermission" }, expectedExceptions = SecurityException.class) - public void noPermissionOf() { - ProcessHandle.of(0); - } + @Test(expectedExceptions = SecurityException.class) + public void noPermissionOf() { + ProcessHandle.of(0); + } - @Test(groups = { "NoManageProcessPermission" }, expectedExceptions = SecurityException.class) - public void noPermissionParent() { - currentHndl.parent(); - } + @Test(expectedExceptions = SecurityException.class) + public void noPermissionParent() { + currentHndl.parent(); + } - @Test(groups = { "NoManageProcessPermission" }, expectedExceptions = SecurityException.class) - public void noPermissionProcessToHandle() throws IOException { - Process p = null; - try { - ProcessBuilder pb = new ProcessBuilder("sleep", "30"); - p = pb.start(); - ProcessHandle ph = p.toHandle(); - Assert.assertNotNull(ph, "ProcessHandle expected from Process"); - } finally { - if (p != null) { - p.destroy(); + @Test(expectedExceptions = SecurityException.class) + public void noPermissionProcessToHandle() throws IOException { + Process p = null; + try { + ProcessBuilder pb = new ProcessBuilder("sleep", "30"); + p = pb.start(); + ProcessHandle ph = p.toHandle(); + Assert.assertNotNull(ph, "ProcessHandle expected from Process"); + } finally { + if (p != null) { + p.destroy(); + } } } } - - @AfterClass - public void tearDownClass() throws Exception { - System.setSecurityManager(sm); - Policy.setPolicy(policy); - } } class TestPolicy extends Policy { @@ -197,14 +200,14 @@ class TestPolicy extends Policy { permissions.add(new RuntimePermission("getClassLoader")); permissions.add(new RuntimePermission("setSecurityManager")); permissions.add(new RuntimePermission("createSecurityManager")); - permissions.add(new PropertyPermission("testng.show.stack.frames", - "read")); permissions.add(new PropertyPermission("user.dir", "read")); permissions.add(new PropertyPermission("test.src", "read")); permissions.add(new PropertyPermission("file.separator", "read")); permissions.add(new PropertyPermission("line.separator", "read")); permissions.add(new PropertyPermission("fileStringBuffer", "read")); permissions.add(new PropertyPermission("dataproviderthreadcount", "read")); + permissions.add(new PropertyPermission("testng.*", "read")); + permissions.add(new ReflectPermission("suppressAccessChecks")); permissions.add(new FilePermission("<>", "execute")); }