@@ -66,8 +66,9 @@ public static void skipIfCannotAttach() {
66
66
if (Platform .isHardenedOSX ()) {
67
67
throw new SkippedException ("SA Attach not expected to work. JDK is hardened." );
68
68
}
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)." );
71
72
}
72
73
}
73
74
} catch (IOException e ) {
@@ -77,11 +78,54 @@ public static void skipIfCannotAttach() {
77
78
78
79
/**
79
80
* 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.
80
82
*/
81
83
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 ();
83
91
}
84
92
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
+
85
129
/**
86
130
* Returns true if a no-password sudo is expected to work properly.
87
131
*/
@@ -218,9 +262,16 @@ private static boolean canPtraceAttachLinux() throws IOException {
218
262
* to timeout. For that reason we don't run this test when privileges are needed. Note
219
263
* it does appear to run fine as root, so we still allow it to run on OSX when privileges
220
264
* 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.
221
272
*/
222
273
public static void validateSADebugDPrivileges () {
223
- if (needsPrivileges ()) {
274
+ if (Platform . isOSX () && ! Platform . isRoot ()) {
224
275
throw new SkippedException ("Cannot run this test on OSX if adding privileges is required." );
225
276
}
226
277
}
0 commit comments