class TBDriverBridgeTest(unittest.TestCase): def tearDown(self): self.tb_driver.quit() def should_load_check_tpo_via_bridge(self, bridge_type): self.tb_driver = TBDriverFixture(TBB_PATH, default_bridge_type=bridge_type) self.tb_driver.load_url_ensure(cm.CHECK_TPO_URL) status = self.tb_driver.find_element_by("h1.on") self.assertEqual(status.text, CONGRATS) # sleep(0) # the bridge type in use is manually verified by # checking the Tor Network Settings dialog. # We set a sleep of a few seconds and exported NO_XVFB=1 to do that # manually. # TODO: find a way to automatically verify the bridge in use # This may be possible with geckodriver, since it can interact # with chrome as well. def test_should_load_check_tpo_via_meek_amazon_bridge(self): self.should_load_check_tpo_via_bridge("meek-amazon") def test_should_load_check_tpo_via_meek_azure_bridge(self): self.should_load_check_tpo_via_bridge("meek-azure") def test_should_load_check_tpo_via_meek_obfs3_bridge(self): self.should_load_check_tpo_via_bridge("obfs3") def test_should_load_check_tpo_via_obfs4_bridge(self): self.should_load_check_tpo_via_bridge("obfs4") def test_should_load_check_tpo_via_fte_bridge(self): self.should_load_check_tpo_via_bridge("fte")
def test_missing_browser(self): driver = TBDriverFixture(TBB_PATH) tempfolder = driver.profile.tempfolder profile_path = driver.profile.path self.assertTrue(isdir(tempfolder)) self.assertTrue(isdir(profile_path)) # kill the browser process driver.binary.kill() driver.quit() self.assertFalse(isdir(profile_path)) self.assertFalse(isdir(tempfolder))
def test_running_with_system_tor(self): if not is_connectable(cm.DEFAULT_SOCKS_PORT): pytest.skip("Skipping. Start system Tor to run this test.") with TBDriverFixture(TBB_PATH, tor_cfg=cm.USE_RUNNING_TOR) as driver: driver.load_url_ensure(cm.CHECK_TPO_URL) driver.find_element_by("h1.on")
def setUpClass(cls): _, cls.temp_file = tempfile.mkstemp() # Passing canvas_allowed_hosts is not needed for TBB >= 4.5a3 canvas_allowed = [cm.CHECK_TPO_HOST] cls.driver = TBDriverFixture(TBB_PATH, canvas_allowed_hosts=canvas_allowed) cls.driver.load_url_ensure(cm.CHECK_TPO_URL, 3)
def test_running_with_system_tor(self): if not is_busy(cm.DEFAULT_SOCKS_PORT): self.fail("System Tor doesn't appear to be running.") with TBDriverFixture(TBB_PATH, tor_cfg=cm.USE_RUNNING_TOR) as driver: driver.load_url_ensure(cm.CHECK_TPO_URL) driver.find_element_by("h1.on")
def test_noscript_should_disable_webgl(self): webgl_status_disabled = ("This browser supports WebGL 1, " "but it is disabled or unavailable.") with TBDriverFixture(TBB_PATH) as driver: driver.load_url_ensure("http://webglreport.com/", wait_for_page_body=True) status = driver.find_element_by(".header > p").text self.assertIn(webgl_status_disabled, status)
def test_missing_browser(self): driver = TBDriverFixture(TBB_PATH) tempfolder = driver.profile.tempfolder profile_path = driver.profile.path self.assertTrue(isdir(tempfolder)) self.assertTrue(isdir(profile_path)) # kill the browser process if driver.w3c: driver.service.stop() driver.quit() else: driver.binary.kill() driver.quit() self.assertFalse(isdir(profile_path)) self.assertFalse(isdir(tempfolder))
def setUpClass(cls): super(TBStemTest, cls).setUpClass() cls.tor_process = launch_tbb_tor_with_stem_fixture(tbb_path=TBB_PATH) cls.controller = Controller.from_port(port=cm.STEM_CONTROL_PORT) cls.controller.authenticate() cls.driver = TBDriverFixture(TBB_PATH, tor_cfg=cm.USE_RUNNING_TOR, socks_port=cm.STEM_SOCKS_PORT)
def test_should_install_custom_extension(self): # We test if we can install the extension. # We should improve the test by checking the expected outcome. test_dir = os.path.dirname(os.path.realpath(__file__)) xpi_name = "xulschoolhello1.xpi" # sample extension taken from: # https://developer.mozilla.org/en-US/Add-ons/Overlay_Extensions/XUL_School/Getting_Started_with_Firefox_Extensions#Extension_Contents # noqa xpi_path = os.path.join(test_dir, "test_data", xpi_name) with TBDriverFixture(TBB_PATH, extensions=[xpi_path]) as driver: driver.load_url_ensure(cm.CHECK_TPO_URL)
def test_security_slider_settings_low_mid(self): # TODO: test other features to distinguish between levels # 2: medium-high, 3: medium-low, 4: low (default) for sec_slider_setting in [2, 3, 4]: slider_dict = {SEC_SLIDER_PREF: sec_slider_setting} with TBDriverFixture(TBB_PATH, pref_dict=slider_dict) as driver: driver.load_url_ensure(cm.CHECK_TPO_URL) driver.find_element_by("JavaScript is enabled.", find_by=By.LINK_TEXT, timeout=5)
def test_temp_tor_data_dir(self): """Tor data directory in TBB should not be modified if we use a separate tor_data_dir. """ tmp_dir = tempfile.mkdtemp() mod_time_before = getmtime(self.TOR_DATA_PATH) with TBDriverFixture(TBB_PATH, tor_data_dir=tmp_dir) as driver: driver.load_url_ensure(cm.CHECK_TPO_URL) mod_time_after = getmtime(self.TOR_DATA_PATH) self.assertEqual(mod_time_before, mod_time_after)
def test_running_with_system_tor(self): if not is_busy(cm.DEFAULT_SOCKS_PORT): if cm.TRAVIS: # Tor should be running on CI self.fail("Skipping. Start system Tor to run this test.") else: pytest.skip("Skipping. Start the system Tor to run this test.") with TBDriverFixture(TBB_PATH, tor_cfg=cm.USE_RUNNING_TOR) as driver: driver.load_url_ensure(cm.CHECK_TPO_URL) driver.find_element_by("h1.on")
def test_noscript_disable_webgl_block(self): """WebGL should work when we disable NoScript's WebGL blocking.""" disable_NS_webgl_pref = {"noscript.forbidWebGL": False} webgl_status_enabled = ("This browser supports WebGL 1") with TBDriverFixture(TBB_PATH, pref_dict=disable_NS_webgl_pref) as driver: driver.load_url_ensure("http://webglreport.com/", wait_for_page_body=True) status = driver.find_element_by(".header > p").text self.assertIn(webgl_status_enabled, status)
def test_set_security_high_webgl(self): with TBDriverFixture(TBB_PATH) as driver: set_security_level(driver, SECURITY_HIGH) driver.load_url_ensure(GET_WEBGL_ORG_URL) try: status_text = self.get_webgl_test_page_status_text(driver) assert status_text == "You must enable JavaScript to use WebGL." except (NoSuchElementException, TimeoutException): self.fail("Security level does not seem to be set to Safest")
def test_noscript_webgl_enabled(self): """Make sure that when we disable NoScript's WebGL blocking, WebGL becomes available. This is to the test method we use in test_noscript is sane. """ disable_NS_webgl_pref = {"noscript.forbidWebGL": False} with TBDriverFixture(TBB_PATH, pref_dict=disable_NS_webgl_pref) as driver: driver.load_url_ensure(cm.CHECK_TPO_URL, wait_for_page_body=True) webgl_support = driver.execute_script(self.WEBGL_CHECK_JS) self.assertIn("getSupportedExtensions", webgl_support)
def test_set_security_high(self): with TBDriverFixture(TBB_PATH) as driver: set_security_level(driver, SECURITY_HIGH) driver.load_url_ensure(CHECK_TPO_URL) try: driver.find_element_by("JavaScript is enabled.", find_by=By.LINK_TEXT, timeout=5) self.fail("Security level does not seem to be set to Safest") except (NoSuchElementException, TimeoutException): pass
def test_non_temp_tor_data_dir(self): """Tor data directory in TBB should be modified if we don't use a separate tor_data_dir. """ mod_time_before = getmtime(self.TOR_DATA_PATH) with TBDriverFixture(TBB_PATH, tor_cfg=cm.LAUNCH_NEW_TBB_TOR) as driver: driver.load_url_ensure(cm.CHECK_TPO_URL) mod_time_after = getmtime(self.TOR_DATA_PATH) self.assertNotEqual(mod_time_before, mod_time_after)
def test_bundled_fonts_via_chrome_script(self): # do not disable this pref when crawling untrusted sites pref_dict = {"dom.ipc.cpows.forbid-unsafe-from-browser": False} with TBDriverFixture(TBB_PATH, pref_dict=pref_dict) as driver: driver.load_url_ensure(CHECK_TPO_URL) driver.set_context('chrome') components = driver.execute_script(COMPONENT_CLASSES_JS) self.assertIn("@mozilla.org/gfx/fontenumerator", str(components)) used_fonts = driver.execute_script(ENUMERATE_FONTS) self.assertIn("Arimo", str(used_fonts))
def test_disable_js(self): with TBDriverFixture(TBB_PATH) as driver: disable_js(driver) driver.load_url_ensure(CHECK_TPO_URL) try: driver.find_element_by("JavaScript is enabled.", find_by=By.LINK_TEXT, timeout=5) self.fail("JavaScript is not disabled") except (NoSuchElementException, TimeoutException): pass
def test_https_everywhere_disabled(self): """Make sure the HTTP->HTTPS redirection in the above test is due to HTTPSEverywhere - not because the site is forwarding to HTTPS by default. We have to find another test site if this test starts to fail. """ disable_HE_pref = {"extensions.https_everywhere.globalEnabled": False} with TBDriverFixture(TBB_PATH, pref_dict=disable_HE_pref) as driver: driver.load_url_ensure(self.HE_HTTP_URL, 1) self.assertEqual(driver.current_url, self.HE_HTTP_URL)
def test_security_slider_settings_hi(self): """Slider setting `High` should disable JavaScript.""" with TBDriverFixture(TBB_PATH, pref_dict={SEC_SLIDER_PREF: 1}) as driver: driver.load_url_ensure(cm.CHECK_TPO_URL) try: driver.find_element_by("JavaScript is enabled.", find_by=By.LINK_TEXT, timeout=5) self.fail("Security slider should disable JavaScript") except (NoSuchElementException, TimeoutException): pass
def setUpClass(cls): _, log_file = tempfile.mkstemp() # https://www.freedesktop.org/software/fontconfig/fontconfig-user.html environ["FC_DEBUG"] = "%d" % (1024 + 8 + 1) cls.driver = TBDriverFixture(TBB_PATH, tbb_logfile_path=log_file) driver = cls.driver if not driver.supports_bundled_fonts: cls.tearDownClass() pytest.skip("Skip bundled font tests. V%s" % driver.tb_version) driver.load_url_ensure("https://www.wikipedia.org/") cls.log_txt = ut.read_file(log_file) cls.bundled_fonts_dir = join(driver.tbb_path, cm.DEFAULT_BUNDLED_FONTS_PATH) cls.bundled_font_files = set(ut.gen_find_files(cls.bundled_fonts_dir))
def setUpClass(cls): super(TBStemTest, cls).setUpClass() cls.control_port = free_port() cls.socks_port = free_port() temp_data_dir = tempfile.mkdtemp() torrc = {'ControlPort': str(cls.control_port), 'SOCKSPort': str(cls.socks_port), 'DataDirectory': temp_data_dir} cls.tor_process = launch_tbb_tor_with_stem_fixture(tbb_path=TBB_PATH, torrc=torrc) cls.controller = Controller.from_port(port=cls.control_port) cls.controller.authenticate() cls.driver = TBDriverFixture(TBB_PATH, tor_cfg=cm.USE_STEM, socks_port=cls.socks_port, control_port=cls.control_port)
def test_disable_js(self): # Disable javascript using the noscript pref # if we don't set torbutton.security_custom to True, torbutton # security slider will overwrite our modification and enable JS pref_dict = { "noscript.global": False, "extensions.torbutton.security_custom": True } with TBDriverFixture(TBB_PATH, pref_dict=pref_dict) as driver: driver.load_url_ensure(CHECK_TPO_URL) try: driver.find_element_by("JavaScript is enabled.", find_by=By.LINK_TEXT, timeout=5) self.fail("JavaScript is not disabled") except (NoSuchElementException, TimeoutException): pass
class TBDriverTest(unittest.TestCase): def setUp(self): self.tb_driver = TBDriverFixture(TBB_PATH) def tearDown(self): self.tb_driver.quit() def test_should_load_check_tpo(self): congrats = "Congratulations. This browser is configured to use Tor." self.tb_driver.load_url_ensure(cm.CHECK_TPO_URL) status = self.tb_driver.find_element_by("h1.on") self.assertEqual(status.text, congrats) def test_should_load_hidden_service(self): self.tb_driver.load_url_ensure("http://3g2upl4pq6kufc4m.onion") self.assertIn("DuckDuckGo", self.tb_driver.title) def test_should_check_environ_in_prepend(self): self.tb_driver.quit() self.tb_driver = TBDriverFixture(TBB_PATH) paths = environ["PATH"].split(':') tbbpath_count = paths.count(self.tb_driver.tbb_browser_dir) self.assertEqual(tbbpath_count, 1)
class TBDriverTest(unittest.TestCase): def setUp(self): self.tb_driver = TBDriverFixture(TBB_PATH) def tearDown(self): self.tb_driver.quit() def test_should_load_check_tpo(self): congrats = "Congratulations. This browser is configured to use Tor." self.tb_driver.load_url_ensure(cm.CHECK_TPO_URL) status = self.tb_driver.find_element_by("h1.on") self.assertEqual(status.text, congrats) def test_should_load_hidden_service(self): self.tb_driver.load_url_ensure("http://3g2upl4pq6kufc4m.onion", wait_for_page_body=True) self.assertIn("DuckDuckGo", self.tb_driver.title) def test_should_check_environ_in_prepend(self): self.tb_driver.quit() self.tb_driver = TBDriverFixture(TBB_PATH) paths = environ["PATH"].split(':') tbbpath_count = paths.count(self.tb_driver.tbb_browser_dir) self.assertEqual(tbbpath_count, 1)
def test_set_security_medium_webgl(self): with TBDriverFixture(TBB_PATH) as driver: set_security_level(driver, SECURITY_MEDIUM) driver.load_url_ensure(GET_WEBGL_ORG_URL) try: # test the status text status_text = self.get_webgl_test_page_status_text(driver) assert status_text == "Your browser supports WebGL" # make sure WebGL is click-to-play (NoScript) webgl_container_inner_html = \ self.get_webgl_test_page_webgl_container_inner_html(driver) assert webgl_container_inner_html.startswith( '<a class="__NoScript_PlaceHolder__') except (NoSuchElementException, TimeoutException) as exc: self.fail( "Security level does not seem to be set to Medium: %s" % exc)
def test_set_security_low_webgl(self): with TBDriverFixture(TBB_PATH) as driver: set_security_level(driver, SECURITY_LOW) driver.load_url_ensure(GET_WEBGL_ORG_URL) try: # test the status text status_text = self.get_webgl_test_page_status_text(driver) assert status_text.startswith("Your browser supports WebGL") # make sure WebGL is enabled webgl_container_inner_html = \ self.get_webgl_test_page_webgl_container_inner_html(driver) assert webgl_container_inner_html.startswith( '<canvas id="webgl-logo"') except (NoSuchElementException, TimeoutException) as exc: self.fail( "Security level does not seem to be set to Standard: %s" % exc)
def setUpClass(cls): _, cls.log_file = tempfile.mkstemp() cls.driver = TBDriverFixture(TBB_PATH, tbb_logfile_path=cls.log_file)
def setUp(self): self.tb_driver = TBDriverFixture(TBB_PATH)
def test_should_check_environ_in_prepend(self): self.tb_driver.quit() self.tb_driver = TBDriverFixture(TBB_PATH) paths = environ["PATH"].split(':') tbbpath_count = paths.count(self.tb_driver.tbb_browser_dir) self.assertEqual(tbbpath_count, 1)
def test_fixture_should_raise_for_invalid_tor_config(self): with self.assertRaises(TBDriverConfigError): TBDriverFixture(TBB_PATH, tor_cfg=-1)
def should_load_check_tpo_via_bridge(self, bridge_type): self.tb_driver = TBDriverFixture(TBB_PATH, default_bridge_type=bridge_type) self.tb_driver.load_url_ensure(cm.CHECK_TPO_URL) status = self.tb_driver.find_element_by("h1.on") self.assertEqual(status.text, CONGRATS)