Skip to content

Commit

Permalink
Run cookie header tests in frames.
Browse files Browse the repository at this point in the history
  • Loading branch information
sammacbeth committed Nov 15, 2022
1 parent 7de1e1f commit 3d9f6d8
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 50 deletions.
48 changes: 47 additions & 1 deletion privacy-protections/storage-blocking/helpers/commonTests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,53 @@
/* exported commonTests */
/* global cookieStore */
/* global cookieStore, THIRD_PARTY_TRACKER_ORIGIN, THIRD_PARTY_ORIGIN */

// tests that are common for both main frame and an iframe
const commonTests = [
{
id: 'first party header cookie',
store: (data) => {
return fetch(`/set-cookie?value=${data}`).then(r => {
if (!r.ok) {
throw new Error('Request failed.');
}
});
},
retrive: () => {
return fetch('/reflect-headers')
.then(r => r.json())
.then(data => data.headers.cookie.match(/headerdata=([0-9]+)/)[1]);
}
},
{
id: 'safe third party header cookie',
store: (data) => {
return fetch(`${THIRD_PARTY_ORIGIN}/set-cookie?value=${data}`, { credentials: 'include' }).then(r => {
if (!r.ok) {
throw new Error('Request failed.');
}
});
},
retrive: () => {
return fetch(`${THIRD_PARTY_ORIGIN}/reflect-headers`, { credentials: 'include' })
.then(r => r.json())
.then(data => data.headers.cookie.match(/headerdata=([0-9]+)/)[1]);
}
},
{
id: 'tracking third party header cookie',
store: (data) => {
return fetch(`${THIRD_PARTY_TRACKER_ORIGIN}/set-cookie?value=${data}`, { credentials: 'include' }).then(r => {
if (!r.ok) {
throw new Error('Request failed.');
}
});
},
retrive: () => {
return fetch(`${THIRD_PARTY_TRACKER_ORIGIN}/reflect-headers`, { credentials: 'include' })
.then(r => r.json())
.then(data => data.headers.cookie.match(/headerdata=([0-9]+)/)[1]);
}
},
{
id: 'JS cookie',
store: (data) => {
Expand Down
3 changes: 3 additions & 0 deletions privacy-protections/storage-blocking/helpers/globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* exported THIRD_PARTY_ORIGIN,THIRD_PARTY_TRACKER_ORIGIN */
const THIRD_PARTY_ORIGIN = 'https://good.third-party.site';
const THIRD_PARTY_TRACKER_ORIGIN = 'https://broken.third-party.site';
1 change: 1 addition & 0 deletions privacy-protections/storage-blocking/iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Storage blocking test page - iframe</title>
<script src='/helpers/idb-wrapper.js'></script>
<script src="./helpers/globals.js"></script>
<script src='./helpers/commonTests.js'></script>
<script src='./iframe.js'></script>
</head>
Expand Down
1 change: 1 addition & 0 deletions privacy-protections/storage-blocking/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<title>Storage blocking test page</title>

<script src='/helpers/idb-wrapper.js' defer></script>
<script src="./helpers/globals.js"></script>
<script src='./helpers/commonTests.js'></script>
<script src='https://broken.third-party.site/privacy-protections/storage-blocking/3rdparty.js' defer></script>
<script src='https://good.third-party.site/privacy-protections/storage-blocking/3rdparty.js' defer></script>
Expand Down
51 changes: 2 additions & 49 deletions privacy-protections/storage-blocking/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* globals commonTests */
const THIRD_PARTY_ORIGIN = 'https://good.third-party.site';
const THIRD_PARTY_TRACKER_ORIGIN = 'https://broken.third-party.site';
/* globals commonTests,THIRD_PARTY_ORIGIN,THIRD_PARTY_TRACKER_ORIGIN */

const storeButton = document.querySelector('#store');
const retriveButton = document.querySelector('#retrive');
Expand Down Expand Up @@ -82,51 +80,6 @@ function create3pIframeTest (name, origin) {
}

const tests = [
{
id: 'first party header cookie',
store: (data) => {
return fetch(`/set-cookie?value=${data}`).then(r => {
if (!r.ok) {
throw new Error('Request failed.');
}
});
},
retrive: () => {
return fetch('/reflect-headers')
.then(r => r.json())
.then(data => data.headers.cookie.match(/headerdata=([0-9]+)/)[1]);
}
},
{
id: 'safe third party header cookie',
store: (data) => {
return fetch(`${THIRD_PARTY_ORIGIN}/set-cookie?value=${data}`, { credentials: 'include' }).then(r => {
if (!r.ok) {
throw new Error('Request failed.');
}
});
},
retrive: () => {
return fetch(`${THIRD_PARTY_ORIGIN}/reflect-headers`, { credentials: 'include' })
.then(r => r.json())
.then(data => data.headers.cookie.match(/headerdata=([0-9]+)/)[1]);
}
},
{
id: 'tracking third party header cookie',
store: (data) => {
return fetch(`${THIRD_PARTY_TRACKER_ORIGIN}/set-cookie?value=${data}`, { credentials: 'include' }).then(r => {
if (!r.ok) {
throw new Error('Request failed.');
}
});
},
retrive: () => {
return fetch(`${THIRD_PARTY_TRACKER_ORIGIN}/reflect-headers`, { credentials: 'include' })
.then(r => r.json())
.then(data => data.headers.cookie.match(/headerdata=([0-9]+)/)[1]);
}
},
create3pIframeTest('safe', THIRD_PARTY_ORIGIN),
create3pIframeTest('tracking', THIRD_PARTY_TRACKER_ORIGIN),
{
Expand Down Expand Up @@ -278,7 +231,7 @@ function retrieveData () {
});
}

tests.concat(commonTests).forEach(test => {
[...commonTests, ...tests].forEach(test => {
all++;

const li = document.createElement('li');
Expand Down

0 comments on commit 3d9f6d8

Please sign in to comment.