Skip to content

Commit

Permalink
use isFeatureEnabled for security features check (appium#989)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlipps authored Jul 2, 2019
1 parent 41c5eb6 commit f771e95
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ Differences are noted here:
|`skipLogCapture`|Skips to start capturing logs such as crash, system, safari console and safari network. It might improve performance such as network. Log related commands will not work. Defaults to `false`. |`true` or `false`|
|`safariGarbageCollect`|Turns on/off Web Inspector garbage collection when executing scripts on Safari. Turning on may improve performance. Defaults to `false`.|`true` or `false`|

## Opt-in Features (With Security Risk)

These can be enabled when running this driver through Appium, via the `--allow-insecure` or `--relaxed-security` flags.

|Feature Name|Description|
|------------|-----------|
|shutdown_other_sims|Allow any session to use a capability to shutdown any running simulators on the host|
|perf_record|Allow recording the system performance and other metrics of the simulator|

## Development<a id="development"></a>

Expand Down
13 changes: 7 additions & 6 deletions lib/commands/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { waitForCondition } from 'asyncbox';

let commands = {};

const PERF_RECORD_FEAT_NAME = 'perf_record';
const RECORDERS_CACHE = {};
const DEFAULT_TIMEOUT_MS = 5 * 60 * 1000;
const STOP_TIMEOUT_MS = 3 * 60 * 1000;
Expand Down Expand Up @@ -62,9 +63,9 @@ async function uploadTrace (localFile, remotePath = null, uploadOptions = {}) {
* @param {?StartPerfRecordOptions} opts - The set of possible start record options
*/
commands.mobileStartPerfRecord = async function mobileStartPerfRecord (opts = {}) {
if (!this.relaxedSecurityEnabled && !this.isRealDevice()) {
log.errorAndThrow(`Appium server must have relaxed security flag set in order ` +
`for Simulator performance measurement to work`);
this.ensureFeatureEnabled(PERF_RECORD_FEAT_NAME);
if (!this.isRealDevice()) {
log.errorAndThrow('Performance measurement is for simulators only');
}

const {
Expand Down Expand Up @@ -170,9 +171,9 @@ commands.mobileStartPerfRecord = async function mobileStartPerfRecord (opts = {}
* has been started before or the resulting .trace file has not been generated properly.
*/
commands.mobileStopPerfRecord = async function mobileStopPerfRecord (opts = {}) {
if (!this.relaxedSecurityEnabled && !this.isRealDevice()) {
log.errorAndThrow(`Appium server must have relaxed security flag set in order ` +
`for Simulator performance measurement to work`);
this.ensureFeatureEnabled(PERF_RECORD_FEAT_NAME);
if (!this.isRealDevice()) {
log.errorAndThrow('Performance measurement is for simulators only');
}

const {
Expand Down
6 changes: 2 additions & 4 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import path from 'path';
import IDB from 'appium-idb';


const SHUTDOWN_OTHER_FEAT_NAME = 'shutdown_other_sims';
const SAFARI_BUNDLE_ID = 'com.apple.mobilesafari';
const WDA_SIM_STARTUP_RETRIES = 2;
const WDA_REAL_DEV_STARTUP_RETRIES = 1;
Expand Down Expand Up @@ -354,10 +355,7 @@ class XCUITestDriver extends BaseDriver {

if (this.isSimulator()) {
if (this.opts.shutdownOtherSimulators) {
if (!this.relaxedSecurityEnabled) {
log.errorAndThrow(`Appium server must have relaxed security flag set in order ` +
`for 'shutdownOtherSimulators' capability to work`);
}
this.ensureFeatureEnabled(SHUTDOWN_OTHER_FEAT_NAME);
await shutdownOtherSimulators(this.opts.device);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
],
"dependencies": {
"@babel/runtime": "^7.0.0",
"appium-base-driver": "^3.0.0",
"appium-base-driver": "^3.17.0",
"appium-idb": "^0.1.0",
"appium-ios-device": "^0.2.1",
"appium-ios-driver": "^4.0.0",
Expand Down

0 comments on commit f771e95

Please sign in to comment.