mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-09-14 11:06:13 +05:00
use archivebox installs in browser security tests
This commit is contained in:
parent
a99321c030
commit
16cd3837e4
@ -59,9 +59,10 @@ def _assert_safe_runtime_paths(*, cwd: Path | None = None, env: dict[str, str] |
|
||||
def _test_source_pythonpath() -> str:
|
||||
entries: list[str] = []
|
||||
for repo_name in ("abxpkg", "abx-plugins", "abx-dl"):
|
||||
repo_path = WORKSPACE_ROOT / repo_name
|
||||
if repo_path.exists():
|
||||
entries.append(str(repo_path.resolve(strict=False)))
|
||||
for repo_path in (WORKSPACE_ROOT / repo_name, REPO_ROOT / repo_name):
|
||||
if repo_path.exists():
|
||||
entries.append(str(repo_path.resolve(strict=False)))
|
||||
break
|
||||
return os.pathsep.join(entries)
|
||||
|
||||
|
||||
@ -1427,26 +1428,6 @@ def _find_system_browser() -> Path | None:
|
||||
return None
|
||||
|
||||
|
||||
def _ensure_puppeteer(shared_lib: Path) -> None:
|
||||
pnpm_prefix = shared_lib / "pnpm" / "packages" / "chrome"
|
||||
node_modules = pnpm_prefix / "node_modules"
|
||||
puppeteer_dir = node_modules / "puppeteer"
|
||||
if puppeteer_dir.exists():
|
||||
return
|
||||
pnpm_prefix.mkdir(parents=True, exist_ok=True)
|
||||
env = os.environ.copy()
|
||||
env["PUPPETEER_SKIP_DOWNLOAD"] = "1"
|
||||
subprocess.run(
|
||||
["pnpm", "add", "--dir", str(pnpm_prefix), "puppeteer"],
|
||||
cwd=str(pnpm_prefix),
|
||||
env=env,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=600,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
def real_archive_with_example(tmp_path_factory, request):
|
||||
"""
|
||||
|
||||
@ -106,9 +106,9 @@ def test_cli_env_does_not_emit_relative_pythonpath_entries():
|
||||
os.environ["PYTHONPATH"] = old_pythonpath
|
||||
|
||||
pythonpath_entries = env["PYTHONPATH"].split(os.pathsep)
|
||||
assert str((WORKSPACE_ROOT / "abxpkg").resolve(strict=False)) in pythonpath_entries
|
||||
assert str((WORKSPACE_ROOT / "abx-plugins").resolve(strict=False)) in pythonpath_entries
|
||||
assert str((WORKSPACE_ROOT / "abx-dl").resolve(strict=False)) in pythonpath_entries
|
||||
for repo_name in ("abxpkg", "abx-plugins", "abx-dl"):
|
||||
repo_path = next(path for path in (WORKSPACE_ROOT / repo_name, REPO_ROOT / repo_name) if path.exists())
|
||||
assert str(repo_path.resolve(strict=False)) in pythonpath_entries
|
||||
assert all(Path(entry).is_absolute() for entry in pythonpath_entries)
|
||||
assert not any(entry.startswith("..") for entry in pythonpath_entries)
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ from urllib.parse import urlencode
|
||||
|
||||
import pytest
|
||||
|
||||
from .conftest import _ensure_puppeteer, _find_cached_chrome, _find_system_browser, run_python_cwd
|
||||
from .conftest import _find_cached_chrome, _find_system_browser, run_python_cwd
|
||||
from .conftest import (
|
||||
cli_env,
|
||||
get_free_port,
|
||||
@ -289,13 +289,28 @@ def _resolve_browser(shared_lib: Path) -> Path | None:
|
||||
return None
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def browser_runtime(tmp_path_factory):
|
||||
@pytest.fixture
|
||||
def browser_runtime(initialized_archive: Path):
|
||||
assert shutil.which("node") is not None, "Node.js is required for browser security tests"
|
||||
assert shutil.which("pnpm") is not None, "pnpm is required for browser security tests"
|
||||
|
||||
shared_lib = tmp_path_factory.mktemp("archivebox_browser_lib")
|
||||
_ensure_puppeteer(shared_lib)
|
||||
shared_lib = initialized_archive / "lib"
|
||||
env = cli_env(
|
||||
ABXPKG_INSTALL_TIMEOUT="900",
|
||||
ABXPKG_MIN_RELEASE_AGE="0",
|
||||
LIB_DIR=str(shared_lib),
|
||||
ABXPKG_LIB_DIR=str(shared_lib),
|
||||
CHROME_HEADLESS="True",
|
||||
CHROME_SANDBOX="False",
|
||||
CHROME_ISOLATION="snapshot",
|
||||
)
|
||||
env.pop("CHROME_BINARY", None)
|
||||
install_result = run_archivebox_cmd(
|
||||
["install", "chrome"],
|
||||
cwd=initialized_archive,
|
||||
env=env,
|
||||
timeout=900,
|
||||
)
|
||||
assert install_result.returncode == 0, install_result.stderr or install_result.stdout
|
||||
|
||||
browser = _resolve_browser(shared_lib)
|
||||
assert browser, "No Chrome/Chromium binary available for browser security tests"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user