Skip to content

Commit

Permalink
Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AliasIO committed Aug 12, 2018
1 parent e59ac69 commit a4285e8
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 148 deletions.
1 change: 1 addition & 0 deletions bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ zip -qr ../../../build/wappalyzer_webextension.zip . \
-x \*.gitkeep \
-x \*.js.map \
-x \*.min.js \
-x \*.spec.js \
-x \*.yarn-integrity \
-x \*package.json \
-x \*LICENSE \
Expand Down
4 changes: 4 additions & 0 deletions bin/validate
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ echo "Validating regular expressions..."
echo "Validating icons..."

./bin/validate-icons

echo "Running tests..."

npm run test
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"mocha": "^5.2.0"
},
"scripts": {
"test": "mocha -R spec ./test",
"test": "mocha -R spec src",
"lint": "eslint src",
"lint:fix": "eslint src --fix"
}
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/npm/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/wappalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ class Wappalyzer {
* Log messages to console
*/
log(message, source, type) {
this.driver.log(message, source || '', type || 'debug');
if (this.driver.log) {
this.driver.log(message, source || '', type || 'debug');
}
}

analyze(url, data, context) {
Expand Down Expand Up @@ -178,7 +180,7 @@ class Wappalyzer {

const app = apps[appName];

this.analyzeUrl(app, url);
promises.push(this.analyzeUrl(app, url));

if (html) {
promises.push(this.analyzeHtml(app, html));
Expand Down
134 changes: 134 additions & 0 deletions src/wappalyzer.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/* eslint-env mocha */

const { assert, expect } = require('chai');
const Wappalyzer = require('../src/wappalyzer');

const appsJson = {
appUrl: {
url: 'test',
},
appCookies: {
cookies: {
test: 'test',
},
},
appHeaders: {
headers: {
'X-Powered-By': 'test',
},
},
appHtml: {
html: 'test v(\\d)\\;confidence:50\\;version:\\1',
implies: 'appImplies',
excludes: 'appExcludes',
},
appMeta: {
meta: {
generator: 'test',
},
},
appScript: {
script: 'test',
},
appJs: {
js: {
key: 'value',
},
},
appImplies: {
},
appExcludes: {
html: 'test',
},
};

const driverData = {
cookies: [
{
name: 'test',
value: 'test',
domain: '',
path: '',
},
],
headers: {
'x-powered-by': [
'test',
],
},
html: '<meta name="generator" content="test"> html test v1',
scripts: [
'test',
],
js: {
appJs: {
key: [
'value',
],
},
},
};

describe('Wappalyzer', () => {
describe('#analyze()', () => {
let apps;

before(async () => {
const wappalyzer = new Wappalyzer();

wappalyzer.apps = appsJson;

wappalyzer.parseJsPatterns();

wappalyzer.driver.displayApps = (detected) => {
apps = detected;
};

await wappalyzer.analyze({ canonical: 'test' }, driverData);
});

it('should identify technologies using URLs', () => {
expect(apps).to.have.any.keys('appUrl');
});

it('should identify technologies using HTML', () => {
expect(apps).to.have.any.keys('appHtml');
});

it('should identify technologies using meta tags', () => {
expect(apps).to.have.any.keys('appMeta');
});

it('should identify technologies using script URLs', () => {
expect(apps).to.have.any.keys('appScript');
});

it('should identify technologies using headers', () => {
expect(apps).to.have.any.keys('appHeaders');
});

it('should identify technologies using cookies', () => {
expect(apps).to.have.any.keys('appCookies');
});

it('should identify technologies using JavaScript', () => {
expect(apps).to.have.any.keys('appJs');
});

it('should return the implied technology', () => {
expect(apps).to.have.any.keys('appImplies');
});

it('should not return the excluded technology', () => {
expect(apps).to.not.have.any.keys('appExcludes');
});

it('should return the confidence value', () => {
assert.equal(apps.appHtml.confidenceTotal, 50);
});

it('should return the version number', () => {
assert.equal(apps.appHtml.version, '1');
});
});
});
144 changes: 0 additions & 144 deletions test/analyze.spec.js

This file was deleted.

0 comments on commit a4285e8

Please sign in to comment.