Skip to content

Commit

Permalink
Merge pull request #138 from mozilla/sl/detected-blocked-trackers
Browse files Browse the repository at this point in the history
Cross site trackers, cryptominers and fingerprinters blocked
  • Loading branch information
sarinali authored Jul 29, 2024
2 parents 423e066 + 1003d4c commit d5d4b71
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 11 deletions.
12 changes: 6 additions & 6 deletions tests/security_and_privacy/test_blocking_cryptominers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from time import sleep

from selenium.webdriver import Firefox

from modules.browser_object_navigation import Navigation
from modules.page_object_about_prefs import AboutPrefs
from modules.browser_object import Navigation, TrackerPanel
from modules.page_object import AboutPrefs, GenericPage

CRYPTOMINERS_URL = "https://senglehardt.com/test/trackingprotection/test_pages/fingerprinting_and_cryptomining.html"

Expand All @@ -12,17 +10,19 @@ def test_blocking_cryptominers(driver: Firefox):
# instantiate objects
nav = Navigation(driver).open()
about_prefs = AboutPrefs(driver, category="privacy").open()
tracker_panel = TrackerPanel(driver)
tracking_page = GenericPage(driver, url=CRYPTOMINERS_URL)

# Select custom option and keep just cryptominers checked
about_prefs.get_element("custom-radio").click()
about_prefs.get_element("cookies-checkbox").click()
about_prefs.get_element("tracking-checkbox").click()
about_prefs.get_element("known-fingerprints-checkbox").click()
about_prefs.get_element("suspected-fingerprints-checkbox").click()
sleep(2)

# Access url and click on the shield icon and verify that cryptominers are blocked
driver.get(CRYPTOMINERS_URL)
tracking_page.open()
tracker_panel.wait_for_blocked_tracking_icon(nav, tracking_page)
with driver.context(driver.CONTEXT_CHROME):
nav.get_element("shield-icon").click()
assert nav.get_element("cryptominers").is_displayed()
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from time import sleep

from selenium.webdriver import Firefox

from modules.browser_object_navigation import Navigation
from modules.browser_object import Navigation, TrackerPanel
from modules.page_object import GenericPage

CRYPTOMINERS_URL = "https://senglehardt.com/test/trackingprotection/test_pages/fingerprinting_and_cryptomining.html"

Expand All @@ -13,8 +12,11 @@ def test_cryptominers_blocked_and_shown_in_info_panel(driver: Firefox):
"""
# Access URL, needed sleep otherwise cryptomining will be displayed as unblocked
nav = Navigation(driver)
sleep(4)
driver.get(CRYPTOMINERS_URL)
tracking_page = GenericPage(driver, url=CRYPTOMINERS_URL)
tracker_panel = TrackerPanel(driver)

tracking_page.open()
tracker_panel.wait_for_blocked_tracking_icon(nav, tracking_page)

# Click on the shield icon and verify that cryptominers are blocked
with driver.context(driver.CONTEXT_CHROME):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from time import sleep

from selenium.webdriver import Firefox

from modules.browser_object import Navigation, TrackerPanel
from modules.page_object import GenericPage

TRACKER_URL = "https://senglehardt.com/test/trackingprotection/test_pages/fingerprinting_and_cryptomining_and_cookies.html"


def test_cross_site_trackrs_crypto_fingerprinter_blocked(driver: Firefox):
"""
C446393: Ensures that some trackers are blocked on certain website
"""
# instantiate objs
tracker_page = GenericPage(driver, url=TRACKER_URL)
tracker_panel = TrackerPanel(driver)
nav = Navigation(driver).open()

# hard wait for fingerprinter blocker
sleep(4)

# wait for the shield icon
tracker_page.open()
tracker_panel.wait_for_blocked_tracking_icon(nav, tracker_page)
nav.open_tracker_panel()

# get children
driver.set_context(driver.CONTEXT_CHROME)
tracker_item_container = tracker_panel.get_element("tracking-item-container")
all_tracking_items = tracker_panel.get_all_children(tracker_item_container)

# instantiate test specific objs
blocked = set(["Cross-Site Tracking Cookies", "Fingerprinters", "Cryptominers"])
allowed = set(["Tracking Content"])
rm_blocked = False
rm_allowed = False

for item in all_tracking_items:
# encounter a header (everything after it is blocked/allowed in the list)
inner_html = item.get_attribute("innerHTML")
if "Blocked" in inner_html:
rm_blocked = True
continue
elif "Allowed" in inner_html:
rm_allowed = True
rm_blocked = False
continue

# assign a temp memory location, assign the set to it depending on the header seen earlier
rm_set = set()
to_rm_item = ""
if rm_blocked:
rm_set = blocked
elif rm_allowed:
rm_set = allowed

# go through the possible strings to look for, remove it if appropriate
for item in rm_set:
if item in inner_html:
to_rm_item = item
break
if to_rm_item != "":
rm_set.remove(to_rm_item)

# ensure that we have seen all of the expected items in each section
assert (
len(blocked) == 0 and len(allowed) == 0
), "Not all of the expected items were found in each of the Blocked/Allowed sections."

0 comments on commit d5d4b71

Please sign in to comment.