From a0ecb0a98ee70673d134c0070c86d44d2b8f9365 Mon Sep 17 00:00:00 2001 From: Johann du Toit Date: Fri, 17 Jul 2015 13:14:23 +0200 Subject: [PATCH 1/4] Updated npm driver to actually return information from HTML and not hit a URL --- src/drivers/npm/index.js | 86 ++++++++++++++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 17 deletions(-) diff --git a/src/drivers/npm/index.js b/src/drivers/npm/index.js index 35ffd2a35..153273a70 100644 --- a/src/drivers/npm/index.js +++ b/src/drivers/npm/index.js @@ -4,26 +4,65 @@ var request = require('request'); var fs = require('fs'); var path = require('path'); -//TODO -exports.detectFromHTML = function(options) {}; +/** +* Does the actual detection with information passed +**/ +exports.detect = function(options, data, cb) { + // run the wrapper function that will + // trigger the actual library to run + runWrappalyer(options, data, cb); + +}; + +/** +* Wraps the detect method, just kept to reuse old method names +* and not break anything. Although this was just stubbed out. +**/ +exports.detectFromHTML = function(options, data, cb) { + + // run the detect method + exports.detect(options, data, cb); + +}; + +/** +* Do a actual request for the body & headers, then +* run through detection +**/ exports.detectFromUrl = function(options, cb) { - var url = options.url; + // ensure options and url were + if(!options || !options.url) { - if (options.debug) { - console.log('Fetching the page'); - } + // send back a error ... + cb(new Error("\"url\" is a required option to run" + + " wappalyzer and get the page content")) - getHTMLFromUrl(url, function(err, data) { - if (err || data === null) { - cb(err, null); - } else { - runWrappalyer(options, data, function(err, detected, appInfo) { - cb(null, detected, appInfo); - }); - } - }); + } else { + + // local variables to + var url = options.url; + + // get the body content from the url + getHTMLFromUrl(url, function(err, data) { + + // check for error or if we got no data back + if (err || data === null) { + + // handle the error and don't do anything else .. + cb(err, null); + + } else { + + // run actual detection + exports.detect(options, data, cb); + + } + + }); + + } }; function getHTMLFromUrl(url, cb) { @@ -42,7 +81,7 @@ function getHTMLFromUrl(url, cb) { } function getAppsJson(cb) { - fs.readFile(path.resolve(__dirname, 'apps.json'), 'utf8', function(err, data) { + fs.readFile(path.resolve(__dirname, '../../apps.json'), 'utf8', function(err, data) { if (err) throw err; return cb(null, JSON.parse(data)); }); @@ -51,7 +90,20 @@ function getAppsJson(cb) { function runWrappalyer(options, data, cb) { var debug = options.debug || false; - var wappalyzer = require('./wappalyzer').wappalyzer; + // according to environment check it + var wappalyzer = null; + + // change depending on the environment + if( process.env.NODE_ENV ) { + + wappalyzer = require('../../wappalyzer').wappalyzer; + + } else { + + wappalyzer = require('./wappalyzer').wappalyzer; + + } + getAppsJson(function(err, apps) { var w = wappalyzer; w.driver = { From 4ada80bb8d64d270f04c9711298c54977b120e06 Mon Sep 17 00:00:00 2001 From: Johann du Toit Date: Fri, 17 Jul 2015 13:14:57 +0200 Subject: [PATCH 2/4] Added samples from the love website that the test is being run against currently --- src/drivers/npm/test/sample.headers.json | 20 +++ src/drivers/npm/test/sample.html | 149 +++++++++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 src/drivers/npm/test/sample.headers.json create mode 100644 src/drivers/npm/test/sample.html diff --git a/src/drivers/npm/test/sample.headers.json b/src/drivers/npm/test/sample.headers.json new file mode 100644 index 000000000..c8441bf8e --- /dev/null +++ b/src/drivers/npm/test/sample.headers.json @@ -0,0 +1,20 @@ +{ + "Date":"Fri, 17 Jul 2015 11:05:08 GMT", + "Content-Encoding":"gzip", + "Age":"0", + "X-Cache":"MISS", + "Connection":"keep-alive", + "Content-Length":"1940", + "Via":"1.1 varnish", + "X-Served-By":"cache-lcy1122-LCY", + "Last-Modified":"Thu, 16 Apr 2015 14:24:18 GMT", + "Server":"GitHub.com", + "X-Timer":"S1437131108.300792,VS0,VE84", + "Vary":"Accept-Encoding", + "Content-Type":"text/html; charset=utf-8", + "Access-Control-Allow-Origin":"*", + "Expires":"Fri, 17 Jul 2015 11:10:54 GMT", + "Cache-Control":"max-age=600", + "Accept-Ranges":"bytes", + "X-Cache-Hits":"0" +} \ No newline at end of file diff --git a/src/drivers/npm/test/sample.html b/src/drivers/npm/test/sample.html new file mode 100644 index 000000000..f8624a4e1 --- /dev/null +++ b/src/drivers/npm/test/sample.html @@ -0,0 +1,149 @@ + + + + + + + + Preso Engines | CodeLanka + + + + + + + + + + + + + +
+
+
+
+
+

