Skip to content

Commit 62ca001

Browse files
committed
8313357: Revisit requiring SA tests on OSX to either run as root or use sudo
Reviewed-by: dholmes, amenkov
1 parent 388dcff commit 62ca001

File tree

1 file changed

+55
-4
lines changed

1 file changed

+55
-4
lines changed

test/lib/jdk/test/lib/SA/SATestUtils.java

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ public static void skipIfCannotAttach() {
6666
if (Platform.isHardenedOSX()) {
6767
throw new SkippedException("SA Attach not expected to work. JDK is hardened.");
6868
}
69-
if (!Platform.isRoot() && !canAddPrivileges()) {
70-
throw new SkippedException("SA Attach not expected to work. Insufficient privileges (not root and can't use sudo).");
69+
if (needsPrivileges() && !canAddPrivileges()) {
70+
throw new SkippedException("SA Attach not expected to work. Insufficient privileges " +
71+
"(developer mode disabled, not root, and can't use sudo).");
7172
}
7273
}
7374
} catch (IOException e) {
@@ -77,11 +78,54 @@ public static void skipIfCannotAttach() {
7778

7879
/**
7980
* Returns true if this platform is expected to require extra privileges (running using sudo).
81+
* If we are running as root or developer mode is enabled, then sudo is not needed.
8082
*/
8183
public static boolean needsPrivileges() {
82-
return Platform.isOSX() && !Platform.isRoot();
84+
if (!Platform.isOSX()) {
85+
return false;
86+
}
87+
if (Platform.isRoot()) {
88+
return false;
89+
}
90+
return !developerModeEnabled();
8391
}
8492

93+
/*
94+
* Run "DevToolsSecurity --status" to see if developer mode is enabled.
95+
*/
96+
private static boolean developerModeEnabled() {
97+
List<String> cmd = new ArrayList<String>();
98+
cmd.add("DevToolsSecurity");
99+
cmd.add("--status");
100+
ProcessBuilder pb = new ProcessBuilder(cmd);
101+
Process p;
102+
try {
103+
p = pb.start();
104+
try {
105+
p.waitFor();
106+
} catch (InterruptedException e) {
107+
throw new RuntimeException("DevToolsSecurity process interrupted", e);
108+
}
109+
110+
String out = new String(p.getInputStream().readAllBytes());
111+
String err = new String(p.getErrorStream().readAllBytes());
112+
System.out.print("DevToolsSecurity stdout: " + out);
113+
if (out.equals("")) System.out.println();
114+
System.out.print("DevToolsSecurity stderr: " + err);
115+
if (err.equals("")) System.out.println();
116+
117+
if (out.contains("Developer mode is currently enabled")) {
118+
return true;
119+
}
120+
if (out.contains("Developer mode is currently disabled")) {
121+
return false;
122+
}
123+
throw new RuntimeException("DevToolsSecurity failed to generate expected output: " + out);
124+
} catch (IOException e) {
125+
throw new RuntimeException(e);
126+
}
127+
}
128+
85129
/**
86130
* Returns true if a no-password sudo is expected to work properly.
87131
*/
@@ -218,9 +262,16 @@ private static boolean canPtraceAttachLinux() throws IOException {
218262
* to timeout. For that reason we don't run this test when privileges are needed. Note
219263
* it does appear to run fine as root, so we still allow it to run on OSX when privileges
220264
* are not required.
265+
*
266+
* Note that we also can't run these tests even if OSX developer mode is enabled (see
267+
* developerModeEnabled()). For the most part the test runs fine, but some reason you end up
268+
* needing to provide admin credentials as the test shuts down. If you don't, it just hangs forever.
269+
* And even after providing the credetials, the test still fails with a timeout.
270+
*
271+
* JDK-8314133 has been filed for these issues.
221272
*/
222273
public static void validateSADebugDPrivileges() {
223-
if (needsPrivileges()) {
274+
if (Platform.isOSX() && !Platform.isRoot()) {
224275
throw new SkippedException("Cannot run this test on OSX if adding privileges is required.");
225276
}
226277
}

0 commit comments

Comments
 (0)