You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/11/28 19:16:23 UTC

[16/50] git commit: ios projects now adhere to whitelist specified by config.xml

ios projects now adhere to whitelist specified by config.xml


Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/f58c26eb
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/f58c26eb
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/f58c26eb

Branch: refs/heads/master
Commit: f58c26eb6c50de11c073785a4091cbf316d4d086
Parents: d774d5d
Author: Fil Maj <ma...@gmail.com>
Authored: Tue Nov 6 12:26:27 2012 -0800
Committer: Fil Maj <ma...@gmail.com>
Committed: Tue Nov 6 12:26:27 2012 -0800

----------------------------------------------------------------------
 package.json                               |    1 +
 spec/fixtures/projects/test/www/config.xml |    1 +
 spec/metadata/ios_parser.spec.js           |   28 ++++++++++++++++------
 src/metadata/ios_parser.js                 |   14 +++++++++--
 4 files changed, 33 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/f58c26eb/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 6d6d235..6c16b97 100644
--- a/package.json
+++ b/package.json
@@ -24,6 +24,7 @@
     "colors":">=0.6.0",
     "elementtree":"0.1.3",
     "pluginstall":"git://github.com/imhotep/pluginstall.git#0.5.2",
+    "plist":"git://github.com/filmaj/node-plist.git",
     "xcode":"0.5.1",
     "express":"3.0",
     "shelljs":"0.0.7",

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/f58c26eb/spec/fixtures/projects/test/www/config.xml
----------------------------------------------------------------------
diff --git a/spec/fixtures/projects/test/www/config.xml b/spec/fixtures/projects/test/www/config.xml
index 1cec68b..84b4137 100644
--- a/spec/fixtures/projects/test/www/config.xml
+++ b/spec/fixtures/projects/test/www/config.xml
@@ -1,4 +1,5 @@
 <?xml version='1.0' encoding='utf-8'?>
 <widget id="io.cordova.hellocordova" version="2.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
     <name>bond. james bond.</name>
+    <access origin="*" />
 </widget>

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/f58c26eb/spec/metadata/ios_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/metadata/ios_parser.spec.js b/spec/metadata/ios_parser.spec.js
index 2914604..e89dccb 100644
--- a/spec/metadata/ios_parser.spec.js
+++ b/spec/metadata/ios_parser.spec.js
@@ -8,13 +8,15 @@ var ios_parser = require('../../src/metadata/ios_parser'),
     ios_path = path.join(__dirname, '..', 'fixtures', 'projects', 'native', 'ios'),
     tempDir = path.join(__dirname, '..', '..', 'temp'),
     ios_plist = path.join(ios_path, 'balls', 'balls-Info.plist'),
-    ios_pbx = path.join(ios_path, 'balls.xcodeproj', 'project.pbxproj');
+    ios_pbx = path.join(ios_path, 'balls.xcodeproj', 'project.pbxproj'),
+    cordova_plist = path.join(ios_path, 'balls', 'Cordova.plist');
 
 var cwd = process.cwd();
 
 var original_pbx = fs.readFileSync(ios_pbx, 'utf-8');
 var original_plist = fs.readFileSync(ios_plist, 'utf-8');
 var original_config = fs.readFileSync(cfg_path, 'utf-8');
+var orig_cordova = fs.readFileSync(cordova_plist, 'utf-8');
 
 describe('ios project parser', function() {
     it('should throw an exception with a path that is not a native ios project', function() {
@@ -39,6 +41,9 @@ describe('ios project parser', function() {
         });
         afterEach(function() {
             fs.writeFileSync(ios_pbx, original_pbx, 'utf-8');
+            fs.writeFileSync(cordova_plist, orig_cordova, 'utf-8');
+            fs.writeFileSync(ios_plist, original_plist, 'utf-8');
+            fs.writeFileSync(cfg_path, original_config, 'utf-8');
         });
         it('should throw an exception if a non config_parser object is passed into it', function() {
             expect(function() {
@@ -47,9 +52,6 @@ describe('ios project parser', function() {
         });
         it('should update the application name properly', function() {
             var cb = jasmine.createSpy();
-            this.after(function() {
-                fs.writeFileSync(ios_pbx, original_pbx, 'utf-8');
-            });
 
             runs(function() {
                 config.name('bond. james bond.');
@@ -65,10 +67,6 @@ describe('ios project parser', function() {
         });
         it('should update the application package name (bundle identifier) properly', function() {
             var cb = jasmine.createSpy();
-            this.after(function() {
-                fs.writeFileSync(ios_plist, original_plist, 'utf-8');
-                fs.writeFileSync(cfg_path, original_config, 'utf-8');
-            });
 
             runs(function() {
                 config.packageName('ca.filmaj.dewd');
@@ -82,6 +80,20 @@ describe('ios project parser', function() {
                 expect(plist_contents).toMatch(/<string>ca.filmaj.dewd/);
             });
         });
+        it('should update the externalhosts whitelist properly', function() {
+            var cb = jasmine.createSpy();
+
+            runs(function() {
+                project.update_from_config(config, cb);
+            });
+
+            waitsFor(function() { return cb.wasCalled; }, "update_from_config callback");
+
+            runs(function() {
+                var plist_contents = fs.readFileSync(cordova_plist, 'utf-8');
+                expect(plist_contents).toMatch(/<key>ExternalHosts<\/key>\s*<array>\s*<string>\*<\/string>/);
+            });
+        });
     });
 
     describe('update_www method', function() {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/f58c26eb/src/metadata/ios_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/ios_parser.js b/src/metadata/ios_parser.js
index 7581185..2531c26 100644
--- a/src/metadata/ios_parser.js
+++ b/src/metadata/ios_parser.js
@@ -3,6 +3,7 @@ var fs   = require('fs'),
     xcode = require('xcode'),
     util = require('../util'),
     shell = require('shelljs'),
+    plist = require('plist'),
     config_parser = require('../config_parser');
 
 module.exports = function ios_parser(project) {
@@ -28,9 +29,16 @@ module.exports.prototype = {
 
         // Update package id (bundle id)
         var plistFile = path.join(this.cordovaproj, this.originalName + '-Info.plist');
-        var contents = fs.readFileSync(plistFile, 'utf-8');
-        contents = contents.replace(/<key>CFBundleIdentifier<\/key>\s*<string>.*<\/string>/i, '<key>CFBundleIdentifier</key><string>' + pkg + '</string>');
-        fs.writeFileSync(plistFile, contents, 'utf-8');
+        var infoPlist = plist.parseFileSync(plistFile);
+        infoPlist['CFBundleIdentifier'] = pkg;
+        fs.writeFileSync(plistFile, plist.build(infoPlist), 'utf-8');
+
+        // Update whitelist
+        var cordovaPlist = path.join(this.cordovaproj, 'Cordova.plist');
+        var contents = plist.parseFileSync(cordovaPlist);
+        var whitelist = config.access.get();
+        contents['ExternalHosts'] = whitelist;
+        fs.writeFileSync(cordovaPlist, plist.build(contents), 'utf-8');
 
         // Update product name
         var proj = new xcode.project(this.pbxproj);