Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #28 from manifoldjs/v0.1.2
Browse files Browse the repository at this point in the history
V0.1.2
  • Loading branch information
msrodri committed Jul 15, 2015
2 parents 0215d75 + 6a08706 commit 8e5b457
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules/
/scripts/node_modules/
npm-debug.log
coverage.html
.ntvs_analysis.dat
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-hostedwebapp",
"version": "0.1.1",
"version": "0.1.2",
"description": "Hosted Web App Plugin",
"cordova": {
"id": "cordova-plugin-hostedwebapp",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-hostedwebapp"
version="0.1.1">
version="0.1.2">
<name>HostedWebApp</name>
<description>Hosted Web App Plugin</description>
<license>MIT License</license>
Expand Down
3 changes: 3 additions & 0 deletions scripts/test/assets/fullUrlForScope/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<widget id="com.example.hello" version="0.0.1">
</widget>
7 changes: 7 additions & 0 deletions scripts/test/assets/fullUrlForScope/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"start_url": "http://wat-docs.azurewebsites.net/",
"name": "WAT Documentation",
"orientation": "landscape",
"display": "fullscreen",
"scope": "http://www.domain.com"
}
2 changes: 0 additions & 2 deletions scripts/test/assets/jsonEmpty/manifest.json

This file was deleted.

3 changes: 3 additions & 0 deletions scripts/test/assets/jsonPropertiesMissing/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"start_url": "http://wat-docs.azurewebsites.net/"
}
1 change: 1 addition & 0 deletions scripts/test/assets/jsonPropertiesMissing/www/empty.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
empty folder
3 changes: 3 additions & 0 deletions scripts/test/assets/wildcardSubdomainForScope/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<widget id="com.example.hello" version="0.0.1">
</widget>
7 changes: 7 additions & 0 deletions scripts/test/assets/wildcardSubdomainForScope/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"start_url": "http://wat-docs.azurewebsites.net/",
"name": "WAT Documentation",
"orientation": "landscape",
"display": "fullscreen",
"scope": "http://*.domain.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
empty folder
50 changes: 44 additions & 6 deletions scripts/test/updateConfigurationBeforePrepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function initializeContext(testDir) {
return ctx;
}

