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
This commit is contained in:
Aaron Brady
2018-07-16 08:29:17 -07:00
committed by Facebook Github Bot
parent e844e4bd34
commit d34aba9e21

View File

@@ -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<void> {
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}`));
}