async function main () { await exportTranslations(); const zipPath = await tempDir.path({prefix: 'translations', suffix: '.zip'}); try { await downloadTranslations(zipPath); const tmpRoot = await tempDir.openDir(); try { await zip.extractAllTo(zipPath, tmpRoot); for (const name of await fs.readdir(tmpRoot)) { const currentPath = path.join(tmpRoot, name); if (!(await fs.stat(currentPath)).isDirectory() || name === ORIGINAL_LANGUAGE) { continue; } const dstPath = path.resolve(RESOURCES_ROOT, name); if (await fs.exists(dstPath)) { await fs.rimraf(dstPath); } await fs.mv(currentPath, path.resolve(RESOURCES_ROOT, name), { mkdirp: true }); log.info(`Successfully updated resources for the '${name}' language`); } } finally { await fs.rimraf(tmpRoot); } } finally { await fs.rimraf(zipPath); } }
async function unzipFile (zipPath) { log.debug(`Unzipping ${zipPath}`); try { await assertZipArchive(zipPath); if (system.isWindows()) { await zip.extractAllTo(zipPath, path.dirname(zipPath)); log.debug("Unzip successful"); } else { await exec('unzip', ['-o', zipPath], {cwd: path.dirname(zipPath)}); log.debug("Unzip successful"); } } catch (e) { throw new Error(`Error occurred while unzipping. Original error: ${e.message}`); } }
apkSigningMethods.checkApkKeystoreMatch = async function (keytool, md5re, keystoreHash, pkg, apk) { let entryHash = null; let rsa = /^META-INF\/.*\.[rR][sS][aA]$/; let foundKeystoreMatch = false; //for (let entry of entries) { await zip.readEntries(apk, async ({entry, extractEntryTo}) => { entry = entry.fileName; if (!rsa.test(entry)) { return; } log.debug(`Entry: ${entry}`); let entryPath = path.join(this.tmpDir, pkg, 'cert'); log.debug(`entryPath: ${entryPath}`); let entryFile = path.join(entryPath, entry); log.debug(`entryFile: ${entryFile}`); // ensure /tmp/pkg/cert/ doesn't exist or extract will fail. await fs.rimraf(entryPath); // META-INF/CERT.RSA await extractEntryTo(entryPath); log.debug("extracted!"); // check for match log.debug("Printing apk md5."); let {stdout} = await exec(keytool, ['-v', '-printcert', '-file', entryFile]); entryHash = md5re.exec(stdout); entryHash = entryHash ? entryHash[1] : null; log.debug(`entryHash MD5: ${entryHash}`); log.debug(`keystore MD5: ${keystoreHash}`); let matchesKeystore = entryHash && entryHash === keystoreHash; log.debug(`Matches keystore? ${matchesKeystore}`); // If we have a keystore match, stop iterating if (matchesKeystore) { foundKeystoreMatch = true; return false; } }); return foundKeystoreMatch; };
/** * Get the content of given file or folder from iOS Simulator and return it as base-64 encoded string. * Folder content is recursively packed into a zip archive. * * @param {Object} device - The device object, which represents the device under test. * This object is expected to have the `udid` property containing the * valid device ID. * @param {string} remotePath - The path to a file or a folder, which exists in the corresponding application * container on Simulator. Use * @<app_bundle_id>:<optional_container_type>/<path_to_the_file_or_folder_inside_container> * format to pull a file or a folder from an application container of the given type. * Possible container types are 'app', 'data', 'groups', '<A specific App Group container>'. * The default type is 'app'. * @param {boolean} isFile - Whether the destination item is a file or a folder * @returns {string} Base-64 encoded content of the file. */ async function pullFromSimulator (device, remotePath, isFile) { let pathOnServer; if (CONTAINER_PATH_PATTERN.test(remotePath)) { const [bundleId, dstPath] = await parseContainerPath(remotePath, async (appBundle, containerType) => await getAppContainer(device.udid, appBundle, null, containerType)); log.info(`Parsed bundle identifier '${bundleId}' from '${remotePath}'. ` + `Will get the data from '${dstPath}'`); pathOnServer = dstPath; } else { const simRoot = device.getDir(); pathOnServer = path.posix.join(simRoot, remotePath); verifyIsSubPath(pathOnServer, simRoot); log.info(`Got the full item path: ${pathOnServer}`); } if (!await fs.exists(pathOnServer)) { log.errorAndThrow(`The remote ${isFile ? 'file' : 'folder'} at '${pathOnServer}' does not exist`); } const buffer = isFile ? await fs.readFile(pathOnServer) : await zip.toInMemoryZip(pathOnServer); return Buffer.from(buffer).toString('base64'); }
/** * Get the content of given file or folder from the real device under test and return it as base-64 encoded string. * Folder content is recursively packed into a zip archive. * * @param {Object} device - The device object, which represents the device under test. * This object is expected to have the `udid` property containing the * valid device ID. * @param {string} remotePath - The path to an existing remote file on the device. This variable can be prefixed with * bundle id, so then the file will be downloaded from the corresponding * application container instead of the default media folder, for example * '@com.myapp.bla/RelativePathInContainer/111.png'. The '@' character at the * beginning of the argument is mandatory in such case. * @param {boolean} isFile - Whether the destination item is a file or a folder * @return {string} Base-64 encoded content of the remote file */ async function pullFromRealDevice (device, remotePath, isFile) { await verifyIFusePresence(); const mntRoot = await tempDir.openDir(); let isUnmountSuccessful = true; try { let dstPath = path.resolve(mntRoot, remotePath); let ifuseArgs = ['-u', device.udid, mntRoot]; if (CONTAINER_PATH_PATTERN.test(remotePath)) { const [bundleId, pathInContainer] = await parseContainerPath(remotePath, mntRoot); dstPath = pathInContainer; log.info(`Parsed bundle identifier '${bundleId}' from '${remotePath}'. ` + `Will get the data from '${dstPath}'`); ifuseArgs = ['-u', device.udid, '--container', bundleId, mntRoot]; } else { verifyIsSubPath(dstPath, mntRoot); } await mountDevice(device, ifuseArgs); isUnmountSuccessful = false; try { if (!await fs.exists(dstPath)) { log.errorAndThrow(`The remote ${isFile ? 'file' : 'folder'} at '${dstPath}' does not exist`); } const buffer = isFile ? await fs.readFile(dstPath) : await zip.toInMemoryZip(dstPath); return Buffer.from(buffer).toString('base64'); } finally { await exec('umount', [mntRoot]); isUnmountSuccessful = true; } } finally { if (isUnmountSuccessful) { await fs.rimraf(mntRoot); } else { log.warn(`Umount has failed, so not removing '${mntRoot}'`); } } }