From 5e37cf822494527ac2df82d1d46ab92462b32ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Wed, 2 Mar 2016 22:41:18 +0100 Subject: [PATCH 1/6] Update Phantomas to v1.14 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 35e8866..e59029c 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "meow": "3.6.0", "minimize": "1.7.4", "parse-color": "1.0.0", - "phantomas": "1.13.0", + "phantomas": "1.14.0", "ps-node": "0.0.5", "q": "1.4.1", "request": "2.67.0", From 2aa9edeb8f13503cfbbc1f28bccfeb2458f6db99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Sun, 20 Mar 2016 14:55:19 +0200 Subject: [PATCH 2/6] Webkit2 engine does not exist anymore in phantomas 1.14 --- lib/tools/phantomas/phantomasWrapper.js | 5 ----- package.json | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/tools/phantomas/phantomasWrapper.js b/lib/tools/phantomas/phantomasWrapper.js index 7d51542..4fc9e38 100644 --- a/lib/tools/phantomas/phantomasWrapper.js +++ b/lib/tools/phantomas/phantomasWrapper.js @@ -118,11 +118,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; diff --git a/package.json b/package.json index e59029c..07c772a 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "meow": "3.6.0", "minimize": "1.7.4", "parse-color": "1.0.0", - "phantomas": "1.14.0", + "phantomas": "git://github.com/gmetais/phantomas.git#fix-about-blank", "ps-node": "0.0.5", "q": "1.4.1", "request": "2.67.0", From f8431849701a644e4d27e2d69ed16d2bae8aa508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Sun, 20 Mar 2016 16:20:57 +0200 Subject: [PATCH 3/6] Add forgottent screenshotWidth parameter to tests --- test/fixtures/settings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/test/fixtures/settings.json b/test/fixtures/settings.json index 58c89ca..a68db4c 100644 --- a/test/fixtures/settings.json +++ b/test/fixtures/settings.json @@ -2,6 +2,7 @@ "serverPort": "8387", "phantomasEngine": "webkit", "googleAnalyticsId": "", + "screenshotWidth": 400, "authorizedKeys": { "1234567890": "contact@gaelmetais.com" From 3948eeaad4ba180aa3c28b6e2ab578b13acca816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Mon, 21 Mar 2016 21:28:17 +0200 Subject: [PATCH 4/6] New advanced settings: block domains --- front/src/css/index.css | 3 +- front/src/js/services/apiService.js | 37 +++++++++++++++++-------- front/src/less/index.less | 2 +- front/src/views/dashboard.html | 7 +++++ front/src/views/index.html | 17 ++++++++---- lib/runner.js | 7 ++++- lib/server/controllers/apiController.js | 8 +++++- lib/tools/phantomas/phantomasWrapper.js | 4 ++- 8 files changed, 63 insertions(+), 22 deletions(-) diff --git a/front/src/css/index.css b/front/src/css/index.css index fa05717..8bcc1ff 100644 --- a/front/src/css/index.css +++ b/front/src/css/index.css @@ -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; } diff --git a/front/src/js/services/apiService.js b/front/src/js/services/apiService.js index 0482748..95aad1e 100644 --- a/front/src/js/services/apiService.js +++ b/front/src/js/services/apiService.js @@ -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(','); } }; diff --git a/front/src/less/index.less b/front/src/less/index.less index 5c665b4..bbc8b4d 100644 --- a/front/src/less/index.less +++ b/front/src/less/index.less @@ -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; } diff --git a/front/src/views/dashboard.html b/front/src/views/dashboard.html index f5dfa2c..430af91 100644 --- a/front/src/views/dashboard.html +++ b/front/src/views/dashboard.html @@ -1,6 +1,13 @@
+
+ : +
+ {{request}} +
+
+

Global score

diff --git a/front/src/views/index.html b/front/src/views/index.html index ada6eca..a72bb2a 100644 --- a/front/src/views/index.html +++ b/front/src/views/index.html @@ -61,15 +61,22 @@
- + diff --git a/lib/runner.js b/lib/runner.js index 977355c..4c5daf2 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -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) { diff --git a/lib/server/controllers/apiController.js b/lib/server/controllers/apiController.js index a2addbf..28ecd81 100644 --- a/lib/server/controllers/apiController.js +++ b/lib/server/controllers/apiController.js @@ -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 }; diff --git a/lib/tools/phantomas/phantomasWrapper.js b/lib/tools/phantomas/phantomasWrapper.js index 4fc9e38..6eeb20f 100644 --- a/lib/tools/phantomas/phantomasWrapper.js +++ b/lib/tools/phantomas/phantomasWrapper.js @@ -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 From 113c1f056592097a9c9f5090faa494bdf5ed5a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Mon, 21 Mar 2016 23:36:07 +0200 Subject: [PATCH 5/6] Fix jQuery version unit tests --- lib/metadata/policies.js | 2 ++ test/core/customPoliciesTest.js | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/metadata/policies.js b/lib/metadata/policies.js index f8fae98..bcc0f59 100644 --- a/lib/metadata/policies.js +++ b/lib/metadata/policies.js @@ -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; diff --git a/test/core/customPoliciesTest.js b/test/core/customPoliciesTest.js index 784bf64..2f517cd 100644 --- a/test/core/customPoliciesTest.js +++ b/test/core/customPoliciesTest.js @@ -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) { From b3804586dcf3a08f5a6b6d28c56842b5a3a36ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Wed, 23 Mar 2016 13:21:51 +0200 Subject: [PATCH 6/6] Regressing with PhantomJS 2.1, cookies don't work. Waiting for a fix. --- test/api/apiTest.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/api/apiTest.js b/test/api/apiTest.js index c13701f..10751d5 100644 --- a/test/api/apiTest.js +++ b/test/api/apiTest.js @@ -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) {