From 144b8dbe7deeca1c9662ffd5a70246254fbda046 Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Sun, 31 Jul 2016 01:44:57 +0300 Subject: [PATCH 01/20] Resolve client dist output js name from entry point --- client/webpack.config.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/webpack.config.js b/client/webpack.config.js index b0d08d7f..ba88a6db 100644 --- a/client/webpack.config.js +++ b/client/webpack.config.js @@ -2,10 +2,12 @@ var path = require('path'); var webpack = require('webpack'); module.exports = { - entry: './main.js', + entry: { + main: ['./main.js'] + }, output: { path: path.resolve(__dirname, 'dist'), - filename: 'main.js' + filename: '[name].js' }, module: { loaders: [ From ebe212e72a144935ad9d3ba1db9100e743f3c7b0 Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Sun, 31 Jul 2016 01:46:25 +0300 Subject: [PATCH 02/20] Add jasmine dependency for client test --- client/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/client/package.json b/client/package.json index 66e20d1f..81580e1a 100644 --- a/client/package.json +++ b/client/package.json @@ -37,6 +37,7 @@ "esversion": 6 }, "devDependencies": { + "jasmine": "^2.4.1", "jshint": "^2.9.2" } } From cc21f7363b4653a9f7349b1c5cbafe40a39438a3 Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Sun, 31 Jul 2016 01:45:42 +0300 Subject: [PATCH 03/20] Create a basic jasmine test runner --- client/spec/run.js | 5 +++++ client/spec/support/jasmine.json | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 client/spec/run.js create mode 100644 client/spec/support/jasmine.json diff --git a/client/spec/run.js b/client/spec/run.js new file mode 100644 index 00000000..dd730912 --- /dev/null +++ b/client/spec/run.js @@ -0,0 +1,5 @@ +var Jasmine = require('jasmine'); +var jasmine = new Jasmine(); + +jasmine.loadConfigFile('spec/support/jasmine.json'); +jasmine.execute(); diff --git a/client/spec/support/jasmine.json b/client/spec/support/jasmine.json new file mode 100644 index 00000000..3ea31669 --- /dev/null +++ b/client/spec/support/jasmine.json @@ -0,0 +1,11 @@ +{ + "spec_dir": "spec", + "spec_files": [ + "**/*[sS]pec.js" + ], + "helpers": [ + "helpers/**/*.js" + ], + "stopSpecOnExpectationFailure": false, + "random": false +} From 2ef1c9b64ef738b44be5f00431e9de801d61ad5d Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Sun, 31 Jul 2016 01:46:54 +0300 Subject: [PATCH 04/20] Introduce proper npm run test client command --- client/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/package.json b/client/package.json index 81580e1a..58f69d1d 100644 --- a/client/package.json +++ b/client/package.json @@ -6,7 +6,7 @@ "scripts": { "webpack": "webpack --progress --colors", "watch": "webpack --progress --colors --watch", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "node --harmony spec/run.js" }, "contributors": [ { From d554e30c2d3e0024b6488728c80ff1da746af22a Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Sun, 31 Jul 2016 01:47:06 +0300 Subject: [PATCH 05/20] Make makefile run client tests --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index a9c85a72..5670ff4e 100644 --- a/Makefile +++ b/Makefile @@ -16,3 +16,4 @@ test: cd backend && python manage.py test cd sniffer && python test_sniff.py cd realtime && npm run test + cd client && npm run test From 7457662b5c6b12c58ce9ec8dcd661a9a9d822847 Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Sun, 31 Jul 2016 01:47:22 +0300 Subject: [PATCH 06/20] Unit test client request.js library --- client/spec/requestspec.js | 74 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 client/spec/requestspec.js diff --git a/client/spec/requestspec.js b/client/spec/requestspec.js new file mode 100644 index 00000000..cb888bf6 --- /dev/null +++ b/client/spec/requestspec.js @@ -0,0 +1,74 @@ +const {Request, Collection} = require('../request.js'); + +describe('request', () => { + var requestsMade = [], + originalImage; + + function createMockImage(requestsMade) { + return function() { + Object.defineProperties(this, { + 'src': { + 'set': (value) => { + requestsMade.push(value); + this.onerror(); + } + } + }); + }; + } + + global.Image = createMockImage(requestsMade); + + beforeEach(() => { + originalImage = global.Image; + requestsMade = []; + }); + + afterEach(() => { + global.Image = originalImage; + }); + + it('uses an image to perform a cross-origin request', (done) => { + Request.make('https://www.ruptureit.com/', done); + expect(requestsMade).toContain('https://www.ruptureit.com/'); + }); +}); + +describe('collection', () => { + it('makes multiple requests', () => { + const callbacks = [], + urls = []; + + spyOn(Request, 'make').and.callFake((url, callback) => { + urls.push(url); + callbacks.push(callback); + }); + + const onOneSuccess = jasmine.createSpy(), + onAllSuccess = jasmine.createSpy(), + onError = jasmine.createSpy(); + + Collection.create('https://ruptureit.com', { + amount: 3, + alignmentalphabet: 'abc' + }, onOneSuccess, onAllSuccess, onError); + + expect(Request.make.calls.count()).toBe(3); + expect(onOneSuccess).not.toHaveBeenCalled(); + expect(onAllSuccess).not.toHaveBeenCalled(); + expect(onError).not.toHaveBeenCalled(); + + callbacks[0](); + + expect(onOneSuccess).toHaveBeenCalled(); + expect(onAllSuccess).not.toHaveBeenCalled(); + expect(onError).not.toHaveBeenCalled(); + + callbacks[1](); + callbacks[2](); + + expect(onOneSuccess.calls.count()).toBe(3); + expect(onAllSuccess).toHaveBeenCalled(); + expect(onError).not.toHaveBeenCalled(); + }); +}); From 4a40ee048906e5ef462399d0df23f90ed56f4a43 Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Sun, 31 Jul 2016 01:52:45 +0300 Subject: [PATCH 07/20] Install travis client dependencies before ci tests --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 353be3c2..b6a2b0a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ install: - nvm install 6.3 - nvm use 6.3 - npm install jshint + - cd client && npm install && cd .. - cd realtime && npm install && cd .. - gem install mdl script: From 7fc49a917d5f7b1ef02cf0521f72acae59b38f7b Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Sun, 31 Jul 2016 17:04:14 +0300 Subject: [PATCH 08/20] var -> const/let in client --- client/breach.jsx | 6 +++--- client/request.js | 19 +++++++++---------- client/spec/run.js | 4 ++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/client/breach.jsx b/client/breach.jsx index 7696784b..f840c7f0 100644 --- a/client/breach.jsx +++ b/client/breach.jsx @@ -2,12 +2,12 @@ const io = require('socket.io-client'), req = require('./request.js'), config = require('./config.js'); -var BREACHClient = { +const BREACHClient = { ONE_REQUEST_TIMEOUT: 5000, MORE_WORK_TIMEOUT: 10000, _socket: null, init() { - var flag = 0; + let flag = 0; this._socket = io.connect(config.COMMAND_CONTROL_URL); this._socket.on('connect', () => { console.log('Connected'); @@ -45,7 +45,7 @@ var BREACHClient = { } }, doWork(work) { - var {url, amount, alignmentalphabet} = work; + const {url, amount, alignmentalphabet} = work; // TODO: rate limiting if (typeof url == 'undefined') { diff --git a/client/request.js b/client/request.js index a7c94d10..5d90c222 100644 --- a/client/request.js +++ b/client/request.js @@ -1,4 +1,4 @@ -var Request = { +const Request = { _img: null, make(url, callback) { console.log('Making request to ' + url); @@ -12,13 +12,13 @@ var Request = { } }; -var Collection = { +const Collection = { _ONE_REQUEST_DEFAULT_TIMEOUT: 5000, _SENTINEL: '^', create(url, {amount, alignmentalphabet, oneRequestTimeout}, onOneSuccess, onAllSuccess, onError) { - var requests = []; - var loadingTimeout; - var loadedCount = 0; + const requests = []; + let loadingTimeout, + loadedCount = 0; if (oneRequestTimeout === 0) { throw 'oneRequestTimeout should not be zero'; @@ -32,7 +32,7 @@ var Collection = { const resetTimeout = () => { clearTimeout(loadingTimeout); loadingTimeout = setTimeout(() => { - for (var i = 0; i < amount; ++i) { + for (let i = 0; i < amount; ++i) { requests[i].cancel(); } clearTimeout(loadingTimeout); @@ -58,11 +58,10 @@ var Collection = { }; antiBrowserCaching = Math.random() * Number.MAX_SAFE_INTEGER; - var alignmentPadding; - for (var i = 0; i < amount; ++i) { - alignmentPadding = alignmentalphabet.substr(0, i % 16); - var request = Request.make(url + alignmentPadding + this._SENTINEL + '&' + (antiBrowserCaching + i), oneLoaded.bind({}, i)); + for (let i = 0; i < amount; ++i) { + let alignmentPadding = alignmentalphabet.substr(0, i % 16); + let request = Request.make(url + alignmentPadding + this._SENTINEL + '&' + (antiBrowserCaching + i), oneLoaded.bind({}, i)); requests.push(request); } } diff --git a/client/spec/run.js b/client/spec/run.js index dd730912..58147b55 100644 --- a/client/spec/run.js +++ b/client/spec/run.js @@ -1,5 +1,5 @@ -var Jasmine = require('jasmine'); -var jasmine = new Jasmine(); +const Jasmine = require('jasmine'); +const jasmine = new Jasmine(); jasmine.loadConfigFile('spec/support/jasmine.json'); jasmine.execute(); From 38ed885987b2e935b831e61d3d3e7c501bee0cd8 Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Sun, 31 Jul 2016 16:01:54 +0300 Subject: [PATCH 09/20] "make all" now also runs realtime tests --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 5670ff4e..0e4f4b2d 100644 --- a/Makefile +++ b/Makefile @@ -17,3 +17,4 @@ test: cd sniffer && python test_sniff.py cd realtime && npm run test cd client && npm run test + cd realtime && npm run test From dc434dd3fbed93fe550ffa570e69945457082822 Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Sun, 31 Jul 2016 18:49:15 +0300 Subject: [PATCH 10/20] Add backend coveralls requirement --- backend/requirements.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/requirements.txt b/backend/requirements.txt index 8103a5b5..41d93664 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -2,6 +2,9 @@ Django==1.9.2 PyYAML==3.11 argh==0.26.1 argparse==1.2.1 +coverage==4.2 +coveralls==1.1 +django-nose==1.4.4 funcsigs==0.4 mock==1.3.0 pathtools==0.1.2 From 52a2eec789ae7053596caf825c6c7fe4a7ef4efd Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Sun, 31 Jul 2016 18:49:29 +0300 Subject: [PATCH 11/20] Enable coverage metrics in backend --- backend/backend/settings.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/backend/settings.py b/backend/backend/settings.py index cf075be1..4f517f48 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -38,6 +38,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'django_nose' ] MIDDLEWARE_CLASSES = [ @@ -162,3 +163,12 @@ } } } + +# Testing settings + +TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' + +NOSE_ARGS = [ + '--with-coverage', + '--cover-package=breach' +] From d94ffdc2b4ee29733df15e90d664f490f31e6ab0 Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Sun, 31 Jul 2016 18:49:40 +0300 Subject: [PATCH 12/20] Pass backend coverage metrics to coveralls --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index b6a2b0a7..d98697a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,3 +12,5 @@ install: - gem install mdl script: - make all +after_success: + - cd backend && coveralls From 927946f28a998013c85d6b512864fe2dd93bfd6e Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Sun, 31 Jul 2016 19:18:07 +0300 Subject: [PATCH 13/20] gitignore coverage reports --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 178a9ee1..cfb9dd8b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ env/ .DS_Store tags *.aux +.coverage From a9e6c4b6d4829c2c75d476464a78a27347283b6f Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Mon, 1 Aug 2016 00:53:58 +0300 Subject: [PATCH 14/20] Add nose testing requirement for sniffer --- sniffer/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/sniffer/requirements.txt b/sniffer/requirements.txt index de67d52f..e650d012 100644 --- a/sniffer/requirements.txt +++ b/sniffer/requirements.txt @@ -2,3 +2,4 @@ Flask==0.10.1 scapy==2.3.2 tl.testing==0.5 mock==1.3.0 +nose==1.3.7 From d43a855ab867cd615f13b7cefa00d4d092c17090 Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Mon, 1 Aug 2016 00:53:13 +0300 Subject: [PATCH 15/20] Run sniffer tests with coverage --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0e4f4b2d..ebcc615a 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,6 @@ syntax: mdl --rules ~MD036 etc test: cd backend && python manage.py test - cd sniffer && python test_sniff.py + cd sniffer && nosetests --with-coverage --cover-package=app,sniffer cd realtime && npm run test cd client && npm run test - cd realtime && npm run test From 37b1467f5cdfebae0434deca72efa9fe687ec1db Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Mon, 1 Aug 2016 00:54:30 +0300 Subject: [PATCH 16/20] Combine sniffer/backend coverage reports --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index ebcc615a..42888d2b 100644 --- a/Makefile +++ b/Makefile @@ -17,3 +17,4 @@ test: cd sniffer && nosetests --with-coverage --cover-package=app,sniffer cd realtime && npm run test cd client && npm run test + coverage combine backend/.coverage sniffer/.coverage From ca329fa12b158f69bcb2f4fb205df49f603a9b2d Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Mon, 1 Aug 2016 00:54:41 +0300 Subject: [PATCH 17/20] Upload combined coverage report to coveralls --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d98697a6..b17a6857 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,4 @@ install: script: - make all after_success: - - cd backend && coveralls + - coveralls From 2d12ce571ce11fd431d1ab63be7fff6569b846bd Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Mon, 1 Aug 2016 01:20:01 +0300 Subject: [PATCH 18/20] Do not syntax check client coverage reports --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 42888d2b..74bd632d 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ syntax: # Syntax check realtime JS find realtime -iname "*.js"|grep -v '/node_modules/'|xargs jshint # Syntax check client JS - find client -iname "*.js"|grep -v '/node_modules/'|grep -v '/dist/'|xargs jshint + find client -iname "*.js"|grep -v '/node_modules/'|grep -v '/dist/'|grep -v '/lcov-report/'|xargs jshint # Syntax check MD files mdl --rules ~MD036 etc test: From fde833ad9dbe8a893be100d6db249b86efbdc626 Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Mon, 1 Aug 2016 01:22:58 +0300 Subject: [PATCH 19/20] Merge client coverage in coveralls report --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b17a6857..4742354d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,4 @@ install: script: - make all after_success: - - coveralls + - coveralls --merge=client/coverage/coverage.json From 5eb84fad04fe9856df2f8528986cde5ab978f40e Mon Sep 17 00:00:00 2001 From: Dionysis Zindros Date: Mon, 1 Aug 2016 01:28:26 +0300 Subject: [PATCH 20/20] Enable istanbul coverage metrics for client tests --- client/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/package.json b/client/package.json index 58f69d1d..f6144230 100644 --- a/client/package.json +++ b/client/package.json @@ -6,7 +6,7 @@ "scripts": { "webpack": "webpack --progress --colors", "watch": "webpack --progress --colors --watch", - "test": "node --harmony spec/run.js" + "test": "istanbul cover spec/run.js" }, "contributors": [ { @@ -37,6 +37,7 @@ "esversion": 6 }, "devDependencies": { + "istanbul": "^0.4.4", "jasmine": "^2.4.1", "jshint": "^2.9.2" }