From efbb855bc9944ff258f742040f020ef2c30ed813 Mon Sep 17 00:00:00 2001 From: Mirko Schubert Date: Sun, 27 May 2018 22:35:32 +0200 Subject: [PATCH] v0.3.2: bug fixes --- TODO | 5 ++- index.js | 2 +- lib/tasks.js | 101 +++++++++++++++++++++++++++------------------------ package.json | 2 +- 4 files changed, 59 insertions(+), 51 deletions(-) diff --git a/TODO b/TODO index e1bd95b..066d2f3 100644 --- a/TODO +++ b/TODO @@ -52,4 +52,7 @@ Todo: ☐ Help pages for every command Bugs: ✔ Manual selection of tasks doesn't work anymore @critical @done(18-05-22 16:31) - ✔ CSS and JS files without a protocol can't be loaded @high @done(18-05-22 17:00) \ No newline at end of file + ✔ CSS and JS files without a protocol can't be loaded @high @done(18-05-22 17:00) + ✔ URL class is not global in nodejs < 10 @critical @done(18-05-27 22:11) + ✔ Inline JS and CSS can't be loaded when there are no external files @high @done(18-05-27 22:12) + ☐ On Google the protocol doesn't upgrade to SSL automatically @low \ No newline at end of file diff --git a/index.js b/index.js index e389ce4..8ac6239 100755 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -#!/usr/bin/env node --harmony +#!/usr/bin/env node 'use strict' diff --git a/lib/tasks.js b/lib/tasks.js index 75fdca1..7da2485 100644 --- a/lib/tasks.js +++ b/lib/tasks.js @@ -1,5 +1,6 @@ 'use strict'; +const URL = require('url').URL; const got = require('got'); const chalk = require('chalk'); const sslCert = require('get-ssl-certificate'); @@ -238,39 +239,42 @@ class Tasks { widths: [5, 20, 0] }); - if (typeof fonts.google !== 'undefined') { - const gf = this.cp.countFonts(fonts.google); - this.ui.info('Google Fonts loaded: ' + chalk.red(gf.length) + '\n'); - gf.forEach((f, i) => { - this.ui.tableitem([chalk.yellow(String(i + 1) + '.'), f, chalk.dim(this.cp.getFontStyles(fonts.google, f))]); - }); - } - if (typeof fonts.wordpress !== 'undefined') { - const wf = this.cp.countFonts(fonts.wordpress); - if (typeof fonts.google !== 'undefined') console.log(''); - this.ui.info('Fonts from wordpress.com loaded: ' + chalk.red(wf.length) + '\n'); - wf.forEach((f, i) => { - this.ui.tableitem([chalk.yellow(String(i + 1) + '.'), f, chalk.dim(this.cp.getFontStyles(fonts.wordpress, f))]); - }); - } - if (typeof fonts.internal !== 'undefined') { - const intf = this.cp.countFonts(fonts.internal); - if (typeof fonts.wordpress !== 'undefined') console.log(''); - this.ui.info('Fonts directly from the site: ' + chalk.red(intf.length) + '\n'); - intf.forEach((f, i) => { - this.ui.tableitem([chalk.yellow(String(i + 1) + '.'), f, chalk.dim(this.cp.getFontStyles(fonts.internal, f))]); - }); + if (Object.keys(fonts).length === 0) { + this.ui.info('There were no Fonts found.'); + } else { + if (typeof fonts.google !== 'undefined') { + const gf = this.cp.countFonts(fonts.google); + this.ui.info('Google Fonts loaded: ' + chalk.red(gf.length) + '\n'); + gf.forEach((f, i) => { + this.ui.tableitem([chalk.yellow(String(i + 1) + '.'), f, chalk.dim(this.cp.getFontStyles(fonts.google, f))]); + }); + } + if (typeof fonts.wordpress !== 'undefined') { + const wf = this.cp.countFonts(fonts.wordpress); + if (typeof fonts.google !== 'undefined') console.log(''); + this.ui.info('Fonts from wordpress.com loaded: ' + chalk.red(wf.length) + '\n'); + wf.forEach((f, i) => { + this.ui.tableitem([chalk.yellow(String(i + 1) + '.'), f, chalk.dim(this.cp.getFontStyles(fonts.wordpress, f))]); + }); + } + if (typeof fonts.internal !== 'undefined') { + const intf = this.cp.countFonts(fonts.internal); + if (typeof fonts.wordpress !== 'undefined') console.log(''); + this.ui.info('Fonts directly from the site: ' + chalk.red(intf.length) + '\n'); + intf.forEach((f, i) => { + this.ui.tableitem([chalk.yellow(String(i + 1) + '.'), f, chalk.dim(this.cp.getFontStyles(fonts.internal, f))]); + }); + } + if (typeof fonts.inline !== 'undefined') { + const inlf = this.cp.countFonts(fonts.inline); + if (typeof fonts.iternal !== 'undefined') console.log(''); + this.ui.info('Inline Fonts from the CSS: ' + chalk.red(inlf.length) + '\n'); + inlf.forEach((f, i) => { + this.ui.tableitem([chalk.yellow(String(i + 1) + '.'), f, chalk.dim(this.cp.getFontStyles(fonts.inline, f))]); + }); + } } - if (typeof fonts.inline !== 'undefined') { - const inlf = this.cp.countFonts(fonts.inline); - if (typeof fonts.iternal !== 'undefined') console.log(''); - this.ui.info('Inline Fonts from the CSS: ' + chalk.red(inlf.length) + '\n'); - inlf.forEach((f, i) => { - this.ui.tableitem([chalk.yellow(String(i + 1) + '.'), f, chalk.dim(this.cp.getFontStyles(fonts.inline, f))]); - }); - } - this.remove('fonts'); } } @@ -421,7 +425,7 @@ class Tasks { }); return this.processMultipleItems(this.data.js, this.loadExternalItem).then(res => { - this.data.js = res; + this.data.js = (res !== 404) ? res : []; this.ui.message({ verbose: chalk.dim('-> Looking for Inline JavaScript') }, { @@ -451,7 +455,7 @@ class Tasks { }); return this.processMultipleItems(this.data.css, this.loadExternalItem).then(res => { - this.data.css = res; + this.data.css = (res !== 404) ? res : []; this.ui.message({ verbose: chalk.dim('-> Looking for Inline CSS') }, { @@ -501,20 +505,22 @@ class Tasks { processMultipleItems(array, fn) { const self = this; var results = []; - return array.reduce((p, item) => { - return p.then(() => { - return fn(item).then((data) => { - self.ui.message({ - verbose: chalk.dim('-> ' + item.url) - }, { - code: data.statusCode, - msg: data.statusMessage - }, false); - results.push(data); - return results; + if (array.length !== 0) { + return array.reduce((p, item) => { + return p.then(() => { + return fn(item).then((data) => { + self.ui.message({ + verbose: chalk.dim('-> ' + item.url) + }, { + code: data.statusCode, + msg: data.statusMessage + }, false); + results.push(data); + return results; + }); }); - }); - }, Promise.resolve()); + }, Promise.resolve()); + } else return Promise.resolve(404); } @@ -556,9 +562,8 @@ class Tasks { url = url.replace(/(https?:)?\/\//, ''); // delete the protocol url = (url.startsWith('/')) ? url.substr(1) : url; // get rid of trailing slash url = (url.endsWith('/')) ? url : url + '/'; // ensure that it ends with a slash - url = 'http://' + url; // set unsecure protocol // upgrade protocol if needed - return got(url).then(res => { + return got('http://' + url).then(res => { url = (url != res.url) ? res.url : url; this.data.html = { url: new URL(url) diff --git a/package.json b/package.json index 6a25f2d..13eec5b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gdpr-cli", - "version": "0.3.1", + "version": "0.3.2", "description": "Checks websites for GDPR compliance", "main": "index.js", "scripts": {