-
-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic canvas fingerprinting detection test.
Fixes #1268.
- Loading branch information
1 parent
4f55ae0
commit 100ae2e
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: UTF-8 -*- | ||
|
||
import unittest | ||
|
||
import pbtest | ||
|
||
|
||
class FingerprintingDetectionTest(pbtest.PBSeleniumTest): | ||
"""Tests to make sure fingerprinting detection works as expected.""" | ||
|
||
def detected_tracking(self, domain, page_url): | ||
return self.js("""let tracker_origin = window.getBaseDomain("{}"), | ||
site_origin = window.getBaseDomain(utils.makeURI("{}").host), | ||
map = badger.storage.snitch_map.getItemClones(); | ||
return ( | ||
map.hasOwnProperty(tracker_origin) && | ||
map[tracker_origin].indexOf(site_origin) != -1 | ||
);""".format(domain, page_url)) | ||
|
||
def test_canvas_fingerprinting_detection(self): | ||
PAGE_URL = ( | ||
"https://cdn.rawgit.com/ghostwords" | ||
"/ff6347b93ec126d4f73a9ddfd8b09919/raw/2332f82d3982bd4a84cd2380aed90228955d1f2a" | ||
"/privacy_badger_fingerprint_test_fixture.html" | ||
) | ||
FINGERPRINTING_DOMAIN = "cdn.jsdelivr.net" | ||
|
||
# visit the page | ||
self.load_url(PAGE_URL) | ||
|
||
# open Badger's background page | ||
self.open_window() | ||
self.load_url(self.bg_url, wait_on_site=1) | ||
|
||
# check that we detected the fingerprinting domain as a tracker | ||
self.assertTrue( | ||
self.detected_tracking(FINGERPRINTING_DOMAIN, PAGE_URL), | ||
"Canvas fingerprinting resource was detected as a tracker." | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |