Merge pull request #144 from gmetais/domains

New advanced option: possibility to block domains
This commit is contained in:
Gaël Métais
2016-03-23 13:29:37 +02:00
13 changed files with 89 additions and 42 deletions
+2 -1
View File
@@ -34,7 +34,8 @@
font-size: 1em;
}
.settings input[type=text],
.settings input[type=password] {
.settings input[type=password],
.settings textarea {
width: 100%;
min-width: 4em;
}
+25 -12
View File
@@ -14,20 +14,22 @@ apiService.factory('API', ['$location', 'Runs', 'Results', function($location, R
waitForSelector: settings.waitForSelector,
cookie: settings.cookie,
authUser: settings.authUser,
authPass: settings.authPass
authPass: settings.authPass,
blockDomain: settings.blockDomain,
allowedDomains: settings.allowedDomains,
noExternals: settings.noExternals
};
if (settings.waitForSelector && settings.waitForSelector !== '') {
runObject.waitForSelector = settings.waitForSelector;
}
if (settings.cookie && settings.cookie !== '') {
runObject.cookie = settings.cookie;
}
if (settings.authUser && settings.authUser !== '' && settings.authPass && settings.authPass !== '') {
runObject.authUser = settings.authUser;
runObject.authPass = settings.authPass;
if (settings.domainsBlackOrWhite === 'black') {
runObject.blockDomain = this.parseDomains(settings.domains);
} else if (settings.domainsBlackOrWhite === 'white') {
var allowedDomains = this.parseDomains(settings.domains);
if (allowedDomains.length > 0) {
runObject.allowDomain = allowedDomains;
} else {
runObject.noExternals = true;
}
}
Runs.save(runObject, function(data) {
@@ -43,6 +45,17 @@ apiService.factory('API', ['$location', 'Runs', 'Results', function($location, R
relaunchTest: function(result) {
this.launchTest(result.params.url, result.params.options);
},
parseDomains: function(textareaContent) {
var lines = textareaContent.split('\n');
function removeEmptyLines (line) {
return line.trim() !== '';
}
// Remove empty lines
return lines.filter(removeEmptyLines).join(',');
}
};
+1 -1
View File
@@ -38,7 +38,7 @@
font-size: 1em;
}
input[type=text], input[type=password] {
input[type=text], input[type=password], textarea {
width: 100%;
min-width: 4em;
}
+7
View File
@@ -1,6 +1,13 @@
<div ng-include="'views/resultSubHeader.html'"></div>
<div class="summary board">
<div ng-if="result.blockedRequests">
<b><ng-pluralize count="result.blockedRequests.length" when="{'0': 'No blocked request', 'one': '1 blocked request', 'other': '{} blocked requests'}"></ng-pluralize>:</b>
<div ng-repeat="request in result.blockedRequests">
{{request}}
</div>
</div>
<div class="globalScore" ng-if="globalScore === 0 || globalScore > 0">
<div>
<h2>Global score</h2>
+12 -5
View File
@@ -61,15 +61,22 @@
</div>
</div>
</div>
<!--<div>
<div class="label">Blocked domains</div>
<div>
<div class="label">
Block domains
<span class="settingsTooltip">
<span class="icon-question"></span>
<div><b>Block some domains</b><br><br>One line per domain or subdomain.<br><br><i><b>Example:</b><br>google-analytics.com<br>ads.yahoo.com<br>ajax.googleapis.com</i><br><br>An empty whitelist will block all domains except the main domain.</div>
</span>
</div>
<div>
<div>
Blacklist / Whitelist
<input type="radio" name="blackOrWhite" ng-model="settings.domainsBlackOrWhite" value="black" />blacklist
<input type="radio" name="blackOrWhite" ng-model="settings.domainsBlackOrWhite" value="white" />whitelist
</div>
<textarea name=""></textarea>
<textarea name="domains" ng-model="settings.domains" rows="5"></textarea>
</div>
</div>-->
</div>
</div>
</div>
</form>
+2
View File
@@ -281,6 +281,8 @@ var policies = {
if (value.indexOf('1.12.') === 0 ||
value.indexOf('2.2.') === 0 ||
value.indexOf('1.13.') === 0 ||
value.indexOf('2.3.') === 0 ||
value.indexOf('3.0.') === 0 ||
value.indexOf('3.1.') === 0) {
score = 100;
+6 -1
View File
@@ -66,9 +66,14 @@ var Runner = function(params) {
delete data.toolsResults.phantomas.metrics.scrollExecutionTree;
delete data.toolsResults.phantomas.offenders.scrollExecutionTree;
if (data.toolsResults.phantomas.offenders.blockedRequests) {
data.blockedRequests = data.toolsResults.phantomas.offenders.blockedRequests;
}
// Finished!
deferred.resolve(data);
})
.fail(function(err) {
+7 -1
View File
@@ -39,7 +39,10 @@ var ApiController = function(app) {
waitForSelector: req.body.waitForSelector || null,
cookie: req.body.cookie || null,
authUser: req.body.authUser || null,
authPass: req.body.authPass || null
authPass: req.body.authPass || null,
blockDomain: req.body.blockDomain || null,
allowDomain: req.body.allowDomain || null,
noExternals: req.body.noExternals || false
}
};
@@ -77,6 +80,9 @@ var ApiController = function(app) {
cookie: run.params.cookie,
authUser: run.params.authUser,
authPass: run.params.authPass,
blockDomain: run.params.blockDomain,
allowDomain: run.params.allowDomain,
noExternals: run.params.noExternals,
phantomasEngine: serverSettings.phantomasEngine
};
+3 -6
View File
@@ -31,12 +31,14 @@ var PhantomasWrapper = function() {
'cookie': task.options.cookie,
'auth-user': task.options.authUser,
'auth-pass': task.options.authPass,
'block-domain': task.options.blockDomain,
'allow-domain': task.options.allowDomain,
'no-externals': task.options.noExternals,
// Mandatory
'reporter': 'json:pretty',
'analyze-css': true,
'skip-modules': [
'blockDomains', // not needed
'domHiddenContent', // overriden
'domMutations', // not compatible with webkit
'domQueries', // overriden
@@ -118,11 +120,6 @@ var PhantomasWrapper = function() {
async.retry(triesNumber, function(cb) {
currentTry ++;
// Fix for https://github.com/gmetais/YellowLabTools/issues/114
if (currentTry === 2 && options.engine === 'webkit2') {
debug('Launching a second try with the old webkit v1 engine');
options.engine = 'webkit';
}
var process = phantomas(task.url, options, function(err, json, results) {
var errorCode = err ? parseInt(err.message, 10) : null;
+1 -1
View File
@@ -45,7 +45,7 @@
"meow": "3.6.0",
"minimize": "1.7.4",
"parse-color": "1.0.0",
"phantomas": "1.13.0",
"phantomas": "git://github.com/gmetais/phantomas.git#fix-about-blank",
"ps-node": "0.0.5",
"q": "1.4.1",
"request": "2.67.0",
+9 -2
View File
@@ -31,6 +31,7 @@ describe('api', function() {
},
json: true,
headers: {
'Content-Type': 'application/json',
'X-Api-Key': 'invalid'
}
}, function(error, response, body) {
@@ -53,6 +54,7 @@ describe('api', function() {
},
json: true,
headers: {
'Content-Type': 'application/json',
'X-Api-Key': Object.keys(config.authorizedKeys)[0]
}
}, function(error, response, body) {
@@ -76,6 +78,7 @@ describe('api', function() {
},
json: true,
headers: {
'Content-Type': 'application/json',
'X-Api-Key': Object.keys(config.authorizedKeys)[0]
}
}, function(error, response, body) {
@@ -99,12 +102,13 @@ describe('api', function() {
screenshot: true,
device: 'tablet',
//waitForSelector: '*',
cookie: 'foo=bar',
//cookie: 'foo=bar;domain=google.com',
authUser: 'joe',
authPass: 'secret'
},
json: true,
headers: {
'Content-Type': 'application/json',
'X-Api-Key': Object.keys(config.authorizedKeys)[0]
}
}, function(error, response, body) {
@@ -133,6 +137,7 @@ describe('api', function() {
},
json: true,
headers: {
'Content-Type': 'application/json',
'X-Api-Key': Object.keys(config.authorizedKeys)[0]
}
}, function(error, response, body) {
@@ -172,7 +177,7 @@ describe('api', function() {
// Check if settings are correctly sent and retrieved
body.params.options.should.have.a.property('device').that.equals('tablet');
//body.params.options.should.have.a.property('waitForSelector').that.equals('*');
body.params.options.should.have.a.property('cookie').that.equals('foo=bar');
//body.params.options.should.have.a.property('cookie').that.equals('foo=bar');
body.params.options.should.have.a.property('authUser').that.equals('joe');
body.params.options.should.have.a.property('authPass').that.equals('secret');
@@ -208,6 +213,7 @@ describe('api', function() {
},
json: true,
headers: {
'Content-Type': 'application/json',
'X-Api-Key': Object.keys(config.authorizedKeys)[0]
}
}, function(error, response, body) {
@@ -232,6 +238,7 @@ describe('api', function() {
url: serverUrl + '/api/runs/' + asyncRunId,
json: true,
headers: {
'Content-Type': 'application/json',
'X-Api-Key': Object.keys(config.authorizedKeys)[0]
}
}, function(error, response, body) {
+13 -12
View File
@@ -183,18 +183,19 @@ describe('customPolicies', function() {
var versions = {
'1.2.9': 0,
'1.3.9': 0,
'1.4.4': 10,
'1.5.0': 20,
'1.6.3': 30,
'1.7.0': 40,
'1.8.3a': 50,
'1.9.2': 70,
'1.10.1': 90,
'2.0.0-rc1': 90,
'1.11.1': 100,
'2.1.1-beta1': 100,
'3.0.0': 100
'1.4.4': 0,
'1.5.0': 10,
'1.6.3': 20,
'1.7.0': 30,
'1.8.3a': 40,
'1.9.2': 50,
'1.10.1': 70,
'2.0.0-rc1': 70,
'1.11.1': 90,
'2.1.1-beta1': 90,
'1.12.1': 100,
'2.3.1': 100,
'3.1.0': 100
};
for (var version in versions) {
+1
View File
@@ -2,6 +2,7 @@
"serverPort": "8387",
"phantomasEngine": "webkit",
"googleAnalyticsId": "",
"screenshotWidth": 400,
"authorizedKeys": {
"1234567890": "contact@gaelmetais.com"