How to use the ffpuppet.helpers.create_profile function in ffpuppet

To help you get started, we’ve selected a few ffpuppet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MozillaSecurity / ffpuppet / ffpuppet / test_helpers.py View on Github external
def test_helpers_03(tmp_path):
    """test create_profile() extension support"""
    # create a profile with a non-existent ext
    with pytest.raises(RuntimeError, match="Unknown extension: 'fake_ext'"):
        create_profile(extension="fake_ext", tmpdir=str(tmp_path))
    # create a profile with an xpi ext
    xpi = (tmp_path / "xpi-ext.xpi")
    xpi.touch()
    prof = create_profile(extension=str(xpi), tmpdir=str(tmp_path))
    assert "extensions" in os.listdir(prof)
    assert "xpi-ext.xpi" in os.listdir(os.path.join(prof, "extensions"))
    # create a profile with an unknown ext
    dummy_ext = (tmp_path / "dummy_ext")
    dummy_ext.mkdir()
    with pytest.raises(RuntimeError, match=r"Failed to find extension id in manifest: '.+?dummy_ext'"):
        create_profile(extension=str(dummy_ext), tmpdir=str(tmp_path))
    # create a profile with a bad legacy ext
    bad_legacy = (tmp_path / "bad_legacy")
    bad_legacy.mkdir()
    (bad_legacy / "install.rdf").touch()
    with pytest.raises(RuntimeError, match=r"Failed to find extension id in manifest: '.+?bad_legacy'"):
github MozillaSecurity / ffpuppet / ffpuppet / test_helpers.py View on Github external
bad_webext.mkdir()
    (bad_webext / "manifest.json").touch()
    with pytest.raises(RuntimeError, match=r"Failed to find extension id in manifest: '.+?bad_webext'"):
        create_profile(extension=str(bad_webext), tmpdir=str(tmp_path))
    # create a profile with a good webext
    good_webext = (tmp_path / "good_webext")
    good_webext.mkdir()
    (good_webext / "manifest.json").write_bytes(b"""{"applications": {"gecko": {"id": "good-webext-id"}}}""")
    (good_webext / "example.js").touch()
    prof = create_profile(extension=str(good_webext), tmpdir=str(tmp_path))
    assert "extensions" in os.listdir(prof)
    ext_path = os.path.join(prof, "extensions")
    assert "good-webext-id" in os.listdir(ext_path)
    assert set(os.listdir(os.path.join(ext_path, "good-webext-id"))) == {"manifest.json", "example.js"}
    # create a profile with multiple extensions
    prof = create_profile(extension=[str(good_webext), str(good_legacy)], tmpdir=str(tmp_path))
    assert "extensions" in os.listdir(prof)
    ext_path = os.path.join(prof, "extensions")
    assert set(os.listdir(ext_path)) == {"good-ext-id", "good-webext-id"}
    assert set(os.listdir(os.path.join(ext_path, "good-webext-id"))) == {"manifest.json", "example.js"}
    assert set(os.listdir(os.path.join(ext_path, "good-ext-id"))) == {"install.rdf", "example.js"}
github MozillaSecurity / ffpuppet / ffpuppet / test_helpers.py View on Github external
def test_helpers_01(tmp_path):
    """test create_profile()"""
    with pytest.raises(IOError, match="Cannot find template profile: 'fake_dir'"):
        create_profile(template="fake_dir")
    with pytest.raises(IOError, match="prefs.js file does not exist: 'fake_prefs'"):
        create_profile(prefs_js="fake_prefs")
    # try creating a profile from scratch, does nothing but create a directory to be populated
    prof = create_profile()
    assert os.path.isdir(prof)
    try:
        assert not os.listdir(prof)
    finally:
        shutil.rmtree(prof, ignore_errors=True)
    # create dummy profile
    profile = (tmp_path / "profile")
    profile.mkdir()
    invalid_js = (profile / "Invalidprefs.js")
    invalid_js.write_bytes(b"blah!")
    # try creating a profile from a template
    prof = create_profile(prefs_js=str(invalid_js), template=str(profile), tmpdir=str(tmp_path))
    assert os.path.isdir(prof)
    contents = os.listdir(prof)
    assert "prefs.js" in contents
    assert "times.json" in contents
github MozillaSecurity / ffpuppet / ffpuppet / test_helpers.py View on Github external
def test_helpers_01(tmp_path):
    """test create_profile()"""
    with pytest.raises(IOError, match="Cannot find template profile: 'fake_dir'"):
        create_profile(template="fake_dir")
    with pytest.raises(IOError, match="prefs.js file does not exist: 'fake_prefs'"):
        create_profile(prefs_js="fake_prefs")
    # try creating a profile from scratch, does nothing but create a directory to be populated
    prof = create_profile()
    assert os.path.isdir(prof)
    try:
        assert not os.listdir(prof)
    finally:
        shutil.rmtree(prof, ignore_errors=True)
    # create dummy profile
    profile = (tmp_path / "profile")
    profile.mkdir()
    invalid_js = (profile / "Invalidprefs.js")
    invalid_js.write_bytes(b"blah!")
    # try creating a profile from a template
    prof = create_profile(prefs_js=str(invalid_js), template=str(profile), tmpdir=str(tmp_path))
    assert os.path.isdir(prof)
    contents = os.listdir(prof)
