|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
35 | 35 |
|
36 | 36 | import org.testng.Assert;
|
37 | 37 | import org.testng.annotations.AfterClass;
|
38 |
| -import org.testng.annotations.BeforeGroups; |
39 | 38 | import org.testng.annotations.Test;
|
40 | 39 |
|
41 | 40 | /*
|
@@ -118,45 +117,54 @@ public void processToHandleWithPermission() throws IOException {
|
118 | 117 | }
|
119 | 118 | }
|
120 | 119 |
|
121 |
| - @BeforeGroups (groups = {"NoManageProcessPermission"}) |
| 120 | + /** |
| 121 | + * Setup a policy that would reject ProcessHandle requests without Permissions ManageProcess. |
| 122 | + */ |
122 | 123 | public void noPermissionsSetup(){
|
123 | 124 | Policy.setPolicy(new TestPolicy());
|
124 | 125 | SecurityManager sm = new SecurityManager();
|
125 | 126 | System.setSecurityManager(sm);
|
126 | 127 | }
|
127 | 128 |
|
128 |
| - @Test(groups = { "NoManageProcessPermission" }, expectedExceptions = SecurityException.class) |
| 129 | + @Test(expectedExceptions = SecurityException.class) |
129 | 130 | public void noPermissionAllChildren() {
|
| 131 | + noPermissionsSetup(); |
130 | 132 | currentHndl.descendants();
|
131 | 133 | }
|
132 | 134 |
|
133 |
| - @Test(groups = { "NoManageProcessPermission" }, expectedExceptions = SecurityException.class) |
| 135 | + @Test(expectedExceptions = SecurityException.class) |
134 | 136 | public void noPermissionAllProcesses() {
|
| 137 | + noPermissionsSetup(); |
135 | 138 | ProcessHandle.allProcesses();
|
136 | 139 | }
|
137 | 140 |
|
138 |
| - @Test(groups = { "NoManageProcessPermission" }, expectedExceptions = SecurityException.class) |
| 141 | + @Test(expectedExceptions = SecurityException.class) |
139 | 142 | public void noPermissionChildren() {
|
| 143 | + noPermissionsSetup(); |
140 | 144 | currentHndl.children();
|
141 | 145 | }
|
142 | 146 |
|
143 |
| - @Test(groups = { "NoManageProcessPermission" }, expectedExceptions = SecurityException.class) |
| 147 | + @Test(expectedExceptions = SecurityException.class) |
144 | 148 | public void noPermissionCurrent() {
|
| 149 | + noPermissionsSetup(); |
145 | 150 | ProcessHandle.current();
|
146 | 151 | }
|
147 | 152 |
|
148 |
| - @Test(groups = { "NoManageProcessPermission" }, expectedExceptions = SecurityException.class) |
| 153 | + @Test(expectedExceptions = SecurityException.class) |
149 | 154 | public void noPermissionOf() {
|
| 155 | + noPermissionsSetup(); |
150 | 156 | ProcessHandle.of(0);
|
151 | 157 | }
|
152 | 158 |
|
153 |
| - @Test(groups = { "NoManageProcessPermission" }, expectedExceptions = SecurityException.class) |
| 159 | + @Test(expectedExceptions = SecurityException.class) |
154 | 160 | public void noPermissionParent() {
|
| 161 | + noPermissionsSetup(); |
155 | 162 | currentHndl.parent();
|
156 | 163 | }
|
157 | 164 |
|
158 |
| - @Test(groups = { "NoManageProcessPermission" }, expectedExceptions = SecurityException.class) |
| 165 | + @Test(expectedExceptions = SecurityException.class) |
159 | 166 | public void noPermissionProcessToHandle() throws IOException {
|
| 167 | + noPermissionsSetup(); |
160 | 168 | Process p = null;
|
161 | 169 | try {
|
162 | 170 | ProcessBuilder pb = new ProcessBuilder("sleep", "30");
|
|
0 commit comments