From e484baaaf929d6180de3aa7e3d41c202f5e0777a Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Fri, 20 Jul 2018 18:17:50 -0700 Subject: [PATCH 01/43] Add selenium-webdriver as a dev dependency --- src/js/package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/js/package.json b/src/js/package.json index 8a85099..8c7315e 100644 --- a/src/js/package.json +++ b/src/js/package.json @@ -5,14 +5,15 @@ "main": "utils.js", "dependencies": {}, "devDependencies": { - "react": "file:./external/react", - "react-dom": "file:./external/react-dom", "chai": "^4.1.2", "coveralls": "^3.0.1", "eslint": "^4.19.1", "jsdom": "^11.10.0", "mocha": "^4.1.0", - "nyc": "^11.7.3" + "nyc": "^11.7.3", + "react": "file:./external/react", + "react-dom": "file:./external/react-dom", + "selenium-webdriver": "^4.0.0-alpha.1" }, "scripts": { "test": "mocha --recursive", From eb3ac7055edd418bcdde200318088f6eba729940 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Tue, 28 Aug 2018 13:29:11 -0700 Subject: [PATCH 02/43] Add express and vhost as dev dependencies --- src/js/package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/js/package.json b/src/js/package.json index 8c7315e..b3cf395 100644 --- a/src/js/package.json +++ b/src/js/package.json @@ -8,12 +8,14 @@ "chai": "^4.1.2", "coveralls": "^3.0.1", "eslint": "^4.19.1", + "express": "^4.16.3", "jsdom": "^11.10.0", "mocha": "^4.1.0", "nyc": "^11.7.3", "react": "file:./external/react", "react-dom": "file:./external/react-dom", - "selenium-webdriver": "^4.0.0-alpha.1" + "selenium-webdriver": "^4.0.0-alpha.1", + "vhost": "^3.0.2" }, "scripts": { "test": "mocha --recursive", From fb089d324bb0cf5d2d36ec74f363d39c31e6e009 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Tue, 28 Aug 2018 14:52:28 -0700 Subject: [PATCH 03/43] Initial commit of selenium + express w/ Chrome --- src/js/package.json | 1 + src/js/selenium/etagApp.js | 47 +++++++++++++++++++++++++++++++++++++ src/js/selenium/selenium.js | 39 ++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 src/js/selenium/etagApp.js create mode 100644 src/js/selenium/selenium.js diff --git a/src/js/package.json b/src/js/package.json index b3cf395..cbd623f 100644 --- a/src/js/package.json +++ b/src/js/package.json @@ -19,6 +19,7 @@ }, "scripts": { "test": "mocha --recursive", + "selenium": "node ./selenium/selenium.js", "lint": "git ls-files | grep \".js$\" | grep -v \"external\" | xargs eslint", "loc": "git ls-files | grep -v 'psl.js' | xargs cat | wc -l", "cover": "nyc --reporter=html --reporter=text mocha", diff --git a/src/js/selenium/etagApp.js b/src/js/selenium/etagApp.js new file mode 100644 index 0000000..9f5bb76 --- /dev/null +++ b/src/js/selenium/etagApp.js @@ -0,0 +1,47 @@ +const express = require('express'), + vhost = require('vhost'); + +class App { + constructor(host, port) { + } +} + +module.exports = port => { + const firstApp = express(); + firstApp.get('/', (req, res) => { + console.log('got a reqest'); + return res.send( +`` + ); + }); + return firstApp; +} + +/* + * todo finish implementing the etag test based on this flask code + +from flask import Flask, Response, request +app = Flask(__name__) + +@app.route('/') +def hello_world(): + return ''' + +Hello, World! +''' + +@app.route('/tracker.js') +def tracker(): + resp = Response('document.documentElement.appendChild(document.createTextNode("foobar"))') + req_if_none_match = request.headers.get('if-none-match') + if (req_if_none_match and req_if_none_match.startswith('count:')): + this_count = int(req_if_none_match.split(':')[-1]) + etag = 'count:%s' % (this_count + 1) + print('increment'); + else: + print('fresh') + etag = 'count:0' + resp.headers['etag'] = etag + print(etag); + return resp + */ diff --git a/src/js/selenium/selenium.js b/src/js/selenium/selenium.js new file mode 100644 index 0000000..3a113bf --- /dev/null +++ b/src/js/selenium/selenium.js @@ -0,0 +1,39 @@ +const sw = require('selenium-webdriver'), + express = require('express'), + vhost = require('vhost'), + etagApp = require("./etagApp"); + +const PORT = 8000; + +/* + * in /etc/hosts this requires: + * 127.0.0.1 etag.local + * 127.0.0.1 thirdpartywithetag.local + */ + +function loadDriverWithExtension(extPath) { + let chromeOptions = sw.Capabilities.chrome(); + chromeOptions.set("chromeOptions", {"args": ['--load-extension='+extPath]}); + return new sw.Builder() + .forBrowser('chrome') + .withCapabilities(chromeOptions) + .build(); +} + +function startApps() { + let appWithVhost = module.exports = express(); + appWithVhost.use(vhost('etag.local', etagApp(PORT))); // Serves first app + //appWithVhost.use(vhost('admin.mydomain.local', app2)); // Serves second app + + /* istanbul ignore next */ + if (!module.parent) { + appWithVhost.listen(PORT); + console.log(`Express started on port ${PORT}`); + } +} + +let path = '../.', + driver = loadDriverWithExtension(path); +startApps(); + +driver.get('etag.local:8000'); From 660a204c16725f9014925a390938c2126fbb8d4f Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Fri, 20 Jul 2018 18:17:50 -0700 Subject: [PATCH 04/43] Add selenium-webdriver as a dev dependency --- src/js/package.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/js/package.json b/src/js/package.json index cbd623f..b4e7cad 100644 --- a/src/js/package.json +++ b/src/js/package.json @@ -13,9 +13,7 @@ "mocha": "^4.1.0", "nyc": "^11.7.3", "react": "file:./external/react", - "react-dom": "file:./external/react-dom", - "selenium-webdriver": "^4.0.0-alpha.1", - "vhost": "^3.0.2" + "react-dom": "file:./external/react-dom" }, "scripts": { "test": "mocha --recursive", From 53949bc05aea7979f14e81e943be5e7494ca09f9 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Thu, 27 Sep 2018 15:01:43 -0700 Subject: [PATCH 05/43] Add selenium/cookies.js tests --- src/js/selenium/cookies.j | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/js/selenium/cookies.j diff --git a/src/js/selenium/cookies.j b/src/js/selenium/cookies.j new file mode 100644 index 0000000..e69de29 From 530c1a5d24862d15c58cf7e05a0026102da6f1ca Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Thu, 27 Sep 2018 15:02:19 -0700 Subject: [PATCH 06/43] refactoring selenium management --- src/js/selenium/selenium.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/js/selenium/selenium.js b/src/js/selenium/selenium.js index 3a113bf..e2ca627 100644 --- a/src/js/selenium/selenium.js +++ b/src/js/selenium/selenium.js @@ -1,13 +1,21 @@ +'use strict'; + const sw = require('selenium-webdriver'), express = require('express'), - vhost = require('vhost'), - etagApp = require("./etagApp"); + {App} = require("./cookies"); -const PORT = 8000; +const PORT = 8000, + host = (hostname, port) => `${hostname}:${port}`, + firstPartyHostname = 'firstparty.local', + thirdPartyHostname = 'thirdparty.local', + firstPartyHost = host(firstPartyHostname, PORT), + thirdPartyHost = host(thirdPartyHostname, PORT); /* * in /etc/hosts this requires: * 127.0.0.1 etag.local + * 127.0.0.1 firstparty.local + * 127.0.0.1 thirdparty.local * 127.0.0.1 thirdpartywithetag.local */ @@ -20,20 +28,10 @@ function loadDriverWithExtension(extPath) { .build(); } -function startApps() { - let appWithVhost = module.exports = express(); - appWithVhost.use(vhost('etag.local', etagApp(PORT))); // Serves first app - //appWithVhost.use(vhost('admin.mydomain.local', app2)); // Serves second app - - /* istanbul ignore next */ - if (!module.parent) { - appWithVhost.listen(PORT); - console.log(`Express started on port ${PORT}`); - } -} +let app = new App(module.exports = express(), firstPartyHostname, thirdPartyHostname, PORT); let path = '../.', driver = loadDriverWithExtension(path); -startApps(); -driver.get('etag.local:8000'); +app.listen(PORT); +driver.get(firstPartyHost); From f27ecd61eb42947fa8feb379643b1087dc1a7c8f Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Thu, 27 Sep 2018 15:02:50 -0700 Subject: [PATCH 07/43] Add note on running selenium tests. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3acfc30..73e3e5f 100644 --- a/README.md +++ b/README.md @@ -134,4 +134,4 @@ Exported stuff is assigned to properties on `exports` just like in node. ## Testing -From inside `src/js/` run `npm test`. To check coverage run `npm run cover`. +From inside `src/js/` you can run node tests with `npm test`, check coverage with `npm run cover`, and run selenium tests with `npm run selenium`. From d7426f74cb0a03543d3719c9e216c1f9fa5d3f4a Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Thu, 27 Sep 2018 17:02:35 -0700 Subject: [PATCH 08/43] fix name of selenium/cookies.js --- src/js/selenium/cookies.j | 0 src/js/selenium/cookies.js | 55 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) delete mode 100644 src/js/selenium/cookies.j create mode 100644 src/js/selenium/cookies.js diff --git a/src/js/selenium/cookies.j b/src/js/selenium/cookies.j deleted file mode 100644 index e69de29..0000000 diff --git a/src/js/selenium/cookies.js b/src/js/selenium/cookies.js new file mode 100644 index 0000000..e52f6db --- /dev/null +++ b/src/js/selenium/cookies.js @@ -0,0 +1,55 @@ +'use strict'; + +const express = require('express'), + {createServer} = require('http'), + vhost = require('vhost'); + +let fp = {cookie: {name: '1pname', value: '1pvalue'}}, + tp = {cookie: {name: '3pname', value: '3pvalue'}}; + +class App { + constructor(app, hostname1, hostname2, port) { + let app1 = firstParty(hostname2, port), + app2 = thirdParty(port); + app.use(vhost(hostname1, app1)); + app.use(vhost(hostname2, app2)); + Object.assign(this, {app, hostname1, hostname2, port}); + } + + async runWith(func) { + this.listen(); + await func() + this.close(); + } + listen(port=this.port) { + this.server = createServer(this.app); + this.server.listen(port); + } + close() { + this.server.close(); + } +} + +function firstParty(hostname, port) { + const app = express(); + app.get('/', (req, res) => { + console.log('got request'); + res.cookie(fp.cookie.name, fp.cookie.value); + return res.send( + `` + ); + }); + return app; +} + +function thirdParty(port) { + const app = express(); + app.get('/tracker.js', (req, res) => { + res.cookie(tp.cookie.name, tp.cookie.value); + console.log('third party hit'); + return res.send('console.log("third party script")'); + }); + return app; +} + +Object.assign(module.exports, {App}); From 9200ec5cfbcf53c6953a9161fa9a62957ff2ed63 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Fri, 28 Sep 2018 15:36:57 -0700 Subject: [PATCH 09/43] Add cookie parser as dev dependency --- src/js/package.json | 1 + src/js/selenium/{selenium.js => integration_tests.js} | 0 2 files changed, 1 insertion(+) rename src/js/selenium/{selenium.js => integration_tests.js} (100%) diff --git a/src/js/package.json b/src/js/package.json index b4e7cad..82e236f 100644 --- a/src/js/package.json +++ b/src/js/package.json @@ -6,6 +6,7 @@ "dependencies": {}, "devDependencies": { "chai": "^4.1.2", + "cookie-parser": "^1.4.3", "coveralls": "^3.0.1", "eslint": "^4.19.1", "express": "^4.16.3", diff --git a/src/js/selenium/selenium.js b/src/js/selenium/integration_tests.js similarity index 100% rename from src/js/selenium/selenium.js rename to src/js/selenium/integration_tests.js From b0f78de49d0cffe4a8058e3230d42690bad7a8a2 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Fri, 28 Sep 2018 15:37:38 -0700 Subject: [PATCH 10/43] Expand and refactor cookie app --- src/js/selenium/cookies.js | 73 ++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/src/js/selenium/cookies.js b/src/js/selenium/cookies.js index e52f6db..dc73d98 100644 --- a/src/js/selenium/cookies.js +++ b/src/js/selenium/cookies.js @@ -1,55 +1,74 @@ 'use strict'; const express = require('express'), + cookieParser = require('cookie-parser'), {createServer} = require('http'), vhost = require('vhost'); -let fp = {cookie: {name: '1pname', value: '1pvalue'}}, - tp = {cookie: {name: '3pname', value: '3pvalue'}}; +let fpcookie = {name: '1pname', value: '1pvalue'}, + tpcookie = {name: '3pname', value: '3pvalue'}; -class App { - constructor(app, hostname1, hostname2, port) { - let app1 = firstParty(hostname2, port), - app2 = thirdParty(port); - app.use(vhost(hostname1, app1)); - app.use(vhost(hostname2, app2)); - Object.assign(this, {app, hostname1, hostname2, port}); +class Channel { + constructor() { + this.items = []; + this.waiting = []; } - - async runWith(func) { - this.listen(); - await func() - this.close(); + async popQueue() { + if (this.items.length > 0) { + return this.items.pop(); + } else { + return new Promise((resolve) => { + this.waiting.push(resolve); + }); + } } - listen(port=this.port) { - this.server = createServer(this.app); - this.server.listen(port); + async next() { + return await this.popQueue(); } - close() { - this.server.close(); + push(item) { + if (this.waiting.length > 0) { + this.waiting.shift()(item); + } else { + this.items.push(item); + } } } -function firstParty(hostname, port) { +function firstPartyApp(thirdPartyHostname, port) { const app = express(); + app.use(cookieParser()); + app.requests = new Channel(); + app.get('/', (req, res) => { - console.log('got request'); - res.cookie(fp.cookie.name, fp.cookie.value); + app.requests.push(req); + res.cookie(fpcookie.name, fpcookie.value); return res.send( - `` + `` ); }); return app; } -function thirdParty(port) { +function thirdPartyApp() { const app = express(); + app.use(cookieParser()); + app.requests = new Channel(); + app.get('/tracker.js', (req, res) => { - res.cookie(tp.cookie.name, tp.cookie.value); - console.log('third party hit'); + app.requests.push(req); + res.cookie(tpcookie.name, tpcookie.value); return res.send('console.log("third party script")'); }); return app; } -Object.assign(module.exports, {App}); +function cookieApp(app, firstPartyHostname, thirdPartyHostname, port) { + let firstParty = firstPartyApp(thirdPartyHostname, port), + thirdParty = thirdPartyApp(); + app.use(vhost(firstPartyHostname, firstParty)); + app.use(vhost(thirdPartyHostname, thirdParty)); + Object.assign(app, {firstParty, thirdParty, firstPartyHostname, thirdPartyHostname, port}); + return app; +} + +Object.assign(module.exports, {cookieApp, fpcookie, tpcookie}); From f27dc924b5a347f21c7856be6d283d787e5d341a Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Fri, 28 Sep 2018 15:37:46 -0700 Subject: [PATCH 11/43] Add actual mocha tests. --- src/js/selenium/integration_tests.js | 51 +++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/src/js/selenium/integration_tests.js b/src/js/selenium/integration_tests.js index e2ca627..71154b1 100644 --- a/src/js/selenium/integration_tests.js +++ b/src/js/selenium/integration_tests.js @@ -1,22 +1,33 @@ 'use strict'; +const {assert} = require('chai'); + const sw = require('selenium-webdriver'), express = require('express'), - {App} = require("./cookies"); + {createServer} = require('http'), + {cookieApp, fpcookie, tpcookie} = require("./cookies"); -const PORT = 8000, +const path = '../.', + PORT = 8000, host = (hostname, port) => `${hostname}:${port}`, firstPartyHostname = 'firstparty.local', thirdPartyHostname = 'thirdparty.local', firstPartyHost = host(firstPartyHostname, PORT), thirdPartyHost = host(thirdPartyHostname, PORT); +function startApp(app, port=PORT) { + app.server = createServer(app); + app.server.listen(port); +} + +function stopApp(app) { + app.server.close(); +} + /* * in /etc/hosts this requires: - * 127.0.0.1 etag.local * 127.0.0.1 firstparty.local * 127.0.0.1 thirdparty.local - * 127.0.0.1 thirdpartywithetag.local */ function loadDriverWithExtension(extPath) { @@ -28,10 +39,32 @@ function loadDriverWithExtension(extPath) { .build(); } -let app = new App(module.exports = express(), firstPartyHostname, thirdPartyHostname, PORT); +describe('selenium test', function() { + beforeEach(function() { + this.app = cookieApp(module.exports = express(), firstPartyHostname, thirdPartyHostname, PORT); + this.driver = loadDriverWithExtension(path); + startApp(this.app); + }); + afterEach(function() { + stopApp(this.app); + this.driver.quit(); + }); -let path = '../.', - driver = loadDriverWithExtension(path); + it('blocks cookies', async function() { + let {app, driver} = this; + driver.get(firstPartyHost); + let request = await app.firstParty.requests.next(); + // no cookies initially + assert.deepEqual(request.cookies, {}); + request = await app.thirdParty.requests.next(); + assert.deepEqual(request.cookies, {}); -app.listen(PORT); -driver.get(firstPartyHost); + driver.get(firstPartyHost); + request = await app.firstParty.requests.next(); + // now we have first party cookies set + assert.deepEqual(request.cookies, {[fpcookie.name]: fpcookie.value}); + request = await app.thirdParty.requests.next(); + // but not third party cookies + assert.deepEqual(request.cookies, {}); + }); +}); From b513375998aaa9973c2adc0e9a0be0a3b647ba01 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Fri, 28 Sep 2018 15:39:29 -0700 Subject: [PATCH 12/43] Update npm run selenium. This reflects selenium test name change. And uses mocha to run the tests. --- src/js/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/package.json b/src/js/package.json index 82e236f..cdde9ba 100644 --- a/src/js/package.json +++ b/src/js/package.json @@ -18,7 +18,7 @@ }, "scripts": { "test": "mocha --recursive", - "selenium": "node ./selenium/selenium.js", + "selenium": "mocha ./selenium/integration_tests.js", "lint": "git ls-files | grep \".js$\" | grep -v \"external\" | xargs eslint", "loc": "git ls-files | grep -v 'psl.js' | xargs cat | wc -l", "cover": "nyc --reporter=html --reporter=text mocha", From a0dbb3972fc3e907306cfe39196211c6db716c34 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 13:29:51 -0700 Subject: [PATCH 13/43] Test with a matrix in .travis.yml --- .travis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c6595fd..9e4e0c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,8 @@ language: node_js node_js: - "10" install: make npm_install -script: make test +matrix: + include: + - name: "Node Unit Tests" + env: TEST_ARG=test +script: make $TEST_ARG From e1f9910433f79cbee85a5a0d4460e91ff359c074 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 13:38:03 -0700 Subject: [PATCH 14/43] git mv ./src/js/selenium . --- {src/js/selenium => selenium}/cookies.js | 0 {src/js/selenium => selenium}/etagApp.js | 0 {src/js/selenium => selenium}/integration_tests.js | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {src/js/selenium => selenium}/cookies.js (100%) rename {src/js/selenium => selenium}/etagApp.js (100%) rename {src/js/selenium => selenium}/integration_tests.js (100%) diff --git a/src/js/selenium/cookies.js b/selenium/cookies.js similarity index 100% rename from src/js/selenium/cookies.js rename to selenium/cookies.js diff --git a/src/js/selenium/etagApp.js b/selenium/etagApp.js similarity index 100% rename from src/js/selenium/etagApp.js rename to selenium/etagApp.js diff --git a/src/js/selenium/integration_tests.js b/selenium/integration_tests.js similarity index 100% rename from src/js/selenium/integration_tests.js rename to selenium/integration_tests.js From 6bdd453cfe6135e50eef0e14d51a9e827679ee6f Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 13:39:13 -0700 Subject: [PATCH 15/43] give selenium tests their own package.json --- selenium/package.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 selenium/package.json diff --git a/selenium/package.json b/selenium/package.json new file mode 100644 index 0000000..f266895 --- /dev/null +++ b/selenium/package.json @@ -0,0 +1,19 @@ +{ + "name": "privacy-possum-selenium-tests", + "version": "1.0.0", + "description": "", + "main": "integration_tests.js", + "scripts": { + "test": "mocha ./integration_tests.js" + }, + "author": "", + "license": "ISC", + "devDependencies": { + "chai": "^4.2.0", + "cookie-parser": "^1.4.3", + "express": "^4.16.3", + "mocha": "^5.2.0", + "selenium-webdriver": "^4.0.0-alpha.1", + "vhost": "^3.0.2" + } +} From 902a2b184727ea34b7af44d405d36dbaeb9b1abb Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 13:41:14 -0700 Subject: [PATCH 16/43] Make selenium script point to correct ext src --- selenium/integration_tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selenium/integration_tests.js b/selenium/integration_tests.js index 71154b1..f6fa40e 100644 --- a/selenium/integration_tests.js +++ b/selenium/integration_tests.js @@ -7,7 +7,7 @@ const sw = require('selenium-webdriver'), {createServer} = require('http'), {cookieApp, fpcookie, tpcookie} = require("./cookies"); -const path = '../.', +const path = '../src/.', PORT = 8000, host = (hostname, port) => `${hostname}:${port}`, firstPartyHostname = 'firstparty.local', From 28dd4d3df66eab60aeb4b28ea20ddc89cca4c91e Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 13:54:33 -0700 Subject: [PATCH 17/43] Add run_in_dir func and selenium_dir to test tools --- scripts/source_me.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/source_me.sh b/scripts/source_me.sh index 9f3d353..042a893 100644 --- a/scripts/source_me.sh +++ b/scripts/source_me.sh @@ -5,3 +5,11 @@ toplevel=$(git rev-parse --show-toplevel) src_dir=${toplevel}/src js_dir=${src_dir}/js +selenium_dir=${toplevel}/selenium + +run_in_dir() { +pushd $1 > /dev/null +trap "popd > /dev/null" EXIT + +$2 +} From 0078af58d16bd8c1eaeabbb311ed73112061316e Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 13:55:49 -0700 Subject: [PATCH 18/43] Use run_in_dir in unittest script --- scripts/test.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/test.sh b/scripts/test.sh index a3da803..d19b64c 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,7 +1,4 @@ #!/usr/bin/env bash source $(git rev-parse --show-toplevel)/scripts/source_me.sh -pushd ${js_dir} > /dev/null -trap "popd > /dev/null" EXIT - -npm test +run_in_dir $js_dir "npm test" From 1d12b070b860584a7f71cd17d4ac034975402738 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 13:56:30 -0700 Subject: [PATCH 19/43] Add scripts/selenium_test.sh --- scripts/selenium_test.sh | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 scripts/selenium_test.sh diff --git a/scripts/selenium_test.sh b/scripts/selenium_test.sh new file mode 100755 index 0000000..d1a1bdf --- /dev/null +++ b/scripts/selenium_test.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +source $(git rev-parse --show-toplevel)/scripts/source_me.sh + +run_in_dir $selenium_dir "npm test" From f6ed8b697813f3fb04d73ae4f096db26bc6cf2d7 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 13:57:36 -0700 Subject: [PATCH 20/43] Add selenium_test target to Makefile --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 40b069e..3df2b92 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ test: ./scripts/test.sh +selenium_test: + ./scripts/selenium_test.sh + npm_install: ./scripts/npm_install.sh From aa1b92cf770ade3a15a3291365ada42b55f0b501 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 14:16:18 -0700 Subject: [PATCH 21/43] make npm_install.sh take a directory argument --- scripts/npm_install.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/npm_install.sh b/scripts/npm_install.sh index 0475fb3..350d2c0 100755 --- a/scripts/npm_install.sh +++ b/scripts/npm_install.sh @@ -1,7 +1,4 @@ #!/usr/bin/env bash source $(git rev-parse --show-toplevel)/scripts/source_me.sh -pushd ${js_dir} > /dev/null -trap "popd > /dev/null" EXIT - -npm install +run_in_dir $1 "npm install" From 494e653a1f83f56dadd0d9765065b92d8b29667d Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 14:16:44 -0700 Subject: [PATCH 22/43] Add npm_install_selenium, use new npm_install.sh --- Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 3df2b92..4798cb3 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,11 @@ test: selenium_test: ./scripts/selenium_test.sh -npm_install: - ./scripts/npm_install.sh +npm_install_node: + ./scripts/npm_install.sh src/js/. + +npm_install_selenium: + ./scripts/npm_install.sh selenium/. psl: ./scripts/getpsl.py > src/js/domains/psl.js @@ -13,4 +16,4 @@ psl: release: ./scripts/release.sh -.PHONY: test npm_install psl release +.PHONY: test selenium_test npm_install_node npm_install_selenium psl release From 94e015bac66427229942d6748cf75bb951879a17 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 14:17:16 -0700 Subject: [PATCH 23/43] call script and install from inside travis matrix --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9e4e0c5..b2062ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,5 @@ install: make npm_install matrix: include: - name: "Node Unit Tests" - env: TEST_ARG=test -script: make $TEST_ARG + install: make npm_install_node + script: make test From cef34d32de801e4ef8af641ad6b96d3fae2d5e3a Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 14:32:17 -0700 Subject: [PATCH 24/43] Install xvfb as dev-dep for selenium --- selenium/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/selenium/package.json b/selenium/package.json index f266895..956e0cc 100644 --- a/selenium/package.json +++ b/selenium/package.json @@ -14,6 +14,7 @@ "express": "^4.16.3", "mocha": "^5.2.0", "selenium-webdriver": "^4.0.0-alpha.1", - "vhost": "^3.0.2" + "vhost": "^3.0.2", + "xvfb": "^0.2.3" } } From 9ca59e98bc14b8ea7a6817d6f98e75af7acad20c Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 14:32:49 -0700 Subject: [PATCH 25/43] WIP use xvfb to run selenium code --- selenium/integration_tests.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/selenium/integration_tests.js b/selenium/integration_tests.js index f6fa40e..30d4cfe 100644 --- a/selenium/integration_tests.js +++ b/selenium/integration_tests.js @@ -4,6 +4,7 @@ const {assert} = require('chai'); const sw = require('selenium-webdriver'), express = require('express'), + Xvfb = require('xvfb'), {createServer} = require('http'), {cookieApp, fpcookie, tpcookie} = require("./cookies"); @@ -41,6 +42,8 @@ function loadDriverWithExtension(extPath) { describe('selenium test', function() { beforeEach(function() { + this.xvfb = new Xvfb(); + this.xvfb.startSync(); this.app = cookieApp(module.exports = express(), firstPartyHostname, thirdPartyHostname, PORT); this.driver = loadDriverWithExtension(path); startApp(this.app); @@ -48,6 +51,7 @@ describe('selenium test', function() { afterEach(function() { stopApp(this.app); this.driver.quit(); + this.xvfb.stopSync(); }); it('blocks cookies', async function() { From 37253956a13517e31a9320de4578ae8b2a8731cb Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 14:33:57 -0700 Subject: [PATCH 26/43] Add selenium to .travis.yml --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index b2062ba..6812afa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,3 +7,6 @@ matrix: - name: "Node Unit Tests" install: make npm_install_node script: make test + - name: "Selenium Unit Tests" + install: make npm_install_selenium + script: make selenium_test From 8301926dcf4c72f20dacb5b7c476e520f629cc2a Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 14:36:12 -0700 Subject: [PATCH 27/43] Add chromedriver to selenium dev-deps --- selenium/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/selenium/package.json b/selenium/package.json index 956e0cc..4f418ef 100644 --- a/selenium/package.json +++ b/selenium/package.json @@ -10,6 +10,7 @@ "license": "ISC", "devDependencies": { "chai": "^4.2.0", + "chromedriver": "^2.42.0", "cookie-parser": "^1.4.3", "express": "^4.16.3", "mocha": "^5.2.0", From b3620dd037faa163c5519327959426b18cea8680 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 19:05:58 -0700 Subject: [PATCH 28/43] Install chrome in travis.yml --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 6812afa..3a1ecb3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,3 +10,5 @@ matrix: - name: "Selenium Unit Tests" install: make npm_install_selenium script: make selenium_test + addons: + chrome: stable From f0bcbf2284dd4400dd6ad96186c734feddf9fc8f Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 19:12:13 -0700 Subject: [PATCH 29/43] Try starting xvfb in .travis.yml --- .travis.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3a1ecb3..ac402af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,10 @@ matrix: install: make npm_install_node script: make test - name: "Selenium Unit Tests" - install: make npm_install_selenium - script: make selenium_test addons: chrome: stable + before_install: + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start + install: make npm_install_selenium + script: make selenium_test From dafc3e4b8eb3a42c858d13edc4dfd27dfe687515 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 19:18:25 -0700 Subject: [PATCH 30/43] Pass the --no-sandbox flag to chrome This should fix the bug referred to here: https://docs.travis-ci.com/user/chrome#sandboxing --- selenium/integration_tests.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/selenium/integration_tests.js b/selenium/integration_tests.js index 30d4cfe..dc8e0e1 100644 --- a/selenium/integration_tests.js +++ b/selenium/integration_tests.js @@ -33,7 +33,10 @@ function stopApp(app) { function loadDriverWithExtension(extPath) { let chromeOptions = sw.Capabilities.chrome(); - chromeOptions.set("chromeOptions", {"args": ['--load-extension='+extPath]}); + chromeOptions.set("chromeOptions", {"args": [ + '--load-extension='+extPath, + '--no-sandbox', + ]}); return new sw.Builder() .forBrowser('chrome') .withCapabilities(chromeOptions) From b49033ea2fce11de534bcb4702ab68b30120a66e Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 19:23:13 -0700 Subject: [PATCH 31/43] Try removing xvfb from selenium code --- selenium/integration_tests.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/selenium/integration_tests.js b/selenium/integration_tests.js index dc8e0e1..430cc45 100644 --- a/selenium/integration_tests.js +++ b/selenium/integration_tests.js @@ -4,7 +4,6 @@ const {assert} = require('chai'); const sw = require('selenium-webdriver'), express = require('express'), - Xvfb = require('xvfb'), {createServer} = require('http'), {cookieApp, fpcookie, tpcookie} = require("./cookies"); @@ -45,8 +44,6 @@ function loadDriverWithExtension(extPath) { describe('selenium test', function() { beforeEach(function() { - this.xvfb = new Xvfb(); - this.xvfb.startSync(); this.app = cookieApp(module.exports = express(), firstPartyHostname, thirdPartyHostname, PORT); this.driver = loadDriverWithExtension(path); startApp(this.app); @@ -54,7 +51,6 @@ describe('selenium test', function() { afterEach(function() { stopApp(this.app); this.driver.quit(); - this.xvfb.stopSync(); }); it('blocks cookies', async function() { From 6d5ebe565d6b2a96264abd3d7c3e81b47191aa3a Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 19:27:11 -0700 Subject: [PATCH 32/43] Use "trusty" as distribution on .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ac402af..b9edf17 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +dist: trusty language: node_js node_js: - "10" From 7d527a136e8ad33667f0deecb63d2d526b37c657 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 19:34:10 -0700 Subject: [PATCH 33/43] try adding sudo: required to .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index b9edf17..1606906 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ dist: trusty +sudo: required language: node_js node_js: - "10" From 1e78f14778b7033464ca49b0a0005491dd96dd9d Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 19:40:10 -0700 Subject: [PATCH 34/43] add some debugging code --- selenium/integration_tests.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/selenium/integration_tests.js b/selenium/integration_tests.js index 430cc45..7b5d890 100644 --- a/selenium/integration_tests.js +++ b/selenium/integration_tests.js @@ -44,9 +44,18 @@ function loadDriverWithExtension(extPath) { describe('selenium test', function() { beforeEach(function() { + let i = 0; + console.log(`at number: ${i}`); + i += 1; this.app = cookieApp(module.exports = express(), firstPartyHostname, thirdPartyHostname, PORT); + console.log(`at number: ${i}`); + i += 1; this.driver = loadDriverWithExtension(path); + console.log(`at number: ${i}`); + i += 1; startApp(this.app); + console.log(`at number: ${i}`); + i += 1; }); afterEach(function() { stopApp(this.app); From 490c3f88cb386dc2f9ee7802e407fc97897f718f Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 20:03:51 -0700 Subject: [PATCH 35/43] more debugging code --- selenium/integration_tests.js | 41 +++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/selenium/integration_tests.js b/selenium/integration_tests.js index 7b5d890..f664f80 100644 --- a/selenium/integration_tests.js +++ b/selenium/integration_tests.js @@ -44,18 +44,19 @@ function loadDriverWithExtension(extPath) { describe('selenium test', function() { beforeEach(function() { - let i = 0; - console.log(`at number: ${i}`); - i += 1; + // we need to only use xvfb when asked + this.i = 0; + console.log(`at number: ${this.i}`); + this.i += 1; this.app = cookieApp(module.exports = express(), firstPartyHostname, thirdPartyHostname, PORT); - console.log(`at number: ${i}`); - i += 1; + console.log(`at number: ${this.i}`); + this.i += 1; this.driver = loadDriverWithExtension(path); - console.log(`at number: ${i}`); - i += 1; + console.log(`at number: ${this.i}`); + this.i += 1; startApp(this.app); - console.log(`at number: ${i}`); - i += 1; + console.log(`at number: ${this.i}`); + this.i += 1; }); afterEach(function() { stopApp(this.app); @@ -64,19 +65,41 @@ describe('selenium test', function() { it('blocks cookies', async function() { let {app, driver} = this; + console.log(`at number: ${this.i}`); + this.i += 1; driver.get(firstPartyHost); + console.log(`at number: ${this.i}`); + this.i += 1; let request = await app.firstParty.requests.next(); + console.log(`at number: ${this.i}`); + this.i += 1; // no cookies initially assert.deepEqual(request.cookies, {}); + console.log(`at number: ${this.i}`); + this.i += 1; request = await app.thirdParty.requests.next(); + console.log(`at number: ${this.i}`); + this.i += 1; assert.deepEqual(request.cookies, {}); + console.log(`at number: ${this.i}`); + this.i += 1; driver.get(firstPartyHost); + console.log(`at number: ${this.i}`); + this.i += 1; request = await app.firstParty.requests.next(); + console.log(`at number: ${this.i}`); + this.i += 1; // now we have first party cookies set assert.deepEqual(request.cookies, {[fpcookie.name]: fpcookie.value}); + console.log(`at number: ${this.i}`); + this.i += 1; request = await app.thirdParty.requests.next(); + console.log(`at number: ${this.i}`); + this.i += 1; // but not third party cookies assert.deepEqual(request.cookies, {}); + console.log(`at number: ${this.i}`); + this.i += 1; }); }); From 12a30cd947f45975b21e4ed8623baef96a3f075a Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 20:12:54 -0700 Subject: [PATCH 36/43] Add test domains to /etc/hosts --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 1606906..e02b1c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,9 @@ matrix: - name: "Selenium Unit Tests" addons: chrome: stable + hosts: + - firstparty.local + - thirdparty.local before_install: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start From 918b04afa87948c52cf1d24ff068af4afdbd0b4f Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 20:33:41 -0700 Subject: [PATCH 37/43] Cleaning up selenium leftovers --- selenium/integration_tests.js | 33 +-------------------------------- src/js/package.json | 3 --- 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/selenium/integration_tests.js b/selenium/integration_tests.js index f664f80..b396192 100644 --- a/selenium/integration_tests.js +++ b/selenium/integration_tests.js @@ -33,7 +33,7 @@ function stopApp(app) { function loadDriverWithExtension(extPath) { let chromeOptions = sw.Capabilities.chrome(); chromeOptions.set("chromeOptions", {"args": [ - '--load-extension='+extPath, + `--load-extension=${extPath}`, '--no-sandbox', ]}); return new sw.Builder() @@ -45,18 +45,9 @@ function loadDriverWithExtension(extPath) { describe('selenium test', function() { beforeEach(function() { // we need to only use xvfb when asked - this.i = 0; - console.log(`at number: ${this.i}`); - this.i += 1; this.app = cookieApp(module.exports = express(), firstPartyHostname, thirdPartyHostname, PORT); - console.log(`at number: ${this.i}`); - this.i += 1; this.driver = loadDriverWithExtension(path); - console.log(`at number: ${this.i}`); - this.i += 1; startApp(this.app); - console.log(`at number: ${this.i}`); - this.i += 1; }); afterEach(function() { stopApp(this.app); @@ -65,41 +56,19 @@ describe('selenium test', function() { it('blocks cookies', async function() { let {app, driver} = this; - console.log(`at number: ${this.i}`); - this.i += 1; driver.get(firstPartyHost); - console.log(`at number: ${this.i}`); - this.i += 1; let request = await app.firstParty.requests.next(); - console.log(`at number: ${this.i}`); - this.i += 1; // no cookies initially assert.deepEqual(request.cookies, {}); - console.log(`at number: ${this.i}`); - this.i += 1; request = await app.thirdParty.requests.next(); - console.log(`at number: ${this.i}`); - this.i += 1; assert.deepEqual(request.cookies, {}); - console.log(`at number: ${this.i}`); - this.i += 1; driver.get(firstPartyHost); - console.log(`at number: ${this.i}`); - this.i += 1; request = await app.firstParty.requests.next(); - console.log(`at number: ${this.i}`); - this.i += 1; // now we have first party cookies set assert.deepEqual(request.cookies, {[fpcookie.name]: fpcookie.value}); - console.log(`at number: ${this.i}`); - this.i += 1; request = await app.thirdParty.requests.next(); - console.log(`at number: ${this.i}`); - this.i += 1; // but not third party cookies assert.deepEqual(request.cookies, {}); - console.log(`at number: ${this.i}`); - this.i += 1; }); }); diff --git a/src/js/package.json b/src/js/package.json index cdde9ba..674c046 100644 --- a/src/js/package.json +++ b/src/js/package.json @@ -6,10 +6,8 @@ "dependencies": {}, "devDependencies": { "chai": "^4.1.2", - "cookie-parser": "^1.4.3", "coveralls": "^3.0.1", "eslint": "^4.19.1", - "express": "^4.16.3", "jsdom": "^11.10.0", "mocha": "^4.1.0", "nyc": "^11.7.3", @@ -18,7 +16,6 @@ }, "scripts": { "test": "mocha --recursive", - "selenium": "mocha ./selenium/integration_tests.js", "lint": "git ls-files | grep \".js$\" | grep -v \"external\" | xargs eslint", "loc": "git ls-files | grep -v 'psl.js' | xargs cat | wc -l", "cover": "nyc --reporter=html --reporter=text mocha", From 1981299a940eca9af97901fe8b11f55da6bc3351 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 20:34:42 -0700 Subject: [PATCH 38/43] Rm unused node-xvfb --- selenium/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/selenium/package.json b/selenium/package.json index 4f418ef..f27a132 100644 --- a/selenium/package.json +++ b/selenium/package.json @@ -15,7 +15,6 @@ "express": "^4.16.3", "mocha": "^5.2.0", "selenium-webdriver": "^4.0.0-alpha.1", - "vhost": "^3.0.2", - "xvfb": "^0.2.3" + "vhost": "^3.0.2" } } From b913dd784eac52c381f83ca95d2f2836d4857e5c Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 20:50:31 -0700 Subject: [PATCH 39/43] move .eslintrc.json to top level --- src/js/.eslintrc.json => .eslintrc.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/js/.eslintrc.json => .eslintrc.json (100%) diff --git a/src/js/.eslintrc.json b/.eslintrc.json similarity index 100% rename from src/js/.eslintrc.json rename to .eslintrc.json From e0d81809989ee39907cfb7615d25f936365d9b83 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 20:51:04 -0700 Subject: [PATCH 40/43] Move selenium utils into their own file --- selenium/cookies.js | 1 - selenium/integration_tests.js | 46 ++++--------------------------- selenium/utils.js | 51 +++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 42 deletions(-) create mode 100644 selenium/utils.js diff --git a/selenium/cookies.js b/selenium/cookies.js index dc73d98..dd75d66 100644 --- a/selenium/cookies.js +++ b/selenium/cookies.js @@ -2,7 +2,6 @@ const express = require('express'), cookieParser = require('cookie-parser'), - {createServer} = require('http'), vhost = require('vhost'); let fpcookie = {name: '1pname', value: '1pvalue'}, diff --git a/selenium/integration_tests.js b/selenium/integration_tests.js index b396192..82703a8 100644 --- a/selenium/integration_tests.js +++ b/selenium/integration_tests.js @@ -2,51 +2,15 @@ const {assert} = require('chai'); -const sw = require('selenium-webdriver'), - express = require('express'), - {createServer} = require('http'), - {cookieApp, fpcookie, tpcookie} = require("./cookies"); +const express = require('express'), + {newDriver, startApp, stopApp, PORT, firstPartyHostname, thirdPartyHostname, firstPartyHost} = require('./utils'), + {cookieApp, fpcookie} = require("./cookies"); -const path = '../src/.', - PORT = 8000, - host = (hostname, port) => `${hostname}:${port}`, - firstPartyHostname = 'firstparty.local', - thirdPartyHostname = 'thirdparty.local', - firstPartyHost = host(firstPartyHostname, PORT), - thirdPartyHost = host(thirdPartyHostname, PORT); - -function startApp(app, port=PORT) { - app.server = createServer(app); - app.server.listen(port); -} - -function stopApp(app) { - app.server.close(); -} - -/* - * in /etc/hosts this requires: - * 127.0.0.1 firstparty.local - * 127.0.0.1 thirdparty.local - */ - -function loadDriverWithExtension(extPath) { - let chromeOptions = sw.Capabilities.chrome(); - chromeOptions.set("chromeOptions", {"args": [ - `--load-extension=${extPath}`, - '--no-sandbox', - ]}); - return new sw.Builder() - .forBrowser('chrome') - .withCapabilities(chromeOptions) - .build(); -} - -describe('selenium test', function() { +describe('cookie tests', function() { beforeEach(function() { // we need to only use xvfb when asked this.app = cookieApp(module.exports = express(), firstPartyHostname, thirdPartyHostname, PORT); - this.driver = loadDriverWithExtension(path); + this.driver = newDriver(); startApp(this.app); }); afterEach(function() { diff --git a/selenium/utils.js b/selenium/utils.js new file mode 100644 index 0000000..68fc457 --- /dev/null +++ b/selenium/utils.js @@ -0,0 +1,51 @@ +'use strict'; + +const sw = require('selenium-webdriver'), + {createServer} = require('http'); + +function startApp(app, port=PORT) { + app.server = createServer(app); + app.server.listen(port); +} + +const path = '../src/.', + PORT = 8000, + host = (hostname, port) => `${hostname}:${port}`, + firstPartyHostname = 'firstparty.local', + thirdPartyHostname = 'thirdparty.local', + firstPartyHost = host(firstPartyHostname, PORT), + thirdPartyHost = host(thirdPartyHostname, PORT); + +function startApp(app, port=PORT) { + app.server = createServer(app); + app.server.listen(port); +} + +function stopApp(app) { + app.server.close(); +} + +/* + * in /etc/hosts this requires: + * 127.0.0.1 firstparty.local + * 127.0.0.1 thirdparty.local + */ + +function loadDriverWithExtension(extPath) { + let chromeOptions = sw.Capabilities.chrome(); + chromeOptions.set("chromeOptions", {"args": [ + `--load-extension=${extPath}`, + '--no-sandbox', + ]}); + return new sw.Builder() + .forBrowser('chrome') + .withCapabilities(chromeOptions) + .build(); +} + +function newDriver() { + return loadDriverWithExtension(path); +} + + +Object.assign(module.exports, {newDriver, startApp, stopApp, PORT, firstPartyHostname, thirdPartyHostname, firstPartyHost, thirdPartyHost}); From 6e63b0a1f0df38f41b1db50a7494b7457dd43c5c Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 20:56:51 -0700 Subject: [PATCH 41/43] Rename targets in the Makefile --- .travis.yml | 4 ++-- Makefile | 6 +++--- README.md | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index e02b1c0..1a8610a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ matrix: include: - name: "Node Unit Tests" install: make npm_install_node - script: make test + script: make test_node - name: "Selenium Unit Tests" addons: chrome: stable @@ -19,4 +19,4 @@ matrix: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start install: make npm_install_selenium - script: make selenium_test + script: make test_selenium diff --git a/Makefile b/Makefile index 4798cb3..dac6b42 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ -test: +test_node: ./scripts/test.sh -selenium_test: +test_selenium: ./scripts/selenium_test.sh npm_install_node: @@ -16,4 +16,4 @@ psl: release: ./scripts/release.sh -.PHONY: test selenium_test npm_install_node npm_install_selenium psl release +.PHONY: test_node test_selenium npm_install_node npm_install_selenium psl release diff --git a/README.md b/README.md index 73e3e5f..6ca7a64 100644 --- a/README.md +++ b/README.md @@ -134,4 +134,4 @@ Exported stuff is assigned to properties on `exports` just like in node. ## Testing -From inside `src/js/` you can run node tests with `npm test`, check coverage with `npm run cover`, and run selenium tests with `npm run selenium`. +From inside `src/js/` you can run node tests with `npm test`, check coverage with `npm run cover`, and run selenium tests inside `selenium/` by running `npm test`. From 9f92adefa47bd680810d3a547f4cfa1bbb036ffe Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 20:57:58 -0700 Subject: [PATCH 42/43] Rm unused etag tests --- selenium/etagApp.js | 47 --------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 selenium/etagApp.js diff --git a/selenium/etagApp.js b/selenium/etagApp.js deleted file mode 100644 index 9f5bb76..0000000 --- a/selenium/etagApp.js +++ /dev/null @@ -1,47 +0,0 @@ -const express = require('express'), - vhost = require('vhost'); - -class App { - constructor(host, port) { - } -} - -module.exports = port => { - const firstApp = express(); - firstApp.get('/', (req, res) => { - console.log('got a reqest'); - return res.send( -`` - ); - }); - return firstApp; -} - -/* - * todo finish implementing the etag test based on this flask code - -from flask import Flask, Response, request -app = Flask(__name__) - -@app.route('/') -def hello_world(): - return ''' - -Hello, World! -''' - -@app.route('/tracker.js') -def tracker(): - resp = Response('document.documentElement.appendChild(document.createTextNode("foobar"))') - req_if_none_match = request.headers.get('if-none-match') - if (req_if_none_match and req_if_none_match.startswith('count:')): - this_count = int(req_if_none_match.split(':')[-1]) - etag = 'count:%s' % (this_count + 1) - print('increment'); - else: - print('fresh') - etag = 'count:0' - resp.headers['etag'] = etag - print(etag); - return resp - */ From a786f22d0b224a253cfe389f66769582d8985993 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Sun, 30 Sep 2018 21:18:16 -0700 Subject: [PATCH 43/43] Clean up selenium test scripts to have simpler API --- scripts/source_me.sh | 1 - selenium/cookies.js | 19 +++++++++---------- selenium/integration_tests.js | 6 ++---- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/scripts/source_me.sh b/scripts/source_me.sh index 042a893..da6073e 100644 --- a/scripts/source_me.sh +++ b/scripts/source_me.sh @@ -10,6 +10,5 @@ selenium_dir=${toplevel}/selenium run_in_dir() { pushd $1 > /dev/null trap "popd > /dev/null" EXIT - $2 } diff --git a/selenium/cookies.js b/selenium/cookies.js index dd75d66..fcb9f2b 100644 --- a/selenium/cookies.js +++ b/selenium/cookies.js @@ -2,6 +2,7 @@ const express = require('express'), cookieParser = require('cookie-parser'), + {firstPartyHostname, thirdPartyHostname, thirdPartyHost} = require('./utils'), vhost = require('vhost'); let fpcookie = {name: '1pname', value: '1pvalue'}, @@ -33,8 +34,7 @@ class Channel { } } -function firstPartyApp(thirdPartyHostname, port) { - const app = express(); +function firstPartyApp(app = express(), tpHost = thirdPartyHost) { app.use(cookieParser()); app.requests = new Channel(); @@ -42,14 +42,13 @@ function firstPartyApp(thirdPartyHostname, port) { app.requests.push(req); res.cookie(fpcookie.name, fpcookie.value); return res.send( - `` + `` ); }); return app; } -function thirdPartyApp() { - const app = express(); +function thirdPartyApp(app = express()) { app.use(cookieParser()); app.requests = new Channel(); @@ -61,12 +60,12 @@ function thirdPartyApp() { return app; } -function cookieApp(app, firstPartyHostname, thirdPartyHostname, port) { - let firstParty = firstPartyApp(thirdPartyHostname, port), +function cookieApp(app = express(), fpHostname = firstPartyHostname, tpHostname = thirdPartyHostname) { + let firstParty = firstPartyApp(), thirdParty = thirdPartyApp(); - app.use(vhost(firstPartyHostname, firstParty)); - app.use(vhost(thirdPartyHostname, thirdParty)); - Object.assign(app, {firstParty, thirdParty, firstPartyHostname, thirdPartyHostname, port}); + app.use(vhost(fpHostname, firstParty)); + app.use(vhost(tpHostname, thirdParty)); + Object.assign(app, {firstParty, thirdParty}); return app; } diff --git a/selenium/integration_tests.js b/selenium/integration_tests.js index 82703a8..7dd524b 100644 --- a/selenium/integration_tests.js +++ b/selenium/integration_tests.js @@ -2,14 +2,12 @@ const {assert} = require('chai'); -const express = require('express'), - {newDriver, startApp, stopApp, PORT, firstPartyHostname, thirdPartyHostname, firstPartyHost} = require('./utils'), +const {newDriver, startApp, stopApp, firstPartyHost} = require('./utils'), {cookieApp, fpcookie} = require("./cookies"); describe('cookie tests', function() { beforeEach(function() { - // we need to only use xvfb when asked - this.app = cookieApp(module.exports = express(), firstPartyHostname, thirdPartyHostname, PORT); + this.app = cookieApp(); this.driver = newDriver(); startApp(this.app); });