diff --git a/selenium/cookies.js b/selenium/cookies.js
index 9335077..8a29f68 100644
--- a/selenium/cookies.js
+++ b/selenium/cookies.js
@@ -1,19 +1,20 @@
'use strict';
-const cookieParser = require('cookie-parser'),
+const express = require('express'),
+ cookieParser = require('cookie-parser'),
{requestRecorderMiddleware, baseTestApp} = require('./utils');
let fpcookie = {name: '1pname', value: '1pvalue'},
tpcookie = {name: '3pname', value: '3pvalue'};
-function cookieSetterApp(cookieName, cookieValue) {
- let app = requestRecorderMiddleware();
+function cookieSetterApp(cookieName, cookieValue, app = express()) {
app.use(cookieParser());
app.use((req, res, next) => {
res.cookie(cookieName, cookieValue);
next();
});
+ requestRecorderMiddleware(app);
return app;
}
diff --git a/selenium/integration_tests.js b/selenium/integration_tests.js
index 314c1e0..3a8bb86 100644
--- a/selenium/integration_tests.js
+++ b/selenium/integration_tests.js
@@ -7,9 +7,9 @@ const {newDriver, startApp, stopApp, firstPartyHost} = require('./utils'),
{etagApp} = require('./etags');
describe('etag tests', function() {
- beforeEach(function() {
+ beforeEach(async function() {
this.app = etagApp();
- this.driver = newDriver();
+ this.driver = await newDriver();
startApp(this.app);
});
afterEach(function() {
@@ -18,21 +18,20 @@ describe('etag tests', function() {
});
it('blocks etags', async function() {
let {app, driver} = this;
- await driver.get('about:blank');
- await driver.get(firstPartyHost);
- await driver.get(firstPartyHost);
- let req1 = await app.firstParty.requests.next();
+ await driver.get(firstPartyHost); // etag gets set
+ await driver.get(firstPartyHost); // browser sends if-none-match to check if etag still valid
+ let req = await app.firstParty.requests.next();
//let req3 = await app.thirdParty.requests.next();
- assert.isTrue(req1.headers.hasOwnProperty('if-none-match'), 'allows 1st party etags on first visit');
+ assert.isTrue(req.headers.hasOwnProperty('if-none-match'), 'allows 1st party etags on first visit');
// known failure on chrome due to lack of access to caching headers in chrome webrquest api
//assert.isFalse(req3.headers.hasOwnProperty('if-none-match'), 'blocks 3rd party etags headers on first visit');
});
});
describe('cookie tests', function() {
- beforeEach(function() {
+ beforeEach(async function() {
this.app = cookieApp();
- this.driver = newDriver();
+ this.driver = await newDriver();
startApp(this.app);
});
afterEach(function() {
@@ -42,6 +41,7 @@ describe('cookie tests', function() {
it('blocks cookies', async function() {
let {app, driver} = this;
+
await driver.get(firstPartyHost);
let request = await app.firstParty.requests.next();
// no cookies initially
diff --git a/selenium/utils.js b/selenium/utils.js
index af9a946..9dc154e 100644
--- a/selenium/utils.js
+++ b/selenium/utils.js
@@ -2,6 +2,7 @@
const sw = require('selenium-webdriver'),
{createServer} = require('http'),
+ path = require('path'),
vhost = require('vhost'),
express = require('express');
@@ -10,7 +11,7 @@ function startApp(app, port=PORT) {
app.server.listen(port);
}
-const path = '../src/.',
+const srcDir = '../src/.',
PORT = 8000,
host = (hostname, port) => `${hostname}:${port}`,
firstPartyHostname = 'firstparty.local',
@@ -33,7 +34,7 @@ function stopApp(app) {
* 127.0.0.1 thirdparty.local
*/
-function loadDriverWithExtension(extPath) {
+async function loadDriverWithExtension(extPath) {
let chromeOptions = sw.Capabilities.chrome();
chromeOptions.set("chromeOptions", {"args": [
`--load-extension=${extPath}`,
@@ -45,11 +46,13 @@ function loadDriverWithExtension(extPath) {
.build();
}
-function newDriver() {
- return loadDriverWithExtension(path);
+async function newDriver() {
+ const srcPath = path.resolve(__dirname, srcDir);
+ return await loadDriverWithExtension(srcPath);
}
class Channel {
+ // async stack datastructure
constructor() {
this.items = [];
this.waiting = [];
@@ -63,12 +66,16 @@ class Channel {
});
}
}
+
+ // Get the item from the top of the stack, or wait for an item if there are none.
async next() {
return await this.popQueue();
}
+
+ // Push an item onto the stack.
push(item) {
if (this.waiting.length > 0) {
- this.waiting.shift()(item);
+ this.waiting.pop()(item);
} else {
this.items.push(item);
}
@@ -87,7 +94,7 @@ function requestRecorderMiddleware(app = express()) {
}
function firstPartyApp(app = express(), tpHost = thirdPartyHost) {
- app.get('/', (req, res) => {
+ app.get('*', (req, res) => {
return res.send(
``
);
@@ -96,7 +103,7 @@ function firstPartyApp(app = express(), tpHost = thirdPartyHost) {
}
function thirdPartyApp(app = express()) {
- app.get('/tracker.js', (req, res) => {
+ app.get('*', (req, res) => {
return res.send('console.log("third party script")');
});
return app;
@@ -106,8 +113,8 @@ function thirdPartyApp(app = express()) {
function baseTestApp(fpApp, tpApp, app = express(), fpHostname = firstPartyHostname, tpHostname = thirdPartyHostname) {
let firstParty = firstPartyApp(fpApp),
thirdParty = thirdPartyApp(tpApp);
- app.use(vhost(fpHostname, firstParty));
- app.use(vhost(tpHostname, thirdParty));
+ app.all('/', vhost(fpHostname, firstParty));
+ app.all('/tracker.js', vhost(tpHostname, thirdParty));
Object.assign(app, {firstParty, thirdParty});
return app;
}
diff --git a/src/js/webrequest.js b/src/js/webrequest.js
index 3fd7931..87323f0 100644
--- a/src/js/webrequest.js
+++ b/src/js/webrequest.js
@@ -28,19 +28,19 @@ class WebRequest {
onBeforeRequest.addListener(
this.onBeforeRequest.bind(this),
{urls: [""]},
- ["blocking"]
+ ["blocking"],
);
onBeforeSendHeaders.addListener(
this.onBeforeSendHeaders.bind(this),
{urls: [""]},
- ["blocking", "requestHeaders"]
+ ["blocking", "requestHeaders", "extraHeaders"],
);
onHeadersReceived.addListener(
this.onHeadersReceived.bind(this),
{urls: [""]},
- ["blocking", "responseHeaders"]
+ ["blocking", "responseHeaders", "extraHeaders"],
);
}