Skip to content

Commit 589bec2

Browse files
committed
nodeify the authorization script and update readme
1 parent f46d77d commit 589bec2

File tree

5 files changed

+94
-65
lines changed

5 files changed

+94
-65
lines changed

README.md

+21-10
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ Change into your local repo clone and install packages using following commands:
2121

2222
First two commands will make test and build tools available (sudo may not be necessary if you installed node.js through homebrew). The third command will install all app dependencies.
2323

24-
To avoid a security dialog that can appear when launching your iOS app, you need to modify your /etc/authorization file. You can do this by settings the element following <allow-root> under <key>system.privilege.taskport</key> to <true/> or by running the supplied python script (at your own risk)
24+
To avoid a security dialog that can appear when launching your iOS app, you need to modify your /etc/authorization file. You can do this by settings the element following <allow-root> under <key>system.privilege.taskport</key> to <true/> or by running the supplied grunt task (at your own risk)
2525

26-
> sudo python authorize.py
26+
> sudo grunt authorize
2727

2828
Quick Start
2929
-----------
@@ -36,20 +36,19 @@ Build an app:
3636
> grunt buildApp:UICatalog
3737
> grunt buildApp:TestApp
3838

39-
Start it:
40-
41-
> grunt appium:TestApp &
42-
43-
Run functional tests (make sure Appium server is not running as this command
44-
runs it for the duration of the test):
39+
Run functional tests against TestApp:
4540

4641
> grunt functional
4742

48-
Run unit tests:
43+
Run unit tests against TestApp:
4944

5045
> grunt unit
5146

52-
Run all tests:
47+
Run tests against UICatalog:
48+
49+
> grunt uicatalog
50+
51+
Run all tests against TestApp and UICatalog:
5352

5453
> grunt test
5554

@@ -61,6 +60,18 @@ Before commiting code please run grunt to run test and check your changes agains
6160

6261
Done, without errors.
6362

63+
More things
64+
-----------
65+
If you want to run the appium server and have it listen indefinitely, you can
66+
do one of the following:
67+
68+
> grunt appium:TestApp
69+
> grunt appium:UICatalog
70+
71+
Then you can, e.g., run individual testfiles using Mocha directly:
72+
73+
> mocha -t 60000 -R spec test/functional/simple.js
74+
6475
Using with a [Bitbeambot](http://bitbeam.org)
6576
-----------
6677

authorize.py

-54
This file was deleted.

grunt-helpers.js

+65
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ var _ = require("underscore")
44
, server = require('./server.js')
55
, fs = require('fs')
66
, path = require('path')
7+
, temp = require('temp')
8+
, difflib = require('difflib')
9+
, prompt = require('prompt')
10+
, exec = require('child_process').exec
711
, spawn = require('child_process').spawn;
812

913
module.exports.startAppium = function(appName, verbose, readyCb, doneCb) {
@@ -77,3 +81,64 @@ module.exports.runMochaTests = function(grunt, appName, testType, cb) {
7781
});
7882

7983
};
84+
85+
module.exports.authorize = function(grunt, cb) {
86+
// somewhat messily ported from lukeis's authorize.py
87+
var authFile = '/etc/authorization';
88+
exec('DevToolsSecurity --enable', function(err, stdout, stderr) {
89+
if (err) throw err;
90+
fs.readFile(authFile, 'utf8', function(err, data) {
91+
if (err) throw err;
92+
var origData = data;
93+
var re = /<key>system.privilege.taskport<\/key>\s*\n\s*<dict>\n\s*<key>allow-root<\/key>\n\s*(<[^>]+>)/;
94+
var match = re.exec(data);
95+
if (!match) {
96+
grunt.fatal("Could not find the system.privilege.taskport key in /etc/authorization");
97+
} else {
98+
if (!(/<false\/>/.exec(match[0]))) {
99+
grunt.fatal("/etc/authorization has already been modified to support appium");
100+
} else {
101+
var newText = match[0].replace(match[1], '<true/>');
102+
var newContent = data.replace(match[0], newText);
103+
temp.open('authorization.backup.', function (err, info) {
104+
fs.write(info.fd, origData);
105+
fs.close(info.fd, function(err) {
106+
if (err) throw err;
107+
grunt.log.writeln("Backed up to " + info.path);
108+
var diff = difflib.contextDiff(origData.split("\n"), newContent.split("\n"), {fromfile: "before", tofile: "after"});
109+
grunt.log.writeln("Check this diff to make sure the change looks cool:");
110+
grunt.log.writeln(diff.join("\n"));
111+
prompt.start();
112+
var promptProps = {
113+
properties: {
114+
proceed: {
115+
pattern: /^(y|n)/
116+
, description: "Make changes? [y/n] "
117+
}
118+
}
119+
};
120+
prompt.get(promptProps, function(err, result) {
121+
if (result.proceed == "y") {
122+
fs.writeFile(authFile, newContent, function(err) {
123+
if (err) {
124+
if (err.code === "EACCES") {
125+
grunt.fatal("You need to run this as sudo!");
126+
} else {
127+
throw err;
128+
}
129+
}
130+
grunt.log.writeln("Wrote new /etc/authorization");
131+
cb();
132+
});
133+
} else {
134+
grunt.log.writeln("No changes were made");
135+
cb();
136+
}
137+
});
138+
});
139+
});
140+
}
141+
}
142+
});
143+
});
144+
};

grunt.js

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var build = require('./build.js')
66
, exec = require('child_process').exec
77
, gruntHelpers = require('./grunt-helpers.js')
88
, startAppium = gruntHelpers.startAppium
9+
, authorize = gruntHelpers.authorize
910
, runTestsWithServer = gruntHelpers.runTestsWithServer
1011
, fs = require('fs');
1112

@@ -107,4 +108,7 @@ module.exports = function(grunt) {
107108
}
108109
});
109110
});
111+
grunt.registerTask('authorize', "Authorize developer", function() {
112+
authorize(grunt, this.async());
113+
});
110114
};

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
"assert": "~0.4.9",
4545
"grunt-mocha-test": "0.0.1",
4646
"request": "~2.12.0",
47-
"winston": "~0.6.2"
47+
"winston": "~0.6.2",
48+
"temp": "~0.5.0",
49+
"difflib": "~0.2.4",
50+
"prompt": "~0.2.9"
4851
}
4952
}

0 commit comments

Comments
 (0)