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

Surrogates test #32

Merged
merged 7 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ <h2>Privacy Protections Tests</h2>
<li><a href='https://privacy-test-pages.glitch.me/privacy-protections/referrer-trimming/'>Referrer trimming</a></li>
<li><a href='http://privacy-test-pages.glitch.me/privacy-protections/https-upgrades/'>HTTPS upgrades</a></li>
<li><a href='http://privacy-test-pages.glitch.me/privacy-protections/click-to-load/'>Facebook click to load</a></li>
<li><a href='http://privacy-test-pages.glitch.me/privacy-protections/surrogates/'>Surrogates</a></li>
</ul>

<h2>Other</h2>
Expand Down
3 changes: 2 additions & 1 deletion privacy-protections/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ <h1>Privacy Protections Tests</h1>
<li><a href='https://privacy-test-pages.glitch.me/privacy-protections/referrer-trimming/'>Referrer trimming</a></li>
<li><a href='http://privacy-test-pages.glitch.me/privacy-protections/https-upgrades/'>HTTPS upgrades</a></li>
<li><a href='http://privacy-test-pages.glitch.me/privacy-protections/click-to-load/'>Facebook click to load</a></li>
<li><a href='http://privacy-test-pages.glitch.me/privacy-protections/surrogates/'>Surrogates</a></li>
</ul>

</body>
</html>
</html>
36 changes: 36 additions & 0 deletions privacy-protections/surrogates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Tracker surrogates</title>
<style>
#results-table {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 70%;
}

#results-table td, #results-table th {
border: 1px solid #ddd;
padding: 8px;
}

#results-table th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #f2f2f2;
color: black;
}
</style>
</head>
<p><a href="../index.html">[Home]</a></p>

<p><b>Test blocking and redirecting to a surrogate</b></p>
<table id='results-table'>
<tr><th>Surrogate</th><th>Loaded</th><th>Passed Test</th><th>Notes</th></tr>
</table>
</body>
<script src='./main.js'></script>
</html>
84 changes: 84 additions & 0 deletions privacy-protections/surrogates/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const results = {};

function updateTable ({ name, testData, error }) {
const table = document.getElementById('results-table');
const row = table.insertRow(-1);
const testName = row.insertCell(0);
const loaded = row.insertCell(1);
const passed = row.insertCell(2);
const note = row.insertCell(3);

// set default values and colors
testName.innerText = name;
loaded.innerText = 'failed';
passed.innerText = 'failed';
row.style.backgroundColor = '#f97268';
note.style.backgroundColor = '#ffff';

results[name] = { pass: true };

if (!error || testData.shouldFail) {
loaded.innerText = 'pass';

const result = testData.test();
if (result) {
passed.innerText = 'pass';
row.style.backgroundColor = '#71bf69';
} else {
results[name].pass = false;
loaded.innerText = 'failed';
}
}

if (testData.notes) {
results[name].notes = testData.notes;
note.innerText = testData.notes;
}

if (testData.cleanup) {
testData.cleanup();
}
}

const surrogates = {
'google-analytics.com/analytics.js, crossOrigin': {
url: 'https://google-analytics.com/analytics.js',
crossOrigin: 'anonymous',
notes: 'Test loading with crossOrigin set on element (should fail on Firefox) https://bugzilla.mozilla.org/show_bug.cgi?id=1694679',
test: () => { return window.ga.answer === 42; },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we testing it this way and not the same way as _gaq?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I learned this would return true with the real ga code too. I updated it to look for an empty object from ga.create()

cleanUp: () => { delete window.ga; }
},
'google-analytics.com/analytics.js': {
url: 'https://google-analytics.com/analytics.js',
test: () => { return window.ga.answer === 42; },
cleanUp: () => { delete window.ga; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are not waiting for test to load/fail, so all tests are running at once - can there be a race condition when they overlap (e.g. two tests use window.ga)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed it 👀

},
'google-analytics, ga.js': {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all other tests involve testing different configurations of analytics.js surrogate why are we also testing ga.js surrogate? Is this some kind of a special case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not special, basically the same as analytics. I got rid of it.

url: 'https://google-analytics.com/ga.js',
test: () => { return !!window._gaq; },
cleanUp: () => { delete window._gaq; }
},
'Directly accessing a web resouce': {
url: 'chrome-extension://bkdgflcldnnnapblkhphbgpggdiikppg/web_accessible_resources/analytics.js',
kdzwinel marked this conversation as resolved.
Show resolved Hide resolved
notes: 'Chromium browsers Only: need access key for web resources',
shouldFail: true,
test: () => { return true; }
}
};

(function loadSurrogates () {
for (const [name, testData] of Object.entries(surrogates)) {
const s = document.createElement('script');

if (testData.crossOrigin) {
s.crossOrigin = testData.crossOrigin;
}

s.src = testData.url;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember that in some cases (local files? cache?) event could fire before listener is set up if you provide url first. Just to be extra sure - can you move this after listeners are ready?


s.onload = () => updateTable({ name, testData });
s.onerror = (error) => updateTable({ name, testData, error });

document.body.appendChild(s);
}
})();