def test_tbb_logfile(self):
        """Make sure log file is populated."""
        _, log_file = tempfile.mkstemp()
        log_len = len(ut.read_file(log_file))
        self.assertEqual(log_len, 0)

        with TorBrowserDriver(TBB_PATH, tbb_logfile_path=log_file) as driver:
            driver.load_url_ensure(cm.CHECK_TPO_URL)

        log_txt = ut.read_file(log_file)
        # make sure we find the expected strings in the log
        self.assertIn("*****@*****.**", log_txt)
        self.assertIn("addons.manager", log_txt)
        if exists(log_file):
            remove(log_file)
Ejemplo n.º 2
0
 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))
Ejemplo n.º 3
0
    def test_should_load_tbb_firefox_libs(self):
        """Make sure we load the Firefox libraries from the TBB directories.
        We only test libxul (main Firefox/Gecko library) and libstdc++.

        The memory map of the TB process is used to find loaded libraries.
        http://man7.org/linux/man-pages/man5/proc.5.html
        """

        driver = self.driver
        pid = driver.binary.process.pid
        xul_lib_path = join(driver.tbb_browser_dir, "libxul.so")
        std_c_lib_path = join(driver.tbb_path, cm.DEFAULT_TOR_BINARY_DIR,
                              "libstdc++.so.6")
        proc_mem_map_file = "/proc/%d/maps" % (pid)
        mem_map = ut.read_file(proc_mem_map_file)
        self.assertIn(xul_lib_path, mem_map)
        self.assertIn(std_c_lib_path, mem_map)
Ejemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     self.change_default_tor_cfg(kwargs)
     last_err = None
     for tries in range(MAX_FIXTURE_TRIES):
         try:
             return super(TBDriverFixture, self).__init__(*args, **kwargs)
         except (TimeoutException, WebDriverException,
                 socket_error) as last_err:
             print("\nTBDriver init error. Attempt %s %s" %
                   ((tries + 1), last_err))
             if FORCE_TB_LOGS_DURING_TESTS:
                 logs = read_file(kwargs.get("tbb_logfile_path"))
                 if len(logs):
                     print("TB logs:\n%s\n(End of TB logs)" % logs)
             super(TBDriverFixture, self).quit()  # clean up
             continue
     # Raise if we didn't return yet
     to_raise = last_err if last_err else\
         TorBrowserDriverInitError("Cannot initialize")
     raise to_raise
    def test_font_bundling(self):
        _, log_file = tempfile.mkstemp()
        used_font_files = set()
        bundled_fonts_dir = join(TBB_PATH, cm.DEFAULT_BUNDLED_FONTS_PATH)
        # join returns a relative path on Travis CI
        bundled_fonts_dir = abspath(bundled_fonts_dir)
        environ["FC_DEBUG"] = "%d" % (1024 + 8 + 1)
        """
        We set FC_DEBUG to 1024 + 8 + 1 to make sure we get logs about...
        MATCH            1    Brief information about font matching
        FONTSET          8    Track loading of font information at startup
        CONFIG        1024    Monitor which config files are loaded
        https://www.freedesktop.org/software/fontconfig/fontconfig-user.html
        """
        with TorBrowserDriver(TBB_PATH, tbb_logfile_path=log_file) as driver:
            driver.load_url_ensure("https://www.wikipedia.org/")
        bundled_font_files = set(ut.gen_find_files(bundled_fonts_dir))
        # make sure we discovered the bundled fonts
        self.assertTrue(len(bundled_font_files) > 0)
        log_txt = ut.read_file(log_file)

        expected_load_cfg_log = "Loading config file %s" %\
                                join(TBB_PATH, cm.DEFAULT_FONTS_CONF_PATH)
        self.assertIn(expected_load_cfg_log, log_txt)

        expected_load_fonts_log = "adding fonts from%s" % bundled_fonts_dir
        self.assertIn(expected_load_fonts_log, log_txt)

        # We get the following log if Firefox cannot find any fonts at startup
        #     (firefox:5611): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type='PangoRenderFc', script='common'  # noqa
        self.assertNotIn("failed to choose a font, expect ugly output",
                         log_txt)
        for _, font_path, _ in re.findall(r"(file: \")(.*)(\".*)", log_txt):
            # make sure all fonts are loaded from the bundled font directory
            # fontconfig logs include path to the font file, e.g.
            # file: "/path/to/tbb/Browser/fonts/Arimo-Bold.ttf"(w)
            self.assertIn(bundled_fonts_dir, font_path)
            used_font_files.add(font_path)
        # make sure the TBB only loaded and used the bundled fonts
        self.assertEqual(used_font_files, bundled_font_files)
        environ["FC_DEBUG"] = ""
