From e1d96b413e754827d8c79e7cb7cf649f7b8ffc1f Mon Sep 17 00:00:00 2001 From: Sarina Li Date: Wed, 24 Jul 2024 13:54:01 -0400 Subject: [PATCH 1/7] format --- modules/browser_object_tracker_panel.py | 29 ++++++++++++ modules/data/tracker_panel.components.json | 6 +++ ...est_cross_site_tracking_cookies_blocked.py | 46 +++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 tests/security_and_privacy/test_cross_site_tracking_cookies_blocked.py diff --git a/modules/browser_object_tracker_panel.py b/modules/browser_object_tracker_panel.py index fc4ab4d7..53a0144c 100644 --- a/modules/browser_object_tracker_panel.py +++ b/modules/browser_object_tracker_panel.py @@ -50,6 +50,35 @@ def shield_active() -> bool: ) return self + def wait_for_trackers(self, nav: Navigation, page: BasePage) -> BasePage: + """ + Waits for trackers to appear + + Remember to open the passed in page beforehand, this waits for the page to load. + + Example Usage: + first_tracker_website.open() + tracker_panel.wait_for_blocked_tracking_icon(nav, first_tracker_website) + """ + + def message_not_present() -> bool: + nav.get_element("refresh-button").click() + with self.driver.context(self.driver.CONTEXT_CONTENT): + page.open() + page.wait_for_page_to_load() + self.get_element("shield-icon").click() + no_trackers_message = self.get_element("no-trackers-message") + if no_trackers_message.get_attribute("hidden") == "true": + return True + return False + + try: + with self.driver.context(self.context_id): + self.wait.until(lambda _: message_not_present()) + except TimeoutException: + logging.warning("No trackers were ever detected after the timeout period.") + return self + def verify_tracker_shield_indicator(self, nav: Navigation) -> BasePage: """ Verifies that the shield icon is in the correct mode diff --git a/modules/data/tracker_panel.components.json b/modules/data/tracker_panel.components.json index 72eb5847..546271ed 100644 --- a/modules/data/tracker_panel.components.json +++ b/modules/data/tracker_panel.components.json @@ -61,5 +61,11 @@ "doNotCache", "requiredForPage" ] + }, + + "no-trackers-message": { + "selectorData": "protections-popup-no-trackers-found-description", + "strategy": "id", + "groups": [] } } \ No newline at end of file diff --git a/tests/security_and_privacy/test_cross_site_tracking_cookies_blocked.py b/tests/security_and_privacy/test_cross_site_tracking_cookies_blocked.py new file mode 100644 index 00000000..63b5546d --- /dev/null +++ b/tests/security_and_privacy/test_cross_site_tracking_cookies_blocked.py @@ -0,0 +1,46 @@ +from time import sleep + +import pytest +from selenium.webdriver import Firefox + +from modules.browser_object import Navigation, TrackerPanel +from modules.page_object import GenericPage + +FIRST_TRACKER_WEBSITE = "https://senglehardt.com/test/trackingprotection/test_pages/tracking_protection.html" +ALLOWED_TRACKING_URLS = set( + [ + "https://content-track-digest256.dummytracker.org", + "https://ads-track-digest256.dummytracker.org", + "https://social-track-digest256.dummytracker.org", + "https://analytics-track-digest256.dummytracker.org", + ] +) + + +@pytest.fixture() +def add_prefs(): + return [ + ("network.cookie.cookieBehavior", 0), + ("privacy.trackingprotection.pbmode.enabled", False), + ("privacy.trackingprotection.cryptomining.enabled", False), + ("privacy.trackingprotection.fingerprinting.enabled", False), + ("privacy.fingerprintingProtection.pbmode", False), + ] + + +def test_cross_site_tracking_cookies_blocked(driver: Firefox): + """ + C446402: Ensures the + """ + # instantiate objects + nav = Navigation(driver) + tracker_panel = TrackerPanel(driver) + tracker_website = GenericPage(driver, url=FIRST_TRACKER_WEBSITE).open() + tracker_panel.wait_for_trackers(nav, tracker_website) + + driver.set_context(driver.CONTEXT_CHROME) + nav.open_tracker_panel() + + # # fetch the items in the cross site trackers + cross_site_trackers = tracker_panel.open_and_return_cross_site_trackers() + sleep(40) From 7e254763d273aed04078d6db5d837bec59d78d9e Mon Sep 17 00:00:00 2001 From: Sarina Li Date: Wed, 24 Jul 2024 13:58:27 -0400 Subject: [PATCH 2/7] fix wiki search --- modules/page_object_google_search.py | 8 ++++++++ .../test_cookies_not_saved_private_browsing.py | 17 +++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/modules/page_object_google_search.py b/modules/page_object_google_search.py index 4c230440..acbf885d 100644 --- a/modules/page_object_google_search.py +++ b/modules/page_object_google_search.py @@ -1,6 +1,7 @@ from selenium.webdriver.remote.webelement import WebElement from modules.page_base import BasePage +from selenium.webdriver.common.keys import Keys class GoogleSearch(BasePage): @@ -17,6 +18,13 @@ def type_in_search_bar(self, text: str) -> BasePage: search_bar = self.get_search_bar_element() search_bar.send_keys(text) + def press_enter_search_bar(self) -> BasePage: + """ + Sends Enter into the search bar + """ + search_bar = self.get_search_bar_element() + search_bar.send_keys(Keys.ENTER) + def get_search_bar_element(self) -> WebElement: """ Finds the search bar element and returns it as a WebElement diff --git a/tests/security_and_privacy/test_cookies_not_saved_private_browsing.py b/tests/security_and_privacy/test_cookies_not_saved_private_browsing.py index df4cd99c..dd221d77 100644 --- a/tests/security_and_privacy/test_cookies_not_saved_private_browsing.py +++ b/tests/security_and_privacy/test_cookies_not_saved_private_browsing.py @@ -1,7 +1,7 @@ from selenium.webdriver import Firefox from modules.browser_object import Navigation, PanelUi -from modules.page_object import AboutPrefs, GenericPage +from modules.page_object import AboutPrefs, GenericPage, GoogleSearch from modules.util import BrowserActions @@ -13,21 +13,18 @@ def test_cookies_not_saved_private_browsing(driver: Firefox): about_prefs = AboutPrefs(driver, category="privacy") panel_ui = PanelUi(driver).open() nav = Navigation(driver) - wiki_page = GenericPage( - driver, url="https://ro.wikipedia.org/wiki/Pagina_principal%C4%83" - ) + google_search = GoogleSearch(driver) ba = BrowserActions(driver) # open new private window panel_ui.open_private_window() nav.switch_to_new_window() - # open the wiki page and perform a search - wiki_page.open() - wiki_search_bar = wiki_page.get_element("wiki-search-bar") - wiki_search_bar.send_keys("hello") - wiki_page.get_element("wiki-search-button").click() - wiki_page.wait_for_page_to_load() + # open the google page and perform a search + google_search.open() + google_search.type_in_search_bar("hello") + google_search.press_enter_search_bar() + google_search.wait_for_page_to_load() # close the page and switch to first tab driver.close() From 2852558527f2079009383293dc7da2e1af33df22 Mon Sep 17 00:00:00 2001 From: Sarina Li Date: Wed, 24 Jul 2024 13:58:56 -0400 Subject: [PATCH 3/7] format --- modules/page_object_google_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/page_object_google_search.py b/modules/page_object_google_search.py index acbf885d..79abe1f2 100644 --- a/modules/page_object_google_search.py +++ b/modules/page_object_google_search.py @@ -1,7 +1,7 @@ +from selenium.webdriver.common.keys import Keys from selenium.webdriver.remote.webelement import WebElement from modules.page_base import BasePage -from selenium.webdriver.common.keys import Keys class GoogleSearch(BasePage): From db398ff03968b5ed30aedc1269387b8ea009f947 Mon Sep 17 00:00:00 2001 From: Sarina Li Date: Wed, 24 Jul 2024 14:11:13 -0400 Subject: [PATCH 4/7] finish test --- .../test_cookies_not_saved_private_browsing.py | 2 +- .../test_cross_site_tracking_cookies_blocked.py | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/security_and_privacy/test_cookies_not_saved_private_browsing.py b/tests/security_and_privacy/test_cookies_not_saved_private_browsing.py index dd221d77..d53cf99d 100644 --- a/tests/security_and_privacy/test_cookies_not_saved_private_browsing.py +++ b/tests/security_and_privacy/test_cookies_not_saved_private_browsing.py @@ -1,7 +1,7 @@ from selenium.webdriver import Firefox from modules.browser_object import Navigation, PanelUi -from modules.page_object import AboutPrefs, GenericPage, GoogleSearch +from modules.page_object import AboutPrefs, GoogleSearch from modules.util import BrowserActions diff --git a/tests/security_and_privacy/test_cross_site_tracking_cookies_blocked.py b/tests/security_and_privacy/test_cross_site_tracking_cookies_blocked.py index 63b5546d..faa9efba 100644 --- a/tests/security_and_privacy/test_cross_site_tracking_cookies_blocked.py +++ b/tests/security_and_privacy/test_cross_site_tracking_cookies_blocked.py @@ -1,4 +1,3 @@ -from time import sleep import pytest from selenium.webdriver import Firefox @@ -7,9 +6,8 @@ from modules.page_object import GenericPage FIRST_TRACKER_WEBSITE = "https://senglehardt.com/test/trackingprotection/test_pages/tracking_protection.html" -ALLOWED_TRACKING_URLS = set( +ALLOWED_COOKIES = set( [ - "https://content-track-digest256.dummytracker.org", "https://ads-track-digest256.dummytracker.org", "https://social-track-digest256.dummytracker.org", "https://analytics-track-digest256.dummytracker.org", @@ -20,7 +18,6 @@ @pytest.fixture() def add_prefs(): return [ - ("network.cookie.cookieBehavior", 0), ("privacy.trackingprotection.pbmode.enabled", False), ("privacy.trackingprotection.cryptomining.enabled", False), ("privacy.trackingprotection.fingerprinting.enabled", False), @@ -30,7 +27,7 @@ def add_prefs(): def test_cross_site_tracking_cookies_blocked(driver: Firefox): """ - C446402: Ensures the + C446402: Ensures the cross tracking cookies are displayed in the tracker panel """ # instantiate objects nav = Navigation(driver) @@ -41,6 +38,7 @@ def test_cross_site_tracking_cookies_blocked(driver: Firefox): driver.set_context(driver.CONTEXT_CHROME) nav.open_tracker_panel() - # # fetch the items in the cross site trackers + # fetch the items in the cross site trackers and verify cross_site_trackers = tracker_panel.open_and_return_cross_site_trackers() - sleep(40) + for item in cross_site_trackers: + assert item.get_attribute("value") in ALLOWED_COOKIES \ No newline at end of file From c9c7f733db58aad23f2e7780c58fd4a16dd4fded Mon Sep 17 00:00:00 2001 From: Sarina Li Date: Wed, 24 Jul 2024 14:16:12 -0400 Subject: [PATCH 5/7] add req for page --- modules/data/google_search.components.json | 4 +++- .../test_cross_site_tracking_cookies_blocked.py | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/data/google_search.components.json b/modules/data/google_search.components.json index 47f3deda..c6bbb4f9 100644 --- a/modules/data/google_search.components.json +++ b/modules/data/google_search.components.json @@ -2,6 +2,8 @@ "search-bar-textarea": { "selectorData": "textarea[aria-label='Search']", "strategy": "css", - "groups": [] + "groups": [ + "requiredForPage" + ] } } \ No newline at end of file diff --git a/tests/security_and_privacy/test_cross_site_tracking_cookies_blocked.py b/tests/security_and_privacy/test_cross_site_tracking_cookies_blocked.py index faa9efba..2e032cfe 100644 --- a/tests/security_and_privacy/test_cross_site_tracking_cookies_blocked.py +++ b/tests/security_and_privacy/test_cross_site_tracking_cookies_blocked.py @@ -1,4 +1,3 @@ - import pytest from selenium.webdriver import Firefox @@ -41,4 +40,4 @@ def test_cross_site_tracking_cookies_blocked(driver: Firefox): # fetch the items in the cross site trackers and verify cross_site_trackers = tracker_panel.open_and_return_cross_site_trackers() for item in cross_site_trackers: - assert item.get_attribute("value") in ALLOWED_COOKIES \ No newline at end of file + assert item.get_attribute("value") in ALLOWED_COOKIES From c60770d97d33ef1118d4e641f79ad6565000e7fa Mon Sep 17 00:00:00 2001 From: Sarina Li Date: Wed, 24 Jul 2024 15:37:59 -0400 Subject: [PATCH 6/7] mark unstable --- .../test_cookies_not_saved_private_browsing.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/security_and_privacy/test_cookies_not_saved_private_browsing.py b/tests/security_and_privacy/test_cookies_not_saved_private_browsing.py index d53cf99d..8d562a7c 100644 --- a/tests/security_and_privacy/test_cookies_not_saved_private_browsing.py +++ b/tests/security_and_privacy/test_cookies_not_saved_private_browsing.py @@ -1,3 +1,4 @@ +import pytest from selenium.webdriver import Firefox from modules.browser_object import Navigation, PanelUi @@ -5,6 +6,7 @@ from modules.util import BrowserActions +@pytest.mark.unstable def test_cookies_not_saved_private_browsing(driver: Firefox): """ C101677: ensure that cookies are not saved after using private browsing From 1eb2afa5a546d87bcebad0cfcb19ac2ec9dbf434 Mon Sep 17 00:00:00 2001 From: Sarina Li Date: Thu, 25 Jul 2024 11:40:42 -0400 Subject: [PATCH 7/7] rm double neg --- modules/browser_object_tracker_panel.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/browser_object_tracker_panel.py b/modules/browser_object_tracker_panel.py index 53a0144c..fbd8edfe 100644 --- a/modules/browser_object_tracker_panel.py +++ b/modules/browser_object_tracker_panel.py @@ -61,20 +61,20 @@ def wait_for_trackers(self, nav: Navigation, page: BasePage) -> BasePage: tracker_panel.wait_for_blocked_tracking_icon(nav, first_tracker_website) """ - def message_not_present() -> bool: + def message_present() -> bool: nav.get_element("refresh-button").click() with self.driver.context(self.driver.CONTEXT_CONTENT): page.open() page.wait_for_page_to_load() self.get_element("shield-icon").click() no_trackers_message = self.get_element("no-trackers-message") - if no_trackers_message.get_attribute("hidden") == "true": + if no_trackers_message.get_attribute("hidden") is None: return True return False try: with self.driver.context(self.context_id): - self.wait.until(lambda _: message_not_present()) + self.wait.until_not(lambda _: message_present()) except TimeoutException: logging.warning("No trackers were ever detected after the timeout period.") return self