From 7099dec5bd6bd48e892ce5843d78c34612ceb66c Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sat, 25 Nov 2023 10:40:46 -0800 Subject: [PATCH] chore: use whilelist --- lib/extensions/permissions.js | 27 +++++++++++--------------- test/functional/simulator-e2e-specs.js | 10 ++++------ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/lib/extensions/permissions.js b/lib/extensions/permissions.js index 77b7cae..f6dda1b 100644 --- a/lib/extensions/permissions.js +++ b/lib/extensions/permissions.js @@ -14,19 +14,13 @@ const STATUS = Object.freeze({ const WIX_SIM_UTILS = 'applesimutils'; -const WIX_SERVICE_NAMES = [ - // 'contacts' permission does not work well with the privacy command while the help description addresses the command support 'contacts' - // Confirmed up to with Xcode 15 and iOS 17 - `contacts`, - - // Below services have not supported by the privacy command by Apple yet. - 'camera', - 'faceid', - 'health', - 'homekit', - 'notifications', - 'speech', - 'userTracking' +// `location` permission does not work with WIX/applesimutils. +// Note that except for 'contacts', the Apple's privacy command sets +// permissions properly but it resets the app process while WIX/applesimutils does not +// reset the app process. +const APPLE_PRIVACY_CMD = [ + 'location', + 'location-always' ]; const SERVICES = Object.freeze({ @@ -103,10 +97,11 @@ async function execWix (args) { * @param {string} udid - udid of the target simulator device. * @param {string} bundleId - bundle identifier of the target application. * @param {Object} permissionsMapping - An object, where keys are service names - * and values are corresponding state values. Services listed in WIX_SERVICE_NAMES - * will be set by WIX_SIM_UTILS otherwise via `xcrun simctl privacy` command by Apple. + * and values are corresponding state values. Services listed in APPLE_PRIVACY_CMD + * will be set with `xcrun simctl privacy` command by Apple otherwise AppleSimulatorUtils by WIX. * See the result of `xcrun simctl privacy` and https://github.com/wix/AppleSimulatorUtils * for more details on available service names and statuses. + * Note that the `xcrun simctl privacy` command kill the app process. * @throws {Error} If there was an error while changing permissions. */ async function setAccess (simctl, udid, bundleId, permissionsMapping) { @@ -117,7 +112,7 @@ async function setAccess (simctl, udid, bundleId, permissionsMapping) { const resetPermissions = []; for (const serviceName in permissionsMapping) { - if (WIX_SERVICE_NAMES.includes(serviceName)) { + if (!APPLE_PRIVACY_CMD.includes(serviceName)) { wixPermissions[serviceName] = permissionsMapping[serviceName]; } else { switch (permissionsMapping[serviceName]) { diff --git a/test/functional/simulator-e2e-specs.js b/test/functional/simulator-e2e-specs.js index 9e5a494..3106fda 100644 --- a/test/functional/simulator-e2e-specs.js +++ b/test/functional/simulator-e2e-specs.js @@ -352,12 +352,10 @@ describe('advanced features', function () { describe('Permission', function () { it('should set and get with simctrl privacy command', async function () { - await sim.setPermission('com.apple.Maps', 'microphone', 'yes'); - await sim.getPermission('com.apple.Maps', 'microphone').should.eventually.eql('yes'); - await sim.setPermission('com.apple.Maps', 'microphone', 'no'); - await sim.getPermission('com.apple.Maps', 'microphone').should.eventually.eql('no'); - await sim.setPermission('com.apple.Maps', 'microphone', 'unset'); - await sim.getPermission('com.apple.Maps', 'microphone').should.eventually.eql('unset'); + // no exceptions + await sim.setPermission('com.apple.Maps', 'location', 'yes').should.eventually.be.true; + await sim.setPermission('com.apple.Maps', 'location', 'no').should.eventually.be.true; + await sim.setPermission('com.apple.Maps', 'location', 'unset').should.eventually.be.true; }); it('should set and get with wix command', async function () {