Ejemplo n.º 6
0
    def __init__(self, *args, **kwargs):
        self.change_default_tor_cfg(kwargs)
        last_err = None
        log_file = kwargs.get("tbb_logfile_path")

        for tries in range(MAX_FIXTURE_TRIES):
            try:
                return super(TBDriverFixture, self).__init__(*args, **kwargs)
            except (TimeoutException, WebDriverException,
                    socket_error) as last_err:
                print ("\nTBDriver init error. Attempt %s %s" %
                       ((tries + 1), last_err))
                if FORCE_TB_LOGS_DURING_TESTS:
                    logs = read_file(log_file)
                    if len(logs):
                        print("TB logs:\n%s\n(End of TB logs)" % logs)
                super(TBDriverFixture, self).quit()  # clean up
                continue
        # Raise if we didn't return yet
        to_raise = last_err if last_err else\
            TorBrowserDriverInitError("Cannot initialize")
        raise to_raise
Ejemplo n.º 7
0
    def test_should_load_tbb_firefox_libs(self):
        """Make sure we load the Firefox libraries from the TBB directories.
        We only test libxul (main Firefox/Gecko library) and libstdc++.

        The memory map of the TB process is used to find loaded libraries.
        http://man7.org/linux/man-pages/man5/proc.5.html
        """
        FF_BINARY_SUFFIX = '.real'
        driver = self.driver
        geckodriver_pid = driver.service.process.pid
        process = psutil.Process(geckodriver_pid)
        tbbinary_path = self.driver.binary.which('firefox') + FF_BINARY_SUFFIX
        for child in process.children():
            if tbbinary_path == child.exe():
                tb_pid = child.pid
                break
        else:
            self.fail("Cannot find the firefox process")
        xul_lib_path = join(driver.tbb_browser_dir, "libxul.so")
        std_c_lib_path = join(driver.tbb_browser_dir, "libssl3.so")
        proc_mem_map_file = "/proc/%d/maps" % (tb_pid)
        mem_map = read_file(proc_mem_map_file)
        self.assertIn(xul_lib_path, mem_map)
        self.assertIn(std_c_lib_path, mem_map)
Ejemplo n.º 8
0
    def test_should_load_tbb_firefox_libs(self):
        """Make sure we load the Firefox libraries from the TBB directories.
        We only test libxul (main Firefox/Gecko library) and libstdc++.

        The memory map of the TB process is used to find loaded libraries.
        http://man7.org/linux/man-pages/man5/proc.5.html
        """

        driver = self.driver
        geckodriver_pid = driver.service.process.pid
        process = psutil.Process(geckodriver_pid)
        tbbinary_path = self.driver.binary.which('firefox')
        for child in process.children():
            if tbbinary_path == child.exe():
                tb_pid = child.pid
                break

        xul_lib_path = join(driver.tbb_browser_dir, "libxul.so")
        std_c_lib_path = join(driver.tbb_path, cm.DEFAULT_TOR_BINARY_DIR,
                              "libstdc++.so.6")
        proc_mem_map_file = "/proc/%d/maps" % (tb_pid)
        mem_map = read_file(proc_mem_map_file)
        self.assertIn(xul_lib_path, mem_map)
        self.assertIn(std_c_lib_path, mem_map)
 def test_read_file(self):
     file_content = ut.read_file(realpath(__file__))
     self.assertIn('whatever written here', file_content)
Ejemplo n.º 10
0
 def test_tbb_logfile(self):
     log_txt = read_file(self.log_file)
     print(log_txt)
     self.assertIn("Torbutton INFO", log_txt)
Ejemplo n.º 11
0
 def test_tbb_logfile(self):
     log_txt = ut.read_file(self.log_file)
     self.assertIn("*****@*****.**", log_txt)
     self.assertIn("addons.manager", log_txt)
Ejemplo n.º 12
0
 def test_tbb_logfile(self):
     log_txt = read_file(self.log_file)
     self.assertIn("*****@*****.**", log_txt)
     self.assertIn("addons.manager", log_txt)
Ejemplo n.º 13
0
 def test_tbb_logfile(self):
     log_txt = read_file(self.log_file)
     self.assertIn("Torbutton INFO", log_txt)