describe('updateConfiguration.js', function (){
describe('updateConfigurationBeforePrepare.js', function (){
beforeEach(function () {
tu.copyRecursiveSync(assetsDirectory, workingDirectory);
});
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('updateConfiguration.js', function (){
});

it('Should not update name if it is missing in manifest.json', function (done) {
var testDir = path.join(workingDirectory, 'jsonEmpty');
var testDir = path.join(workingDirectory, 'jsonPropertiesMissing');
var configXML = path.join(testDir, 'config.xml');
var ctx = initializeContext(testDir);

Expand Down Expand Up @@ -146,7 +146,7 @@ describe('updateConfiguration.js', function (){
});

it('Should not update orientation if it is missing in manifest.json', function (done){
var testDir = path.join(workingDirectory, 'jsonEmpty');
var testDir = path.join(workingDirectory, 'jsonPropertiesMissing');
var configXML = path.join(testDir, 'config.xml');
var ctx = initializeContext(testDir);

Expand Down Expand Up @@ -187,7 +187,7 @@ describe('updateConfiguration.js', function (){
});

it('Should not update fullscreen if it is missing in manifest.json', function (done){
var testDir = path.join(workingDirectory, 'jsonEmpty');
var testDir = path.join(workingDirectory, 'jsonPropertiesMissing');
var configXML = path.join(testDir, 'config.xml');
var ctx = initializeContext(testDir);

Expand All @@ -214,7 +214,7 @@ describe('updateConfiguration.js', function (){
});

it('Should keep existing access rules unchanged in config.xml', function (done){
var testDir = path.join(workingDirectory, 'jsonEmpty');
var testDir = path.join(workingDirectory, 'jsonPropertiesMissing');
var configXML = path.join(testDir, 'config.xml');
var ctx = initializeContext(testDir);

Expand Down Expand Up @@ -267,7 +267,7 @@ describe('updateConfiguration.js', function (){
});
});

it('Should add access rules for scope in config.xml', function (done){
it('Should add access rules for scope in config.xml if scope is a relative URL', function (done){
var testDir = path.join(workingDirectory, 'xmlEmptyWidget');
var configXML = path.join(testDir, 'config.xml');
var ctx = initializeContext(testDir);
Expand All @@ -286,6 +286,44 @@ describe('updateConfiguration.js', function (){
});
});

it('Should add access rules for scope in config.xml if scope is a full URL', function (done){
var testDir = path.join(workingDirectory, 'fullUrlForScope');
var configXML = path.join(testDir, 'config.xml');
var ctx = initializeContext(testDir);

updateConfiguration(ctx).then(function () {
var content = fs.readFileSync(configXML).toString();

// rules for android
assert(content.match(/<platform name="android">[\s\S]*<access hap-rule="yes" origin="http:\/\/www.domain.com\/\*" \/>[\s\S]*<\/platform>/));
assert(content.match(/<platform name="android">[\s\S]*<allow-navigation hap-rule="yes" href="http:\/\/www.domain.com\/\*" \/>[\s\S]*<\/platform>/));

// rules for ios
assert(content.match(/<platform name="ios">[\s\S]*<access hap-rule="yes" origin="http:\/\/www.domain.com\/\*" \/>[\s\S]*<\/platform>/));

done();
});
});

it('Should add access rules for scope in config.xml if scope is a full URL with wildcard as subdomain', function (done){
var testDir = path.join(workingDirectory, 'wildcardSubdomainForScope');
var configXML = path.join(testDir, 'config.xml');
var ctx = initializeContext(testDir);

updateConfiguration(ctx).then(function () {
var content = fs.readFileSync(configXML).toString();

// rules for android
assert(content.match(/<platform name="android">[\s\S]*<access hap-rule="yes" origin="http:\/\/\*.domain.com" \/>[\s\S]*<\/platform>/));
assert(content.match(/<platform name="android">[\s\S]*<allow-navigation hap-rule="yes" href="http:\/\/\*.domain.com" \/>[\s\S]*<\/platform>/));

// rules for ios
assert(content.match(/<platform name="ios">[\s\S]*<access hap-rule="yes" origin="http:\/\/\*.domain.com" \/>[\s\S]*<\/platform>/));

done();
});
});

it('Should add access rules from mjs_access_whitelist list', function (done){
var testDir = path.join(workingDirectory, 'xmlEmptyWidget');
var configXML = path.join(testDir, 'config.xml');
Expand Down
30 changes: 26 additions & 4 deletions scripts/updateConfigurationBeforePrepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,18 @@ function processAccessRules(manifest) {
// determine base rule based on the start_url and the scope
var baseUrlPattern = manifest.start_url;
if (manifest.scope && manifest.scope.length) {
baseUrlPattern = url.resolve(baseUrlPattern, manifest.scope);
var parsedScopeUrl = url.parse(manifest.scope);
if (parsedScopeUrl.protocol) {
baseUrlPattern = manifest.scope;
} else {
baseUrlPattern = url.resolve(baseUrlPattern, manifest.scope);
}
}

baseUrlPattern = url.resolve(baseUrlPattern, '*');
// If there are no wildcards in the pattern, add '*' at the end
if (baseUrlPattern.indexOf('*') === -1) {
baseUrlPattern = url.resolve(baseUrlPattern, '*');
}

// add base rule as an access rule for Android
var androidAccessBaseRule = new etree.SubElement(androidRoot, 'access');
Expand Down Expand Up @@ -594,20 +602,34 @@ module.exports = function (context) {
var manifestPath = path.join(projectRoot, 'manifest.json');
fs.readFile(manifestPath, function (err, data) {
if (err) {
logger.error('ERROR: Failed to read manifest in at \'' + manifestPath + '\'.');
logger.error('Failed to read manifest at \'' + manifestPath + '\'.');
return task.reject(err);
}

var manifestJson = data.toString().replace(/^\uFEFF/, '');
var appManifestPath = path.join(projectRoot, 'www', 'manifest.json');
fs.writeFile(appManifestPath, manifestJson, function (err) {
if (err) {
logger.error('ERROR: Failed to copy manifest to \'www\' folder.');
logger.error('Failed to copy manifest to \'www\' folder.');
return task.reject(err);
}

var manifest = JSON.parse(manifestJson);

// The start_url member is required and must be a full URL.
// Even though a relative URL is a valid according to the W3C spec, a full URL
// is needed because the plugin cannot determine the manifest's origin.
var start_url;
if (manifest.start_url) {
start_url = url.parse(manifest.start_url);
}

if (!(start_url && start_url.hostname && start_url.protocol)) {
logger.error('Invalid or incomplete W3C manifest.');
var err = new Error('The start_url member in the manifest is required and must be a full URL.');
return task.reject(err);
}

// update name, start_url, orientation, and fullscreen from manifest
if (manifest.short_name) {
config.setName(manifest.short_name.replace(/\//g,'').replace(/\s/g,''));
Expand Down

0 comments on commit 8e5b457

Please sign in to comment.