Fix Flipper lints #7
Summary: Fix lints according to https://www.internalfb.com/intern/staticdocs/flipper/docs/internals/linters. Logic should be unchanged. Reviewed By: timur-valiev Differential Revision: D30766176 fbshipit-source-id: a7b3f78af66188704913c87321b07aff0fed270a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
93660d6be3
commit
4ba9a334d5
@@ -355,66 +355,62 @@ export default class CertificateProvider {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getTargetAndroidDeviceId(
|
private async getTargetAndroidDeviceId(
|
||||||
appName: string,
|
appName: string,
|
||||||
deviceCsrFilePath: string,
|
deviceCsrFilePath: string,
|
||||||
csr: string,
|
csr: string,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return this.adb
|
const devices = await this.adb.then((client) => client.listDevices());
|
||||||
.then((client) => client.listDevices())
|
if (devices.length === 0) {
|
||||||
.then((devices) => {
|
throw new Error('No Android devices found');
|
||||||
if (devices.length === 0) {
|
}
|
||||||
throw new Error('No Android devices found');
|
const deviceMatchList = devices.map(async (device) => {
|
||||||
}
|
try {
|
||||||
const deviceMatchList = devices.map((device) =>
|
const result = await this.androidDeviceHasMatchingCSR(
|
||||||
this.androidDeviceHasMatchingCSR(
|
deviceCsrFilePath,
|
||||||
deviceCsrFilePath,
|
device.id,
|
||||||
device.id,
|
appName,
|
||||||
appName,
|
csr,
|
||||||
csr,
|
|
||||||
)
|
|
||||||
.then((result) => {
|
|
||||||
return {id: device.id, ...result, error: null};
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
console.warn(
|
|
||||||
`Unable to check for matching CSR in ${device.id}:${appName}`,
|
|
||||||
logTag,
|
|
||||||
);
|
|
||||||
return {id: device.id, isMatch: false, foundCsr: null, error: e};
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
return Promise.all(deviceMatchList).then((devices) => {
|
return {id: device.id, ...result, error: null};
|
||||||
const matchingIds = devices.filter((m) => m.isMatch).map((m) => m.id);
|
} catch (e) {
|
||||||
if (matchingIds.length == 0) {
|
console.warn(
|
||||||
const erroredDevice = devices.find((d) => d.error);
|
`Unable to check for matching CSR in ${device.id}:${appName}`,
|
||||||
if (erroredDevice) {
|
logTag,
|
||||||
throw erroredDevice.error;
|
);
|
||||||
}
|
return {id: device.id, isMatch: false, foundCsr: null, error: e};
|
||||||
const foundCsrs = devices
|
}
|
||||||
.filter((d) => d.foundCsr !== null)
|
});
|
||||||
.map((d) => (d.foundCsr ? encodeURI(d.foundCsr) : 'null'));
|
return Promise.all(deviceMatchList).then((devices) => {
|
||||||
console.warn(`Looking for CSR (url encoded):
|
const matchingIds = devices.filter((m) => m.isMatch).map((m) => m.id);
|
||||||
|
if (matchingIds.length == 0) {
|
||||||
|
const erroredDevice = devices.find((d) => d.error);
|
||||||
|
if (erroredDevice) {
|
||||||
|
throw erroredDevice.error;
|
||||||
|
}
|
||||||
|
const foundCsrs = devices
|
||||||
|
.filter((d) => d.foundCsr !== null)
|
||||||
|
.map((d) => (d.foundCsr ? encodeURI(d.foundCsr) : 'null'));
|
||||||
|
console.warn(`Looking for CSR (url encoded):
|
||||||
|
|
||||||
${encodeURI(this.santitizeString(csr))}
|
${encodeURI(this.santitizeString(csr))}
|
||||||
|
|
||||||
Found these:
|
Found these:
|
||||||
|
|
||||||
${foundCsrs.join('\n\n')}`);
|
${foundCsrs.join('\n\n')}`);
|
||||||
throw new Error(`No matching device found for app: ${appName}`);
|
throw new Error(`No matching device found for app: ${appName}`);
|
||||||
}
|
}
|
||||||
if (matchingIds.length > 1) {
|
if (matchingIds.length > 1) {
|
||||||
console.warn(
|
console.warn(
|
||||||
new Error('More than one matching device found for CSR'),
|
new Error('More than one matching device found for CSR'),
|
||||||
csr,
|
csr,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return matchingIds[0];
|
return matchingIds[0];
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private getTargetiOSDeviceId(
|
private async getTargetiOSDeviceId(
|
||||||
appName: string,
|
appName: string,
|
||||||
deviceCsrFilePath: string,
|
deviceCsrFilePath: string,
|
||||||
csr: string,
|
csr: string,
|
||||||
@@ -424,30 +420,29 @@ export default class CertificateProvider {
|
|||||||
// It's a simulator, the deviceId is in the filepath.
|
// It's a simulator, the deviceId is in the filepath.
|
||||||
return Promise.resolve(matches[1]);
|
return Promise.resolve(matches[1]);
|
||||||
}
|
}
|
||||||
return iosUtil
|
const targets = await iosUtil.targets(
|
||||||
.targets(this.config.idbPath, this.config.enablePhysicalIOS)
|
this.config.idbPath,
|
||||||
.then((targets) => {
|
this.config.enablePhysicalIOS,
|
||||||
if (targets.length === 0) {
|
);
|
||||||
throw new Error('No iOS devices found');
|
if (targets.length === 0) {
|
||||||
}
|
throw new Error('No iOS devices found');
|
||||||
const deviceMatchList = targets.map((target) =>
|
}
|
||||||
this.iOSDeviceHasMatchingCSR(
|
const deviceMatchList = targets.map(async (target) => {
|
||||||
deviceCsrFilePath,
|
const isMatch = await this.iOSDeviceHasMatchingCSR(
|
||||||
target.udid,
|
deviceCsrFilePath,
|
||||||
appName,
|
target.udid,
|
||||||
csr,
|
appName,
|
||||||
).then((isMatch) => {
|
csr,
|
||||||
return {id: target.udid, isMatch};
|
);
|
||||||
}),
|
return {id: target.udid, isMatch};
|
||||||
);
|
});
|
||||||
return Promise.all(deviceMatchList).then((devices) => {
|
return Promise.all(deviceMatchList).then((devices) => {
|
||||||
const matchingIds = devices.filter((m) => m.isMatch).map((m) => m.id);
|
const matchingIds = devices.filter((m) => m.isMatch).map((m) => m.id);
|
||||||
if (matchingIds.length == 0) {
|
if (matchingIds.length == 0) {
|
||||||
throw new Error(`No matching device found for app: ${appName}`);
|
throw new Error(`No matching device found for app: ${appName}`);
|
||||||
}
|
}
|
||||||
return matchingIds[0];
|
return matchingIds[0];
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private androidDeviceHasMatchingCSR(
|
private androidDeviceHasMatchingCSR(
|
||||||
@@ -477,7 +472,7 @@ export default class CertificateProvider {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private iOSDeviceHasMatchingCSR(
|
private async iOSDeviceHasMatchingCSR(
|
||||||
directory: string,
|
directory: string,
|
||||||
deviceId: string,
|
deviceId: string,
|
||||||
bundleId: string,
|
bundleId: string,
|
||||||
@@ -486,71 +481,54 @@ export default class CertificateProvider {
|
|||||||
const originalFile = this.getRelativePathInAppContainer(
|
const originalFile = this.getRelativePathInAppContainer(
|
||||||
path.resolve(directory, csrFileName),
|
path.resolve(directory, csrFileName),
|
||||||
);
|
);
|
||||||
return tmpDir({unsafeCleanup: true})
|
const dir = await tmpDir({unsafeCleanup: true});
|
||||||
.then((dir) => {
|
await iosUtil.pull(
|
||||||
return iosUtil
|
deviceId,
|
||||||
.pull(deviceId, originalFile, bundleId, dir, this.config.idbPath)
|
originalFile,
|
||||||
.then(() => dir);
|
bundleId,
|
||||||
})
|
dir,
|
||||||
.then((dir) => {
|
this.config.idbPath,
|
||||||
return fs
|
);
|
||||||
.readdir(dir)
|
const items = await fs.readdir(dir);
|
||||||
.then((items) => {
|
if (items.length > 1) {
|
||||||
if (items.length > 1) {
|
throw new Error('Conflict in temp dir');
|
||||||
throw new Error('Conflict in temp dir');
|
}
|
||||||
}
|
if (items.length === 0) {
|
||||||
if (items.length === 0) {
|
throw new Error('Failed to pull CSR from device');
|
||||||
throw new Error('Failed to pull CSR from device');
|
}
|
||||||
}
|
const fileName = items[0];
|
||||||
return items[0];
|
const copiedFile = path.resolve(dir, fileName);
|
||||||
})
|
console.debug('Trying to read CSR from', copiedFile);
|
||||||
.then((fileName) => {
|
const data = await fs.readFile(copiedFile);
|
||||||
const copiedFile = path.resolve(dir, fileName);
|
const csrFromDevice = this.santitizeString(data.toString());
|
||||||
console.debug('Trying to read CSR from', copiedFile);
|
return csrFromDevice === this.santitizeString(csr);
|
||||||
return fs
|
|
||||||
.readFile(copiedFile)
|
|
||||||
.then((data) => this.santitizeString(data.toString()));
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then((csrFromDevice) => csrFromDevice === this.santitizeString(csr));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private santitizeString(csrString: string): string {
|
private santitizeString(csrString: string): string {
|
||||||
return csrString.replace(/\r/g, '').trim();
|
return csrString.replace(/\r/g, '').trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
extractAppNameFromCSR(csr: string): Promise<string> {
|
async extractAppNameFromCSR(csr: string): Promise<string> {
|
||||||
return this.writeToTempFile(csr)
|
const path = await this.writeToTempFile(csr);
|
||||||
.then((path) =>
|
const subject = await openssl('req', {
|
||||||
openssl('req', {
|
in: path,
|
||||||
in: path,
|
noout: true,
|
||||||
noout: true,
|
subject: true,
|
||||||
subject: true,
|
nameopt: true,
|
||||||
nameopt: true,
|
RFC2253: false,
|
||||||
RFC2253: false,
|
});
|
||||||
}).then((subject) => {
|
await fs.unlink(path);
|
||||||
return [path, subject];
|
const matches = subject.trim().match(x509SubjectCNRegex);
|
||||||
}),
|
if (!matches || matches.length < 2) {
|
||||||
)
|
throw new Error(`Cannot extract CN from ${subject}`);
|
||||||
.then(async ([path, subject]) => {
|
}
|
||||||
await fs.unlink(path);
|
const appName = matches[1];
|
||||||
return subject;
|
if (!appName.match(allowedAppNameRegex)) {
|
||||||
})
|
throw new Error(
|
||||||
.then((subject) => {
|
`Disallowed app name in CSR: ${appName}. Only alphanumeric characters and '.' allowed.`,
|
||||||
const matches = subject.trim().match(x509SubjectCNRegex);
|
);
|
||||||
if (!matches || matches.length < 2) {
|
}
|
||||||
throw new Error(`Cannot extract CN from ${subject}`);
|
return appName;
|
||||||
}
|
|
||||||
return matches[1];
|
|
||||||
})
|
|
||||||
.then((appName) => {
|
|
||||||
if (!appName.match(allowedAppNameRegex)) {
|
|
||||||
throw new Error(
|
|
||||||
`Disallowed app name in CSR: ${appName}. Only alphanumeric characters and '.' allowed.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return appName;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadSecureServerConfig(): Promise<SecureServerConfig> {
|
async loadSecureServerConfig(): Promise<SecureServerConfig> {
|
||||||
@@ -691,10 +669,10 @@ export default class CertificateProvider {
|
|||||||
.then((_) => undefined);
|
.then((_) => undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
private writeToTempFile(content: string): Promise<string> {
|
private async writeToTempFile(content: string): Promise<string> {
|
||||||
return tmpFile().then((path) =>
|
const path = await tmpFile();
|
||||||
fs.writeFile(path, content).then((_) => path),
|
await fs.writeFile(path, content);
|
||||||
);
|
return path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user