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/06 22:03:02 UTC
[5/6] git commit: adding access whitelist api to config_parser
adding access whitelist api to config_parser
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/commit/d774d5d2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/d774d5d2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/d774d5d2
Branch: refs/heads/cordova-client
Commit: d774d5d2cac4605541c6d1ba166f9b6c9e25012c
Parents: c7bc488
Author: Fil Maj <ma...@gmail.com>
Authored: Mon Nov 5 18:17:42 2012 -0800
Committer: Fil Maj <ma...@gmail.com>
Committed: Mon Nov 5 18:17:42 2012 -0800
----------------------------------------------------------------------
spec/config_parser.spec.js | 36 ++++++++++++++++++++++++++++++++++++
src/config_parser.js | 24 ++++++++++++++++++++++++
templates/www/config.xml | 5 ++---
3 files changed, 62 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/d774d5d2/spec/config_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/config_parser.spec.js b/spec/config_parser.spec.js
index 7afeedb..1791beb 100644
--- a/spec/config_parser.spec.js
+++ b/spec/config_parser.spec.js
@@ -63,4 +63,40 @@ describe('config.xml parser', function () {
expect(fs.readFileSync(xml, 'utf-8')).toMatch(/<name>one toke over the line<\/name>/);
});
});
+
+ describe('access elements (whitelist)', function() {
+ var cfg;
+
+ beforeEach(function() {
+ cfg = new config_parser(xml);
+ });
+
+ describe('getter', function() {
+ it('should get the (default) access element', function() {
+ expect(cfg.access.get()[0]).toEqual('*');
+ });
+ it('should return an array of all access origin uris via access()', function() {
+ expect(cfg.access.get() instanceof Array).toBe(true);
+ });
+ });
+ describe('setters', function() {
+ it('should allow removing a uri from the access list', function() {
+ cfg.access.remove('*');
+ expect(cfg.access.get().length).toEqual(0);
+ });
+ it('should write to disk after removing a uri', function() {
+ cfg.access.remove('*');
+ expect(fs.readFileSync(xml, 'utf-8')).not.toMatch(/<access.*\/>/);
+ });
+ it('should allow adding a new uri to the access list', function() {
+ cfg.access.add('http://canucks.com');
+ expect(cfg.access.get().length).toEqual(2);
+ expect(cfg.access.get().indexOf('http://canucks.com') > -1).toBe(true);
+ });
+ it('should write to disk after adding a uri', function() {
+ cfg.access.add('http://cordova.io');
+ expect(fs.readFileSync(xml, 'utf-8')).toMatch(/<access origin="http:\/\/cordova\.io/);
+ });
+ });
+ });
});
http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/d774d5d2/src/config_parser.js
----------------------------------------------------------------------
diff --git a/src/config_parser.js b/src/config_parser.js
index 59ddce0..ecd12e5 100644
--- a/src/config_parser.js
+++ b/src/config_parser.js
@@ -4,6 +4,7 @@ var et = require('elementtree'),
function config_parser(path) {
this.path = path;
this.doc = new et.ElementTree(et.XML(fs.readFileSync(path, 'utf-8')));
+ this.access = new access(this);
}
config_parser.prototype = {
@@ -24,4 +25,27 @@ config_parser.prototype = {
}
};
+function access(cfg) {
+ this.config = cfg;
+};
+
+access.prototype = {
+ add:function(uri) {
+ var el = new et.Element('access');
+ el.attrib.origin = uri;
+ this.config.doc.getroot().append(el);
+ this.config.update();
+ },
+ remove:function(uri) {
+ var self = this;
+ this.config.doc.findall('access[@origin="' + uri + '"]').forEach(function(a) {
+ self.config.doc.getroot().remove(0, a);
+ });
+ this.config.update();
+ },
+ get:function() {
+ return this.config.doc.findall('access').map(function(a) { return a.attrib.origin; });
+ }
+};
+
module.exports = config_parser;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/d774d5d2/templates/www/config.xml
----------------------------------------------------------------------
diff --git a/templates/www/config.xml b/templates/www/config.xml
index fa3369d..206bc56 100644
--- a/templates/www/config.xml
+++ b/templates/www/config.xml
@@ -13,9 +13,6 @@
Apache Cordova Team
</author>
- <platforms>
- </platforms>
-
<icon src="res/icon/cordova_512.png" width="512" height="512" />
<icon src="res/icon/cordova_android_96.png" width="96" height="96" gap:platform="android" />
<icon src="res/icon/cordova_bb_80.png" width="80" height="80" gap:platform="blackberry" />
@@ -47,4 +44,6 @@
<preference name="orientation" value="default" />
<preference name="target-device" value="universal" />
<preference name="fullscreen" value="false" />
+
+ <access origin="*" />
</widget>