From 7a64e960cf3527a2ce7200aad74bdaeceee9e688 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Tue, 9 Jul 2019 14:50:29 -0700 Subject: [PATCH 1/4] Add browser_compat_test.js --- src/js/test/browser_compat_test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/js/test/browser_compat_test.js diff --git a/src/js/test/browser_compat_test.js b/src/js/test/browser_compat_test.js new file mode 100644 index 0000000..04c907d --- /dev/null +++ b/src/js/test/browser_compat_test.js @@ -0,0 +1,12 @@ +"use strict"; + +const {assert} = require('chai'), + {getOnBeforeRequestOptions, getOnBeforeSendHeadersOptions, getOnHeadersReceivedOptions} = require('../browser_compat'); + +describe('browser_compat.js', function() { + it("gets options", function () { + assert.deepEqual(getOnBeforeRequestOptions(), ['blocking']) + assert.deepEqual(getOnBeforeSendHeadersOptions(), ['blocking', 'requestHeaders']) + assert.deepEqual(getOnHeadersReceivedOptions(), ['blocking', 'responseHeaders']) + }); +}); From 39ffdd6ba06cc7dc275f01c2c23ef2db6d5cd66a Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Tue, 9 Jul 2019 15:58:12 -0700 Subject: [PATCH 2/4] Add referer test app --- selenium/referer.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 selenium/referer.js diff --git a/selenium/referer.js b/selenium/referer.js new file mode 100644 index 0000000..3aec879 --- /dev/null +++ b/selenium/referer.js @@ -0,0 +1,24 @@ +'use strict'; + +const express = require('express'), + {requestRecorderMiddleware, baseTestApp} = require('./utils'); + +function requireRefererApp(app = express()) { + app.use((req, res, next) => { + if (!req.headers['referer']) { + res.statusCode = 401; + return res.send(); + } + next(); + }); + requestRecorderMiddleware(app); + return app; +} + +function refererApp() { + let fpApp = express(), + tpApp = requireRefererApp(); + return baseTestApp(fpApp, tpApp); +} + +Object.assign(module.exports, {refererApp}); From d7d5cbb9fa657e9d6d41078571163d3086d10c7f Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Tue, 9 Jul 2019 15:59:41 -0700 Subject: [PATCH 3/4] Add integration tests for refere stuff --- selenium/integration_tests.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/selenium/integration_tests.js b/selenium/integration_tests.js index 3a8bb86..3c423d9 100644 --- a/selenium/integration_tests.js +++ b/selenium/integration_tests.js @@ -2,8 +2,10 @@ const {assert} = require('chai'); -const {newDriver, startApp, stopApp, firstPartyHost} = require('./utils'), +const {newDriver, startApp, stopApp, firstPartyHost, thirdPartyText} = require('./utils'), + {By} = require('selenium-webdriver'), {cookieApp, fpcookie} = require("./cookies"), + {refererApp} = require('./referer'), {etagApp} = require('./etags'); describe('etag tests', function() { @@ -58,3 +60,21 @@ describe('cookie tests', function() { assert.deepEqual(request.cookies, {}); }); }); + +describe('referer tests', function() { + beforeEach(async function() { + this.app = refererApp(); + this.driver = await newDriver(); + startApp(this.app); + }); + afterEach(function() { + stopApp(this.app); + this.driver.quit(); + }); + it('sends header when required', async function() { + let {app, driver} = this; + await driver.get(firstPartyHost); + let el = await driver.findElement(By.xpath('/html/body/div')); + assert.deepEqual(await el.getText(), thirdPartyText); + }); +}); From 177ebf7b6dd9f3367eca2a1833bf34bdbbd83a53 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Tue, 9 Jul 2019 16:00:45 -0700 Subject: [PATCH 4/4] Make third party app install div --- selenium/utils.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/selenium/utils.js b/selenium/utils.js index 9dc154e..fa53170 100644 --- a/selenium/utils.js +++ b/selenium/utils.js @@ -16,6 +16,7 @@ const srcDir = '../src/.', host = (hostname, port) => `${hostname}:${port}`, firstPartyHostname = 'firstparty.local', thirdPartyHostname = 'thirdparty.local', + thirdPartyText = 'Third party loaded.', firstPartyHost = host(firstPartyHostname, PORT), thirdPartyHost = host(thirdPartyHostname, PORT); @@ -46,6 +47,7 @@ async function loadDriverWithExtension(extPath) { .build(); } + async function newDriver() { const srcPath = path.resolve(__dirname, srcDir); return await loadDriverWithExtension(srcPath); @@ -95,16 +97,27 @@ function requestRecorderMiddleware(app = express()) { function firstPartyApp(app = express(), tpHost = thirdPartyHost) { app.get('*', (req, res) => { - return res.send( - `` - ); + return res.send(` + + + + + +`); }); return app; } function thirdPartyApp(app = express()) { app.get('*', (req, res) => { - return res.send('console.log("third party script")'); + return res.send(` +window.onload = () => { + console.log("third party script"); + const div = document.createElement('div'); + div.innerText = '${thirdPartyText}'; + document.body.appendChild(div); +}; +`); }); return app; } @@ -119,4 +132,4 @@ function baseTestApp(fpApp, tpApp, app = express(), fpHostname = firstPartyHostn return app; } -Object.assign(module.exports, {newDriver, startApp, stopApp, PORT, firstPartyHostname, thirdPartyHostname, firstPartyHost, thirdPartyHost, Channel, requestRecorderMiddleware, firstPartyApp, thirdPartyApp, baseTestApp}); +Object.assign(module.exports, {newDriver, startApp, stopApp, PORT, firstPartyHostname, thirdPartyHostname, firstPartyHost, thirdPartyHost, thirdPartyText, Channel, requestRecorderMiddleware, firstPartyApp, thirdPartyApp, baseTestApp});