From d4165c9e9ce19c0e5cc703b3bbe9c99f3d9f0872 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Wed, 5 Jul 2017 14:20:09 -0700 Subject: [PATCH 1/4] Add cookieException for google drive fixes #9810 Auditors: @diracdeltas, @bsclifton, @bbondy Test Plan: 1. Go to google drive 2. Make sure block 3rd party cookies 3. You should be able to download file --- app/filtering.js | 12 ++++++++---- js/data/siteHacks.js | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/filtering.js b/app/filtering.js index 5d9c6f20ca8..76f8ceaca23 100644 --- a/app/filtering.js +++ b/app/filtering.js @@ -33,6 +33,7 @@ const {updateElectronDownloadItem} = require('./browser/electronDownloadItem') const {fullscreenOption} = require('./common/constants/settingsEnums') const isThirdPartyHost = require('./browser/isThirdPartyHost') var extensionState = require('./common/state/extensionState.js') +const {cookieExceptions, refererExceptions} = require('../js/data/siteHacks') let appStore = null @@ -46,9 +47,6 @@ let initializedPartitions = {} const transparent1pxGif = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' const pdfjsOrigin = `chrome-extension://${config.PDFJSExtensionId}` -// Third party domains that require a valid referer to work -const refererExceptions = ['use.typekit.net', 'cloud.typography.com', 'www.moremorewin.net'] - /** * Maps partition name to the session object */ @@ -273,9 +271,15 @@ function registerForBeforeSendHeaders (session, partition) { if (cookieSetting === 'blockAllCookies' || isThirdPartyHost(parsedFirstPartyUrl.hostname, parsedTargetUrl.hostname)) { + let hasCookieException = false + cookieExceptions.forEach((exceptionPair) => { + if (getOrigin(firstPartyUrl) === exceptionPair[0] && getOrigin(details.url) === exceptionPair[1] && cookieSetting !== 'blockAllCookies') { + hasCookieException = true + } + }) // Clear cookie and referer on third-party requests if (requestHeaders['Cookie'] && - getOrigin(firstPartyUrl) !== pdfjsOrigin) { + getOrigin(firstPartyUrl) !== pdfjsOrigin && !hasCookieException) { requestHeaders['Cookie'] = undefined } if (cookieSetting !== 'blockAllCookies' && diff --git a/js/data/siteHacks.js b/js/data/siteHacks.js index 42e9617393b..a77ddfbe0a1 100644 --- a/js/data/siteHacks.js +++ b/js/data/siteHacks.js @@ -27,9 +27,13 @@ const emptyDataURI = { */ module.exports.cookieExceptions = [ ['https://inbox.google.com', 'https://hangouts.google.com'], - ['https://mail.google.com', 'https://hangouts.google.com'] + ['https://mail.google.com', 'https://hangouts.google.com'], + ['https://drive.google.com', 'https://doc-0g-3g-docs.googleusercontent.com'] ] +// Third party domains that require a valid referer to work +module.exports.refererExceptions = ['use.typekit.net', 'cloud.typography.com', 'www.moremorewin.net'] + /** * Holds an array of [Primary URL, subresource URL] to allow 3rd party localstorage. * Subresource URL can be '*' or undefined to indicate all. From 695f0f876b962120c58a367fb2ce0d5969a9476a Mon Sep 17 00:00:00 2001 From: Brian Clifton Date: Thu, 6 Jul 2017 23:05:37 -0700 Subject: [PATCH 2/4] Broke the cookie/referer check out to a function + wrote unit tests :) Auditors: @darkdh, @diracdeltas Test Plan: `npm run unittest -- --grep="filtering unit tests"` --- app/filtering.js | 57 +++++++++++-------- test/unit/app/filteringTest.js | 101 +++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 24 deletions(-) create mode 100644 test/unit/app/filteringTest.js diff --git a/app/filtering.js b/app/filtering.js index 76f8ceaca23..46dc00a209d 100644 --- a/app/filtering.js +++ b/app/filtering.js @@ -218,6 +218,38 @@ function registerForBeforeRedirect (session, partition) { }) } +module.exports.considerRequestExceptions = (requestHeaders, url, firstPartyUrl, isPrivate) => { + const cookieSetting = module.exports.isResourceEnabled(appConfig.resourceNames.COOKIEBLOCK, firstPartyUrl, isPrivate) + if (cookieSetting) { + const parsedTargetUrl = urlParse(url || '') + const parsedFirstPartyUrl = urlParse(firstPartyUrl) + + if (cookieSetting === 'blockAllCookies' || + isThirdPartyHost(parsedFirstPartyUrl.hostname, parsedTargetUrl.hostname)) { + let hasCookieException = false + cookieExceptions.forEach((exceptionPair) => { + if (getOrigin(firstPartyUrl) === exceptionPair[0] && + getOrigin(url) === exceptionPair[1] && + cookieSetting !== 'blockAllCookies') { + hasCookieException = true + } + }) + // Clear cookie and referer on third-party requests + if (requestHeaders['Cookie'] && + getOrigin(firstPartyUrl) !== pdfjsOrigin && !hasCookieException) { + requestHeaders['Cookie'] = undefined + } + if (cookieSetting !== 'blockAllCookies' && + requestHeaders['Referer'] && + !refererExceptions.includes(parsedTargetUrl.hostname)) { + requestHeaders['Referer'] = getOrigin(url) + } + } + } + + return requestHeaders +} + /** * Register for notifications for webRequest.onBeforeSendHeaders for * a particular session. @@ -264,31 +296,8 @@ function registerForBeforeSendHeaders (session, partition) { } } - const cookieSetting = module.exports.isResourceEnabled(appConfig.resourceNames.COOKIEBLOCK, firstPartyUrl, isPrivate) - if (cookieSetting) { - const parsedTargetUrl = urlParse(details.url || '') - const parsedFirstPartyUrl = urlParse(firstPartyUrl) + requestHeaders = module.exports.considerRequestExceptions(requestHeaders, details.url, firstPartyUrl, isPrivate) - if (cookieSetting === 'blockAllCookies' || - isThirdPartyHost(parsedFirstPartyUrl.hostname, parsedTargetUrl.hostname)) { - let hasCookieException = false - cookieExceptions.forEach((exceptionPair) => { - if (getOrigin(firstPartyUrl) === exceptionPair[0] && getOrigin(details.url) === exceptionPair[1] && cookieSetting !== 'blockAllCookies') { - hasCookieException = true - } - }) - // Clear cookie and referer on third-party requests - if (requestHeaders['Cookie'] && - getOrigin(firstPartyUrl) !== pdfjsOrigin && !hasCookieException) { - requestHeaders['Cookie'] = undefined - } - if (cookieSetting !== 'blockAllCookies' && - requestHeaders['Referer'] && - !refererExceptions.includes(parsedTargetUrl.hostname)) { - requestHeaders['Referer'] = getOrigin(details.url) - } - } - } if (sendDNT) { requestHeaders['DNT'] = '1' } diff --git a/test/unit/app/filteringTest.js b/test/unit/app/filteringTest.js new file mode 100644 index 00000000000..80a02d5125f --- /dev/null +++ b/test/unit/app/filteringTest.js @@ -0,0 +1,101 @@ +/* global describe, before, after, it */ +const mockery = require('mockery') +const assert = require('assert') +const sinon = require('sinon') +const {cookieExceptions, refererExceptions} = require('../../../js/data/siteHacks') + +require('../braveUnit') + +describe('filtering unit tests', function () { + let filtering + const fakeElectron = require('../lib/fakeElectron') + + before(function () { + mockery.enable({ + warnOnReplace: false, + warnOnUnregistered: false, + useCleanCache: true + }) + mockery.registerMock('electron', fakeElectron) + mockery.registerMock('./adBlock', {adBlockResourceName: 'adblock'}) + filtering = require('../../../app/filtering') + }) + + after(function () { + mockery.disable() + }) + + describe('considerRequestExceptions', function () { + describe('when cookieSetting === "blockAllCookies"', function () { + let isResourceEnabledStub + before(function () { + isResourceEnabledStub = sinon.stub(filtering, 'isResourceEnabled').returns('blockAllCookies') + }) + after(function () { + isResourceEnabledStub.restore() + }) + + it('clears cookie field', function () { + const url = 'https://cdnp3.stackassets.com/574db2390a12942fcef927356dadc6f9955edea9/store/fe3eb8fc014a20f2d25810b3c4f4b5b0db8695adfd7e8953721a55c51b90/sale_7217_primary_image.jpg' + const firstPartyUrl = 'https://slashdot.org/' + const requestHeaders = { + Cookie: 'optimizelyEndUserId=oeu1491721215718r0.024789086462633003; __ssid=97b17d31-8f1b-4193-8914-df36e7b740f6; optimizelySegments=%7B%22300150879%22%3A%22false%22%2C%22300333436%22%3A%22gc%22%2C%22300387578%22%3A%22campaign%22%7D; optimizelyBuckets=%7B%7D; _pk_id.40.2105=8fca10ea565f58bf.1485982886.187.1499406000.1499405260.; _pk_ses.40.2105=*' + } + const result = filtering.considerRequestExceptions(requestHeaders, url, firstPartyUrl, false) + + assert.equal(result.Cookie, undefined) + }) + + describe('when there is a cookie exception', function () { + it('keeps the cookie field', function () { + const cookieException = cookieExceptions && cookieExceptions[0] + + assert(cookieException) + + const url = cookieException[0] + const firstPartyUrl = cookieException[1] + const requestHeaders = { + Cookie: 'optimizelyEndUserId=oeu1491721215718r0.024789086462633003; __ssid=97b17d31-8f1b-4193-8914-df36e7b740f6; optimizelySegments=%7B%22300150879%22%3A%22false%22%2C%22300333436%22%3A%22gc%22%2C%22300387578%22%3A%22campaign%22%7D; optimizelyBuckets=%7B%7D; _pk_id.40.2105=8fca10ea565f58bf.1485982886.187.1499406000.1499405260.; _pk_ses.40.2105=*' + } + const result = filtering.considerRequestExceptions(requestHeaders, url, firstPartyUrl, false) + + assert.equal(result.Cookie, requestHeaders.Cookie) + }) + }) + }) + + describe('when cookieSetting === "block3rdPartyCookie"', function () { + let isResourceEnabledStub + before(function () { + isResourceEnabledStub = sinon.stub(filtering, 'isResourceEnabled').returns('block3rdPartyCookie') + }) + after(function () { + isResourceEnabledStub.restore() + }) + + it('sets the referer to the origin', function () { + const url = 'https://cdnp3.stackassets.com/574db2390a12942fcef927356dadc6f9955edea9/store/fe3eb8fc014a20f2d25810b3c4f4b5b0db8695adfd7e8953721a55c51b90/sale_7217_primary_image.jpg' + const firstPartyUrl = 'https://slashdot.org/' + const requestHeaders = { + Referer: 'https://brave.com' + } + const result = filtering.considerRequestExceptions(requestHeaders, url, firstPartyUrl, false) + + assert.equal(result.Referer, 'https://cdnp3.stackassets.com') + }) + + describe('when there is a referer exception', function () { + it('keeps the referer field', function () { + const url = 'https://' + refererExceptions[0] + const firstPartyUrl = 'https://slashdot.org/' + const requestHeaders = { + Referer: 'https://brave.com' + } + const result = filtering.considerRequestExceptions(requestHeaders, url, firstPartyUrl, false) + + assert.equal(result.Referer, requestHeaders.Referer) + }) + }) + }) + }) +}) From 8b624dfb59d11c8536c5637a9b82c4e17bf0d1a7 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Fri, 7 Jul 2017 13:27:27 -0700 Subject: [PATCH 3/4] Change cookieExceptions to map Auditors: @diracdeltas, @bsclifton --- app/filtering.js | 18 +++++++++--------- js/data/siteHacks.js | 12 ++++++------ js/state/contentSettings.js | 6 +++--- test/unit/app/filteringTest.js | 12 +++++++++--- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/app/filtering.js b/app/filtering.js index 46dc00a209d..5054fa80258 100644 --- a/app/filtering.js +++ b/app/filtering.js @@ -227,22 +227,22 @@ module.exports.considerRequestExceptions = (requestHeaders, url, firstPartyUrl, if (cookieSetting === 'blockAllCookies' || isThirdPartyHost(parsedFirstPartyUrl.hostname, parsedTargetUrl.hostname)) { let hasCookieException = false - cookieExceptions.forEach((exceptionPair) => { - if (getOrigin(firstPartyUrl) === exceptionPair[0] && - getOrigin(url) === exceptionPair[1] && - cookieSetting !== 'blockAllCookies') { - hasCookieException = true - } - }) + const firstPartyOrigin = getOrigin(firstPartyUrl) + const targetOrigin = getOrigin(url) + if (cookieExceptions.hasOwnProperty(firstPartyOrigin) && + cookieExceptions[firstPartyOrigin] === targetOrigin && + cookieSetting !== 'blockAllCookies') { + hasCookieException = true + } // Clear cookie and referer on third-party requests if (requestHeaders['Cookie'] && - getOrigin(firstPartyUrl) !== pdfjsOrigin && !hasCookieException) { + firstPartyOrigin !== pdfjsOrigin && !hasCookieException) { requestHeaders['Cookie'] = undefined } if (cookieSetting !== 'blockAllCookies' && requestHeaders['Referer'] && !refererExceptions.includes(parsedTargetUrl.hostname)) { - requestHeaders['Referer'] = getOrigin(url) + requestHeaders['Referer'] = targetOrigin } } } diff --git a/js/data/siteHacks.js b/js/data/siteHacks.js index a77ddfbe0a1..b37dfe2a5f8 100644 --- a/js/data/siteHacks.js +++ b/js/data/siteHacks.js @@ -22,14 +22,14 @@ const emptyDataURI = { } /** - * Holds an array of [Primary URL, subresource URL] to allow 3rd party cookies. + * Holds an map of {Primary URL: subresource URL} to allow 3rd party cookies. * Subresource URL can be '*' or undefined to indicate all. */ -module.exports.cookieExceptions = [ - ['https://inbox.google.com', 'https://hangouts.google.com'], - ['https://mail.google.com', 'https://hangouts.google.com'], - ['https://drive.google.com', 'https://doc-0g-3g-docs.googleusercontent.com'] -] +module.exports.cookieExceptions = { + 'https://inbox.google.com': 'https://hangouts.google.com', + 'https://mail.google.com': 'https://hangouts.google.com', + 'https://drive.google.com': 'https://doc-0g-3g-docs.googleusercontent.com' +} // Third party domains that require a valid referer to work module.exports.refererExceptions = ['use.typekit.net', 'cloud.typography.com', 'www.moremorewin.net'] diff --git a/js/state/contentSettings.js b/js/state/contentSettings.js index 21c54f36029..0e60a90628b 100644 --- a/js/state/contentSettings.js +++ b/js/state/contentSettings.js @@ -263,9 +263,9 @@ const siteSettingsToContentSettings = (currentSiteSettings, defaultContentSettin contentSettings = addContentSettings(contentSettings, 'cookies', primaryPattern, '*', 'block') contentSettings = addContentSettings(contentSettings, 'cookies', primaryPattern, primaryPattern, 'allow') contentSettings = addContentSettings(contentSettings, 'referer', primaryPattern, '*', 'block') - cookieExceptions.forEach((exceptionPair) => { - contentSettings = addContentSettings(contentSettings, 'cookies', exceptionPair[0], exceptionPair[1], 'allow') - }) + for (let key in cookieExceptions) { + contentSettings = addContentSettings(contentSettings, 'cookies', key, cookieExceptions[key], 'allow') + } } else if (siteSetting.get('cookieControl') === 'blockAllCookies') { contentSettings = addContentSettings(contentSettings, 'cookies', primaryPattern, '*', 'block') contentSettings = addContentSettings(contentSettings, 'referer', primaryPattern, '*', 'block') diff --git a/test/unit/app/filteringTest.js b/test/unit/app/filteringTest.js index 80a02d5125f..d3a61b80644 100644 --- a/test/unit/app/filteringTest.js +++ b/test/unit/app/filteringTest.js @@ -48,12 +48,18 @@ describe('filtering unit tests', function () { describe('when there is a cookie exception', function () { it('keeps the cookie field', function () { - const cookieException = cookieExceptions && cookieExceptions[0] + let cookieException = false + let firstPartyUrl = '' + let url = '' + for (let key in cookieExceptions) { + firstPartyUrl = key + url = cookieException[key] + cookieException = true + break + } assert(cookieException) - const url = cookieException[0] - const firstPartyUrl = cookieException[1] const requestHeaders = { Cookie: 'optimizelyEndUserId=oeu1491721215718r0.024789086462633003; __ssid=97b17d31-8f1b-4193-8914-df36e7b740f6; optimizelySegments=%7B%22300150879%22%3A%22false%22%2C%22300333436%22%3A%22gc%22%2C%22300387578%22%3A%22campaign%22%7D; optimizelyBuckets=%7B%7D; _pk_id.40.2105=8fca10ea565f58bf.1485982886.187.1499406000.1499405260.; _pk_ses.40.2105=*' } From b794367571708b710b6a5bc3b8cd9126ba958d35 Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Sun, 9 Jul 2017 23:09:41 -0700 Subject: [PATCH 4/4] Using wildcard pattern --- app/filtering.js | 25 +++++++++++++++++-------- js/data/siteHacks.js | 6 +++--- js/state/contentSettings.js | 5 ++++- test/unit/app/filteringTest.js | 25 +++++++++++++++++++------ 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/app/filtering.js b/app/filtering.js index 5054fa80258..08c4067bafb 100644 --- a/app/filtering.js +++ b/app/filtering.js @@ -218,7 +218,7 @@ function registerForBeforeRedirect (session, partition) { }) } -module.exports.considerRequestExceptions = (requestHeaders, url, firstPartyUrl, isPrivate) => { +module.exports.applyCookieSetting = (requestHeaders, url, firstPartyUrl, isPrivate) => { const cookieSetting = module.exports.isResourceEnabled(appConfig.resourceNames.COOKIEBLOCK, firstPartyUrl, isPrivate) if (cookieSetting) { const parsedTargetUrl = urlParse(url || '') @@ -229,18 +229,27 @@ module.exports.considerRequestExceptions = (requestHeaders, url, firstPartyUrl, let hasCookieException = false const firstPartyOrigin = getOrigin(firstPartyUrl) const targetOrigin = getOrigin(url) - if (cookieExceptions.hasOwnProperty(firstPartyOrigin) && - cookieExceptions[firstPartyOrigin] === targetOrigin && - cookieSetting !== 'blockAllCookies') { - hasCookieException = true + if (cookieExceptions.hasOwnProperty(firstPartyOrigin)) { + const subResources = cookieExceptions[firstPartyOrigin] + for (let i = 0; i < subResources.length; ++i) { + if (subResources[i] === targetOrigin) { + hasCookieException = true + break + } else if (subResources[i].includes('*')) { + const regSubResource = new RegExp(subResources[i].replace('//', '\\/\\/').replace('*', '.*'), 'g') + if (targetOrigin.match(regSubResource)) { + hasCookieException = true + break + } + } + } } // Clear cookie and referer on third-party requests if (requestHeaders['Cookie'] && firstPartyOrigin !== pdfjsOrigin && !hasCookieException) { requestHeaders['Cookie'] = undefined } - if (cookieSetting !== 'blockAllCookies' && - requestHeaders['Referer'] && + if (requestHeaders['Referer'] && !refererExceptions.includes(parsedTargetUrl.hostname)) { requestHeaders['Referer'] = targetOrigin } @@ -296,7 +305,7 @@ function registerForBeforeSendHeaders (session, partition) { } } - requestHeaders = module.exports.considerRequestExceptions(requestHeaders, details.url, firstPartyUrl, isPrivate) + requestHeaders = module.exports.applyCookieSetting(requestHeaders, details.url, firstPartyUrl, isPrivate) if (sendDNT) { requestHeaders['DNT'] = '1' diff --git a/js/data/siteHacks.js b/js/data/siteHacks.js index b37dfe2a5f8..6a464e18eeb 100644 --- a/js/data/siteHacks.js +++ b/js/data/siteHacks.js @@ -26,9 +26,9 @@ const emptyDataURI = { * Subresource URL can be '*' or undefined to indicate all. */ module.exports.cookieExceptions = { - 'https://inbox.google.com': 'https://hangouts.google.com', - 'https://mail.google.com': 'https://hangouts.google.com', - 'https://drive.google.com': 'https://doc-0g-3g-docs.googleusercontent.com' + 'https://inbox.google.com': ['https://hangouts.google.com'], + 'https://mail.google.com': ['https://hangouts.google.com'], + 'https://drive.google.com': ['https://doc-*-docs.googleusercontent.com'] } // Third party domains that require a valid referer to work diff --git a/js/state/contentSettings.js b/js/state/contentSettings.js index 0e60a90628b..0c94ff98f53 100644 --- a/js/state/contentSettings.js +++ b/js/state/contentSettings.js @@ -264,7 +264,10 @@ const siteSettingsToContentSettings = (currentSiteSettings, defaultContentSettin contentSettings = addContentSettings(contentSettings, 'cookies', primaryPattern, primaryPattern, 'allow') contentSettings = addContentSettings(contentSettings, 'referer', primaryPattern, '*', 'block') for (let key in cookieExceptions) { - contentSettings = addContentSettings(contentSettings, 'cookies', key, cookieExceptions[key], 'allow') + const subResources = cookieExceptions[key] + for (let i = 0; i < subResources.length; ++i) { + contentSettings = addContentSettings(contentSettings, 'cookies', key, subResources[i], 'allow') + } } } else if (siteSetting.get('cookieControl') === 'blockAllCookies') { contentSettings = addContentSettings(contentSettings, 'cookies', primaryPattern, '*', 'block') diff --git a/test/unit/app/filteringTest.js b/test/unit/app/filteringTest.js index d3a61b80644..961ff19a174 100644 --- a/test/unit/app/filteringTest.js +++ b/test/unit/app/filteringTest.js @@ -25,7 +25,7 @@ describe('filtering unit tests', function () { mockery.disable() }) - describe('considerRequestExceptions', function () { + describe('applyCookieSetting', function () { describe('when cookieSetting === "blockAllCookies"', function () { let isResourceEnabledStub before(function () { @@ -41,7 +41,7 @@ describe('filtering unit tests', function () { const requestHeaders = { Cookie: 'optimizelyEndUserId=oeu1491721215718r0.024789086462633003; __ssid=97b17d31-8f1b-4193-8914-df36e7b740f6; optimizelySegments=%7B%22300150879%22%3A%22false%22%2C%22300333436%22%3A%22gc%22%2C%22300387578%22%3A%22campaign%22%7D; optimizelyBuckets=%7B%7D; _pk_id.40.2105=8fca10ea565f58bf.1485982886.187.1499406000.1499405260.; _pk_ses.40.2105=*' } - const result = filtering.considerRequestExceptions(requestHeaders, url, firstPartyUrl, false) + const result = filtering.applyCookieSetting(requestHeaders, url, firstPartyUrl, false) assert.equal(result.Cookie, undefined) }) @@ -53,7 +53,8 @@ describe('filtering unit tests', function () { let url = '' for (let key in cookieExceptions) { firstPartyUrl = key - url = cookieException[key] + const urls = cookieExceptions[key] + url = urls[0] cookieException = true break } @@ -63,7 +64,19 @@ describe('filtering unit tests', function () { const requestHeaders = { Cookie: 'optimizelyEndUserId=oeu1491721215718r0.024789086462633003; __ssid=97b17d31-8f1b-4193-8914-df36e7b740f6; optimizelySegments=%7B%22300150879%22%3A%22false%22%2C%22300333436%22%3A%22gc%22%2C%22300387578%22%3A%22campaign%22%7D; optimizelyBuckets=%7B%7D; _pk_id.40.2105=8fca10ea565f58bf.1485982886.187.1499406000.1499405260.; _pk_ses.40.2105=*' } - const result = filtering.considerRequestExceptions(requestHeaders, url, firstPartyUrl, false) + const result = filtering.applyCookieSetting(requestHeaders, url, firstPartyUrl, false) + + assert.equal(result.Cookie, requestHeaders.Cookie) + }) + it('wildcard cookie exception', function () { + // Specifically testing drive.google.com + const firstPartyUrl = 'https://drive.google.com' + const url = 'https://doc-0g-3g-docs.googleusercontent.com' + + const requestHeaders = { + Cookie: 'optimizelyEndUserId=oeu1491721215718r0.024789086462633003; __ssid=97b17d31-8f1b-4193-8914-df36e7b740f6; optimizelySegments=%7B%22300150879%22%3A%22false%22%2C%22300333436%22%3A%22gc%22%2C%22300387578%22%3A%22campaign%22%7D; optimizelyBuckets=%7B%7D; _pk_id.40.2105=8fca10ea565f58bf.1485982886.187.1499406000.1499405260.; _pk_ses.40.2105=*' + } + const result = filtering.applyCookieSetting(requestHeaders, url, firstPartyUrl, false) assert.equal(result.Cookie, requestHeaders.Cookie) }) @@ -85,7 +98,7 @@ describe('filtering unit tests', function () { const requestHeaders = { Referer: 'https://brave.com' } - const result = filtering.considerRequestExceptions(requestHeaders, url, firstPartyUrl, false) + const result = filtering.applyCookieSetting(requestHeaders, url, firstPartyUrl, false) assert.equal(result.Referer, 'https://cdnp3.stackassets.com') }) @@ -97,7 +110,7 @@ describe('filtering unit tests', function () { const requestHeaders = { Referer: 'https://brave.com' } - const result = filtering.considerRequestExceptions(requestHeaders, url, firstPartyUrl, false) + const result = filtering.applyCookieSetting(requestHeaders, url, firstPartyUrl, false) assert.equal(result.Referer, requestHeaders.Referer) })