Preso Engines

+ "Presentation Engines" +
+
+ +
+
By | CodeLanka
+
+
+
+

+
+
+
+
+
+ + {{presentation.name}} + + + + {{presentation.website}} + + + + {{presentation.description}} + +
+
+ +

{{presentation.stargazers_count}}

+
+
+ +

{{presentation.watchers_count}}

+
+
+ +

{{presentation.open_issues_count}}

+
+ +
+
+

Github - + {{presentation.github}} +

+

Demo - + {{presentation.demo}} +

+ +

License - {{presentation.license}}

+ +

Language - {{presentation.language}}

+
+
+
+
+
+
+
+
+
+ + + + + + + \ No newline at end of file From 064555fc2e95c195ed44d5cced05600b306adbc4 Mon Sep 17 00:00:00 2001 From: Johann du Toit Date: Fri, 17 Jul 2015 13:15:52 +0200 Subject: [PATCH 3/4] Updated to add "TESTING" as the NODE_ENV variable when testing to look for the module in another spot --- src/drivers/npm/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/npm/package.json b/src/drivers/npm/package.json index d1131c707..71171aac7 100644 --- a/src/drivers/npm/package.json +++ b/src/drivers/npm/package.json @@ -4,7 +4,7 @@ "description": "NPM Module that uncovers the technologies used on websites", "main": "index.js", "scripts": { - "test": "mocha -t 15000" + "test": "NODE_ENV=testing mocha -t 15000" }, "repository": { "type": "git", From 938ccca7537c5ce8ee794df7e3ce14cfd2e19dad Mon Sep 17 00:00:00 2001 From: Johann du Toit Date: Fri, 17 Jul 2015 13:16:11 +0200 Subject: [PATCH 4/4] Added test for the #detectFromHTML method --- src/drivers/npm/test/test.js | 40 +++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/drivers/npm/test/test.js b/src/drivers/npm/test/test.js index ce4426172..8e994d1cc 100644 --- a/src/drivers/npm/test/test.js +++ b/src/drivers/npm/test/test.js @@ -1,4 +1,5 @@ -var assert = require("assert") +var assert = require("assert") +var fs = require('fs') describe('wappalyzer', function(){ describe('detectFromUrl', function(){ @@ -24,4 +25,41 @@ describe('wappalyzer', function(){ }) }) + describe('detectFromHTML', function(){ + it('should have the expected apps detected when passed raw info', function(done){ + + var wappalyzer = require("../index"); + + var expect = ['AngularJS','Font Awesome','Google Font API','Twitter Bootstrap','jQuery']; + + var options={ + url : "http://codelanka.github.io/Presentation-Engines", + hostname:"codelanka.github.io", + debug:false + } + + var data = { + + url: options.url, + headers: require('./sample.headers.json'), + html: fs.readFileSync('./test/sample.html').toString(), + headers: { + + headers: {} + + } + + }; + + wappalyzer.detectFromHTML(options, data, function (err,apps) { + + assert.equal(expect[0], apps[0]); + assert.equal(expect[1], apps[1]); + assert.equal(expect[2], apps[2]); + assert.equal(expect[3], apps[3]); + done(); + }) + + }) + }) })