UNPKG

appium-ios-simulator

Version:
76 lines 3.11 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isBiometricEnrolled = isBiometricEnrolled; exports.enrollBiometric = enrollBiometric; exports.sendBiometricMatch = sendBiometricMatch; exports.toBiometricDomainComponent = toBiometricDomainComponent; const lodash_1 = __importDefault(require("lodash")); const ENROLLMENT_NOTIFICATION_RECEIVER = 'com.apple.BiometricKit.enrollmentChanged'; const BIOMETRICS = { touchId: 'fingerTouch', faceId: 'pearl', }; /** * @returns Promise that resolves to true if biometric is enrolled */ async function isBiometricEnrolled() { const { stdout } = await this.simctl.spawnProcess([ 'notifyutil', '-g', ENROLLMENT_NOTIFICATION_RECEIVER ]); const match = (new RegExp(`${lodash_1.default.escapeRegExp(ENROLLMENT_NOTIFICATION_RECEIVER)}\\s+([01])`)) .exec(stdout); if (!match) { throw new Error(`Cannot parse biometric enrollment state from '${stdout}'`); } this.log.info(`Current biometric enrolled state for ${this.udid} Simulator: ${match[1]}`); return match[1] === '1'; } /** * @param isEnabled Whether to enable biometric enrollment */ async function enrollBiometric(isEnabled = true) { this.log.debug(`Setting biometric enrolled state for ${this.udid} Simulator to '${isEnabled ? 'enabled' : 'disabled'}'`); await this.simctl.spawnProcess([ 'notifyutil', '-s', ENROLLMENT_NOTIFICATION_RECEIVER, isEnabled ? '1' : '0' ]); await this.simctl.spawnProcess([ 'notifyutil', '-p', ENROLLMENT_NOTIFICATION_RECEIVER ]); if (await this.isBiometricEnrolled() !== isEnabled) { throw new Error(`Cannot set biometric enrolled state for ${this.udid} Simulator to '${isEnabled ? 'enabled' : 'disabled'}'`); } } /** * Sends a notification to match/not match the particular biometric. * * @param shouldMatch Set it to true or false in order to emulate * matching/not matching the corresponding biometric * @param biometricName Either touchId or faceId (faceId is only available since iOS 11) */ async function sendBiometricMatch(shouldMatch = true, biometricName = 'touchId') { const domainComponent = toBiometricDomainComponent(biometricName); const domain = `com.apple.BiometricKit_Sim.${domainComponent}.${shouldMatch ? '' : 'no'}match`; await this.simctl.spawnProcess([ 'notifyutil', '-p', domain ]); this.log.info(`Sent notification ${domain} to ${shouldMatch ? 'match' : 'not match'} ${biometricName} biometric ` + `for ${this.udid} Simulator`); } /** * @param name Biometric name (touchId or faceId) * @returns Domain component string */ function toBiometricDomainComponent(name) { if (!BIOMETRICS[name]) { throw new Error(`'${name}' is not a valid biometric. Use one of: ${JSON.stringify(lodash_1.default.keys(BIOMETRICS))}`); } return BIOMETRICS[name]; } //# sourceMappingURL=biometric.js.map