From d34aba9e212e0b2f1fd625f6055925f15875050f Mon Sep 17 00:00:00 2001 From: Aaron Brady Date: Mon, 16 Jul 2018 08:29:17 -0700 Subject: [PATCH] Allow filesystem to decide path validity for cert dest folder (sonarCA.cert failing to write on windows) Summary: On windows when I used a more complicated path for the sonar directory (e.g. for writing sonarCA.cert to), it failed this regex but succeeded the node fs.writeFile call. Unless I'm missing something else this regex does, we should just let the authority of the fs module decide if it can write something. Reviewed By: jknoxville Differential Revision: D8822094 fbshipit-source-id: 294c9a7b70080fefcfffdddd239d321ff7faa4e1 --- src/utils/CertificateProvider.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/utils/CertificateProvider.js b/src/utils/CertificateProvider.js index 2f9dc7604..e293e0471 100644 --- a/src/utils/CertificateProvider.js +++ b/src/utils/CertificateProvider.js @@ -33,7 +33,6 @@ const serverSubject = '/C=US/ST=CA/L=Menlo Park/O=Sonar/CN=localhost'; 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'; /* @@ -81,13 +80,6 @@ export default class CertificateProvider { appDirectory: string, ): Promise { this.ensureOpenSSLIsAvailable(); - if (!appDirectory.match(allowedAppDirectoryRegex)) { - return Promise.reject( - new RecurringError( - `Invalid appDirectory recieved from ${os} device: ${appDirectory}`, - ), - ); - } return this.certificateSetup .then(_ => this.getCACertificate()) .then(caCert => @@ -172,8 +164,18 @@ export default class CertificateProvider { ); } if (os === 'iOS' || os === 'windows') { - fs.writeFileSync(destination + filename, contents); - return Promise.resolve(); + return new Promise((resolve, reject) => { + fs.writeFile(destination + filename, contents, err => { + if (err) { + reject( + `Invalid appDirectory recieved from ${os} device: ${destination}: ` + + err.toString(), + ); + } else { + resolve(); + } + }); + }); } return Promise.reject(new RecurringError(`Unsupported device os: ${os}`)); }