Display message when "Operation Not Permitted" bug is seen

Summary:
On certain samsung devices, the 'run-as' command, inside adb shell doesn't work.
We don't yet have a workaround for this, otherwise potentially upgrading to android 8.
Distinguish these errors (log them so we'll see how often it happens), and tell the user why it's not working.

Reviewed By: danielbuechele

Differential Revision: D8638728

fbshipit-source-id: f4764120cc27187330a3f236636292a5e63e8ec9
This commit is contained in:
John Knox
2018-06-26 12:56:43 -07:00
committed by Facebook Github Bot
parent 46df0b25a0
commit 266af3e274

View File

@@ -33,6 +33,7 @@ const minCertExpiryWindowSeconds = 24 * 60 * 60;
const appNotDebuggableRegex = /debuggable/;
const allowedAppNameRegex = /^[a-zA-Z0-9.\-]+$/;
const allowedAppDirectoryRegex = /^\/[ a-zA-Z0-9.\-\/]+$/;
const operationNotPermittedRegex = /not permitted/;
const logTag = 'CertificateProvider';
/*
* RFC2253 specifies the unamiguous x509 subject format.
@@ -106,7 +107,8 @@ export default class CertificateProvider {
csr,
os,
),
);
)
.catch(e => console.error(e));
}
ensureOpenSSLIsAvailable(): void {
@@ -271,22 +273,21 @@ export default class CertificateProvider {
.then(adb.util.readAll)
.then(buffer => buffer.toString())
.then(output => {
const matches = output.match(appNotDebuggableRegex);
if (matches) {
if (output.match(appNotDebuggableRegex)) {
const e = new Error(
`Android app ${user} is not debuggable. To use it with sonar, add android:debuggable="true" to the application section of AndroidManifest.xml`,
);
this.server.emit('error', e);
throw e;
}
if (output.toLowerCase().match(operationNotPermittedRegex)) {
const e = new Error(
`Your android device (${deviceId}) does not support the adb shell run-as command. We're tracking this at https://github.com/facebook/Sonar/issues/92`,
);
this.server.emit('error', e);
throw e;
}
return output;
})
.catch(err => {
console.error(
`Error executing command on android device ${deviceId}:${user}. Command: ${command}`,
logTag,
);
console.error(err, logTag);
});
}