github MozillaSecurity / ffpuppet / ffpuppet / test_helpers.py View on Github external
with pytest.raises(IOError, match="prefs.js file does not exist: 'fake_prefs'"):
        create_profile(prefs_js="fake_prefs")
    # try creating a profile from scratch, does nothing but create a directory to be populated
    prof = create_profile()
    assert os.path.isdir(prof)
    try:
        assert not os.listdir(prof)
    finally:
        shutil.rmtree(prof, ignore_errors=True)
    # create dummy profile
    profile = (tmp_path / "profile")
    profile.mkdir()
    invalid_js = (profile / "Invalidprefs.js")
    invalid_js.write_bytes(b"blah!")
    # try creating a profile from a template
    prof = create_profile(prefs_js=str(invalid_js), template=str(profile), tmpdir=str(tmp_path))
    assert os.path.isdir(prof)
    contents = os.listdir(prof)
    assert "prefs.js" in contents
    assert "times.json" in contents
    assert "Invalidprefs.js" not in contents
github MozillaSecurity / ffpuppet / ffpuppet / test_helpers.py View on Github external
def test_helpers_01(tmp_path):
    """test create_profile()"""
    with pytest.raises(IOError, match="Cannot find template profile: 'fake_dir'"):
        create_profile(template="fake_dir")
    with pytest.raises(IOError, match="prefs.js file does not exist: 'fake_prefs'"):
        create_profile(prefs_js="fake_prefs")
    # try creating a profile from scratch, does nothing but create a directory to be populated
    prof = create_profile()
    assert os.path.isdir(prof)
    try:
        assert not os.listdir(prof)
    finally:
        shutil.rmtree(prof, ignore_errors=True)
    # create dummy profile
    profile = (tmp_path / "profile")
    profile.mkdir()
    invalid_js = (profile / "Invalidprefs.js")
    invalid_js.write_bytes(b"blah!")
    # try creating a profile from a template
    prof = create_profile(prefs_js=str(invalid_js), template=str(profile), tmpdir=str(tmp_path))
github MozillaSecurity / ffpuppet / ffpuppet / core.py View on Github external
self._last_bin_path = os.path.dirname(bin_path)  # need the path for minidump_stackwalk

        log.debug("requested location: %r", location)
        if location is not None:
            if os.path.isfile(location):
                location = "///".join(
                    ["file:", pathname2url(os.path.realpath(location)).lstrip("/")])
            elif re.match(r"http(s)?://", location, re.IGNORECASE) is None:
                raise IOError("Cannot find %r" % location)

        self.reason = None
        launch_timeout = max(launch_timeout, self.LAUNCH_TIMEOUT_MIN)
        log.debug("launch timeout: %d", launch_timeout)

        # create and modify a profile
        self.profile = create_profile(
            extension=extension,
            prefs_js=prefs_js,
            template=self._profile_template)

        # performing the bootstrap helps guarantee that the browser
        # will be loaded and ready to accept input when launch() returns
        bootstrapper = Bootstrapper()
        try:
            prefs = {
                "capability.policy.policynames": "'localfilelinks'",
                "capability.policy.localfilelinks.sites": "'%s'" % bootstrapper.location,
                "capability.policy.localfilelinks.checkloaduri.enabled": "'allAccess'",
                "privacy.partition.network_state": "false"}
            if self._use_rr or self._use_valgrind:
                # when the browser is running slowly socket reads can fail if this is > 0
                prefs["network.http.speculative-parallel-limit"] = "0"
github MozillaSecurity / grizzly / grizzly / target / adb_device / adb_process.py View on Github external
self._session.call(["shell", "chmod", "666", sanitizer_logs])
        self.reason = None
        # setup bootstrapper and reverse port
        # reverse does fail occasionally so use a retry loop
        for _ in range(10):
            bootstrapper = Bootstrapper(poll_wait=0.5)
            if not self._session.reverse(bootstrapper.port, bootstrapper.port):
                bootstrapper.close()
                log.debug("failed to reverse port, retrying...")
                time.sleep(0.25)
                continue
            break
        else:
            raise ADBLaunchError("Could not reverse port")
        try:
            profile = create_profile(extension=extension, prefs_js=prefs_js, template=self._profile_template)
            try:
                prefs = {
                    "capability.policy.policynames": "'localfilelinks'",
                    "capability.policy.localfilelinks.sites": "'%s'" % bootstrapper.location,
                    "capability.policy.localfilelinks.checkloaduri.enabled": "'allAccess'"}
                append_prefs(profile, prefs)
                self.profile = "/".join([self._working_path, os.path.basename(profile)])
                if not self._session.push(profile, self.profile):
                    raise ADBLaunchError("Could not upload profile %r" % profile)
            finally:
                shutil.rmtree(profile, True)
            cmd = [
                "shell", "am", "start", "-W", "-n",
                "/".join([self._package, "org.mozilla.gecko.BrowserApp"]),
                "-a", "android.intent.action.VIEW", "-d", bootstrapper.location,
                "--es", "args", "-profile\\ %s" % self.profile]