From 266af3e274f93327d719d039d632ebadccd1a898 Mon Sep 17 00:00:00 2001 From: John Knox Date: Tue, 26 Jun 2018 12:56:43 -0700 Subject: [PATCH] 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 --- src/utils/CertificateProvider.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/utils/CertificateProvider.js b/src/utils/CertificateProvider.js index 80477c747..605b00793 100644 --- a/src/utils/CertificateProvider.js +++ b/src/utils/CertificateProvider.js @@ -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); }); }