Skip to content
This repository has been archived by the owner on May 13, 2021. It is now read-only.

Commit

Permalink
Added support for mjs_extended_scope manifest member
Browse files Browse the repository at this point in the history
  • Loading branch information
mrodriguez committed Nov 20, 2015
1 parent 831e57d commit eabaacc
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 36 deletions.
7 changes: 7 additions & 0 deletions lib/manifestTools/assets/web-manifest-extended.json
Expand Up @@ -12,6 +12,13 @@
"$ref": "#/definitions/mjs_access_whitelist_rule"
}
},
"mjs_extended_scope": {
"description": "The mjs_extended_scope member is an array of rules that define the navigation scope of this web application's application context.",
"type": "array",
"items": {
"type": "string", "format": "uri"
}
},
"mjs_api_access": {
"description": "The mjs_api_whitelist member is an array of rules that indicates the type of access to the runtime API the URLs matching the rule should have.",
"type": "array",
Expand Down
6 changes: 4 additions & 2 deletions lib/manifestTools/validationConstants.js
Expand Up @@ -10,7 +10,8 @@ module.exports = {
missingImageGroup: 'missing-image-group',
missingImage: 'missing-image',
missingImageOnsite: 'missing-image-onsite',
requiredAbsoluteUrl: 'requiredAbsoluteUrl'
requiredAbsoluteUrl: 'requiredAbsoluteUrl',
deprecatedMember: 'deprecatedMember'
},
manifestMembers: {
lang: 'lang',
Expand All @@ -25,7 +26,8 @@ module.exports = {
related_applications: 'related_applications',
prefer_related_applications: 'prefer_related_applications',
mjs_access_whitelist: 'mjs_access_whitelist',
mjs_api_access: 'mjs_api_acces'
mjs_api_access: 'mjs_api_acces',
mjs_extended_scope: 'mjs_extended_scope'
},
platforms: {
all: 'all',
Expand Down
17 changes: 17 additions & 0 deletions lib/manifestTools/validationRules/all/accessRulesDeprecated.js
@@ -0,0 +1,17 @@
'use strict';

var validationConstants = require('../../validationConstants');

module.exports = function (manifestContent, callback) {
if (manifestContent.mjs_access_whitelist) {
return callback(undefined, {
'description': 'The mjs_access_whitelist member is deprecated and won\'t be supported in future versions. Use mjs_extended_scope instead',
'platform': validationConstants.platforms.all,
'level': validationConstants.levels.warning,
'member': validationConstants.manifestMembers.mjs_access_whitelist,
'code': validationConstants.codes.deprecatedMember
});
}

callback();
};
20 changes: 20 additions & 0 deletions lib/manifestTools/validationRules/all/extendedScopeRequired.js
@@ -0,0 +1,20 @@
'use strict';

var validationConstants = require('../../validationConstants');

module.exports = function (manifestContent, callback) {
var mjs_access_whitelist = manifestContent.mjs_access_whitelist;
var mjs_extended_scope = manifestContent.mjs_extended_scope;
if ((!mjs_access_whitelist || !(mjs_access_whitelist instanceof Array) || mjs_access_whitelist.length === 0) &&
(!mjs_extended_scope || !(mjs_extended_scope instanceof Array) || mjs_extended_scope.length === 0)) {
return callback(undefined, {
'description': 'It is recommended to specify a set of rules that represent the navigation scope of the application',
'platform': validationConstants.platforms.all,
'level': validationConstants.levels.suggestion,
'member': validationConstants.manifestMembers.mjs_extended_scope,
'code': validationConstants.codes.requiredValue
});
}

callback();
};
18 changes: 0 additions & 18 deletions lib/manifestTools/validationRules/all/requiredAccessRules.js

This file was deleted.

8 changes: 7 additions & 1 deletion lib/platformUtils/windows10Utils.js
Expand Up @@ -107,13 +107,19 @@ function replaceManifestValues(w3cManifestInfo, content) {
tryAddAcurToList(acurList, { 'match': baseAcurMatch, 'type': 'include' });

// Add rules from mjs_access_whitelist to ACUR list
// TODO: mjs_access_whitelist is deprecated. Should be removed in future versions
if (w3cManifest.mjs_access_whitelist) {
w3cManifest.mjs_access_whitelist.forEach(function(whitelistRule) {
tryAddAcurToList(acurList, { 'match': whitelistRule.url, 'type': 'include', 'runtimeAccess': whitelistRule.apiAccess });
});
}

// TODO: Add rules from mjs_extended_scope to ACUR list
// Add rules from mjs_extended_scope to ACUR list
if (w3cManifest.mjs_extended_scope) {
w3cManifest.mjs_extended_scope.forEach(function(whitelistRule) {
tryAddAcurToList(acurList, { 'match': whitelistRule.url, 'type': 'include' });
});
}

// Add rules from mjs_api_access to ACUR list
if (w3cManifest.mjs_api_access) {
Expand Down
6 changes: 3 additions & 3 deletions test/manifestTools.js
Expand Up @@ -688,7 +688,7 @@ describe('Manifest Tools', function () {
});
});

it('Should recommend to specify access rules', function (done) {
it('Should recommend to specify scope rules', function (done) {
var manifestInfo = {
content: {
'short_name': 'MyApp',
Expand All @@ -698,10 +698,10 @@ describe('Manifest Tools', function () {
};

var expectedValidation = {
'description': 'It is recommended to specify a set of access rules that represent the navigation scope of the application',
'description': 'It is recommended to specify a set of rules that represent the navigation scope of the application',
'platform': validationConstants.platforms.all,
'level': validationConstants.levels.suggestion,
'member': validationConstants.manifestMembers.mjs_access_whitelist,
'member': validationConstants.manifestMembers.mjs_extended_scope,
'code': validationConstants.codes.requiredValue
};

Expand Down
29 changes: 29 additions & 0 deletions test/manifestTools/validations/all/accessRulesDeprecated.js
@@ -0,0 +1,29 @@
'use strict';

var validation = require('../../../../lib/manifestTools/validationRules/all/accessRulesDeprecated');
var validationConstants = require('../../../../lib/manifestTools/validationConstants');
var should = require('should');

describe('Validation - All', function () {
describe('deprecatedAccessRules', function () {
it('Should return a \'deprecated\' warning if manifest defines access rules', function(done) {
validation({ mjs_access_whitelist: ['test'] }, function(err, warning) {
should.not.exist(err);
should.exist(warning);
warning.should.have.property('platform', validationConstants.platforms.all);
warning.should.have.property('level', validationConstants.levels.warning);
warning.should.have.property('member', validationConstants.manifestMembers.mjs_access_whitelist);
warning.should.have.property('code', validationConstants.codes.deprecatedMember);
done();
});
});

it('Should not return a warning if manifest access rules is not defined', function(done) {
validation({}, function(err, warning) {
should.not.exist(err);
should.not.exist(warning);
done();
});
});
});
});
@@ -1,49 +1,49 @@
'use strict';

var validation = require('../../../../lib/manifestTools/validationRules/all/requiredAccessRules');
var validation = require('../../../../lib/manifestTools/validationRules/all/extendedScopeRequired');
var validationConstants = require('../../../../lib/manifestTools/validationConstants');
var should = require('should');

describe('Validation - All', function () {
describe('requiredAccessRules', function () {
it('Should return a suggestion if manifest does not contains access rules', function(done) {
describe('extendedScopeRequired', function () {
it('Should return a suggestion if manifest does not contain scope rules', function(done) {
validation({}, function(err, suggestion) {
should.not.exist(err);
should.exist(suggestion);
suggestion.should.have.property('platform', validationConstants.platforms.all);
suggestion.should.have.property('level', validationConstants.levels.suggestion);
suggestion.should.have.property('member', validationConstants.manifestMembers.mjs_access_whitelist);
suggestion.should.have.property('member', validationConstants.manifestMembers.mjs_extended_scope);
suggestion.should.have.property('code', validationConstants.codes.requiredValue);
done();
});
});

it('Should return a suggestion if manifest access rules is not an array', function(done) {
validation({ mjs_access_whitelist: 'test' }, function(err, suggestion) {
it('Should return a suggestion if manifest scope rules is not an array', function(done) {
validation({ mjs_extended_scope: 'test' }, function(err, suggestion) {
should.not.exist(err);
should.exist(suggestion);
suggestion.should.have.property('platform', validationConstants.platforms.all);
suggestion.should.have.property('level', validationConstants.levels.suggestion);
suggestion.should.have.property('member', validationConstants.manifestMembers.mjs_access_whitelist);
suggestion.should.have.property('member', validationConstants.manifestMembers.mjs_extended_scope);
suggestion.should.have.property('code', validationConstants.codes.requiredValue);
done();
});
});

it('Should return a suggestion if manifest access rules is empty', function(done) {
validation({ mjs_access_whitelist: [] }, function(err, suggestion) {
it('Should return a suggestion if manifest scope rules is an empty array', function(done) {
validation({ mjs_extended_scope: [] }, function(err, suggestion) {
should.not.exist(err);
should.exist(suggestion);
suggestion.should.have.property('platform', validationConstants.platforms.all);
suggestion.should.have.property('level', validationConstants.levels.suggestion);
suggestion.should.have.property('member', validationConstants.manifestMembers.mjs_access_whitelist);
suggestion.should.have.property('member', validationConstants.manifestMembers.mjs_extended_scope);
suggestion.should.have.property('code', validationConstants.codes.requiredValue);
done();
});
});

it('Should not return a suggestion if manifest access rules is not empty', function(done) {
validation({ mjs_access_whitelist: ['something'] }, function(err, suggestion) {
it('Should not return a suggestion if manifest scope rules array is not empty', function(done) {
validation({ mjs_extended_scope: ['url'] }, function(err, suggestion) {
should.not.exist(err);
should.not.exist(suggestion);
done();
Expand Down

0 comments on commit eabaacc

Please sign in to comment.