Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update webrequest infospeck fixes chrome changes #180

Merged
merged 3 commits into from
Jul 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions selenium/cookies.js
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down
18 changes: 9 additions & 9 deletions selenium/integration_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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
Expand Down
25 changes: 16 additions & 9 deletions selenium/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const sw = require('selenium-webdriver'),
{createServer} = require('http'),
path = require('path'),
vhost = require('vhost'),
express = require('express');

Expand All @@ -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',
Expand All @@ -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}`,
Expand All @@ -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 = [];
Expand All @@ -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);
}
Expand All @@ -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(
`<script type="text/javascript" src="http://${tpHost}/tracker.js"></script>`
);
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/js/webrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ class WebRequest {
onBeforeRequest.addListener(
this.onBeforeRequest.bind(this),
{urls: ["<all_urls>"]},
["blocking"]
["blocking"],
);

onBeforeSendHeaders.addListener(
this.onBeforeSendHeaders.bind(this),
{urls: ["<all_urls>"]},
["blocking", "requestHeaders"]
["blocking", "requestHeaders", "extraHeaders"],
);

onHeadersReceived.addListener(
this.onHeadersReceived.bind(this),
{urls: ["<all_urls>"]},
["blocking", "responseHeaders"]
["blocking", "responseHeaders", "extraHeaders"],
);
}

Expand Down