Skip to content

Commit

Permalink
chore: use whilelist
Browse files Browse the repository at this point in the history
  • Loading branch information
KazuCocoa committed Nov 25, 2023
1 parent c6aa895 commit 7099dec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
27 changes: 11 additions & 16 deletions lib/extensions/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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) {
Expand All @@ -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]) {
Expand Down
10 changes: 4 additions & 6 deletions test/functional/simulator-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 7099dec

Please sign in to comment.