Skip to content

Commit

Permalink
Fix certutil lookup on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
tysmith committed Apr 24, 2023
1 parent cef9386 commit c0d07dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/ffpuppet/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from logging import getLogger
from os import W_OK, access, chmod, environ
from os.path import isfile
from pathlib import Path
from platform import system
from stat import S_IWUSR
Expand All @@ -20,6 +19,7 @@
if system() == "Windows":
from .lsof import pids_by_file

CERTUTIL = "certutil.exe" if system() == "Windows" else "certutil"
LLVM_SYMBOLIZER = "llvm-symbolizer.exe" if system() == "Windows" else "llvm-symbolizer"
LOG = getLogger(__name__)

Expand Down Expand Up @@ -66,8 +66,8 @@ def _configure_sanitizers(
]
# set llvm-symbolizer path
# *SAN_OPTIONS=external_symbolizer_path takes priority if it is defined in env
llvm_sym = env.get("ASAN_SYMBOLIZER_PATH", str(target_path / LLVM_SYMBOLIZER))
if isfile(llvm_sym):
llvm_sym = Path(env.get("ASAN_SYMBOLIZER_PATH") or target_path / LLVM_SYMBOLIZER)
if llvm_sym.is_file():
# add *SAN_OPTIONS=external_symbolizer_path
common_flags.append(("external_symbolizer_path", f"'{llvm_sym}'"))
else:
Expand Down Expand Up @@ -185,10 +185,10 @@ def certutil_find(browser_bin: Optional[Path] = None) -> str:
Path to certutil tool to use.
"""
if browser_bin:
path = browser_bin.parent / "bin" / "certutil"
path = browser_bin.parent / "bin" / CERTUTIL
if path.is_file():
return str(path)
return "certutil"
return CERTUTIL


def files_in_use(files: Iterable[Path]) -> Iterator[Tuple[Path, int, str]]:
Expand Down
16 changes: 7 additions & 9 deletions src/ffpuppet/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
from multiprocessing import Event, Process
from os import getpid
from pathlib import Path
from platform import system
from subprocess import CalledProcessError

from pytest import mark, raises

from .helpers import (
CERTUTIL,
LLVM_SYMBOLIZER,
_configure_sanitizers,
certutil_available,
certutil_find,
Expand Down Expand Up @@ -109,10 +110,7 @@ def parse(opt_str):
for key, value in (x.split(sep="=", maxsplit=1) for x in options):
assert asan_opts[key] == value
# test using packaged llvm-symbolizer
if system().startswith("Windows"):
llvm_sym_packed = tmp_path / "llvm-symbolizer.exe"
else:
llvm_sym_packed = tmp_path / "llvm-symbolizer"
llvm_sym_packed = tmp_path / LLVM_SYMBOLIZER
llvm_sym_packed.touch()
env = {"ASAN_OPTIONS": ":".join(options)}
env = _configure_sanitizers(env, tmp_path, "blah")
Expand Down Expand Up @@ -289,19 +287,19 @@ def test_helpers_07(tmp_path):
def test_certutil_available_01(mocker, raised, result):
"""test certutil_available()"""
mocker.patch("ffpuppet.helpers.check_output", autospec=True, side_effect=raised)
assert certutil_available("certutil") == result
assert certutil_available(CERTUTIL) == result


def test_certutil_find_01(tmp_path):
"""test certutil_find()"""
# default
assert certutil_find() == "certutil"
assert certutil_find() == CERTUTIL
# missing bundled certutil
browser_bin = tmp_path / "browser"
browser_bin.touch()
assert certutil_find(browser_bin) == "certutil"
assert certutil_find(browser_bin) == CERTUTIL
# found bundled certutil
certutil_bin = tmp_path / "bin" / "certutil"
certutil_bin = tmp_path / "bin" / CERTUTIL
certutil_bin.parent.mkdir()
certutil_bin.touch()
assert certutil_find(browser_bin) == str(certutil_bin)

0 comments on commit c0d07dd

Please sign in to comment.