UNPKG

appium-ios-simulator

Version:
82 lines 3.28 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', }; /** * @this {CoreSimulatorWithBiometric} * @returns {Promise<boolean>} */ 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'; } /** * @this {CoreSimulatorWithBiometric} * @param {boolean} isEnabled */ 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. * * @this {CoreSimulatorWithBiometric} * @param {boolean} shouldMatch [true] - Set it to true or false in order to emulate * matching/not matching the corresponding biometric * @param {string} biometricName [touchId] - 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 {string} name * @returns {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]; } /** * @typedef {import('../types').CoreSimulator & import('../types').SupportsBiometric} CoreSimulatorWithBiometric */ //# sourceMappingURL=biometric.js.map