mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-06-28 06:41:43 +00:00
feat: add blacklisted paths to implicit dependencies processing
It has been found that in some cases additional packages have been added as dependencies, like usr/share/applications, usr/lib/cmake, etc This commit adds an ability to blacklist specific paths from processing
This commit is contained in:
@ -7,6 +7,7 @@ from pytest_mock import MockerFixture
|
||||
from ahriman import __version__
|
||||
from ahriman.core.alpm.pacman import Pacman
|
||||
from ahriman.core.alpm.remote import AUR
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.models.build_status import BuildStatus, BuildStatusEnum
|
||||
from ahriman.models.counters import Counters
|
||||
from ahriman.models.filesystem_package import FilesystemPackage
|
||||
@ -17,6 +18,7 @@ from ahriman.models.package_description import PackageDescription
|
||||
from ahriman.models.package_source import PackageSource
|
||||
from ahriman.models.remote_source import RemoteSource
|
||||
from ahriman.models.repository_paths import RepositoryPaths
|
||||
from ahriman.models.scan_paths import ScanPaths
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -77,7 +79,7 @@ def internal_status(counters: Counters) -> InternalStatus:
|
||||
|
||||
@pytest.fixture
|
||||
def package_archive_ahriman(package_ahriman: Package, repository_paths: RepositoryPaths, pacman: Pacman,
|
||||
passwd: Any, mocker: MockerFixture) -> PackageArchive:
|
||||
scan_paths: ScanPaths, passwd: Any, mocker: MockerFixture) -> PackageArchive:
|
||||
"""
|
||||
package archive fixture
|
||||
|
||||
@ -85,6 +87,7 @@ def package_archive_ahriman(package_ahriman: Package, repository_paths: Reposito
|
||||
package_ahriman(Package): package test instance
|
||||
repository_paths(RepositoryPaths): repository paths test instance
|
||||
pacman(Pacman): pacman test instance
|
||||
scan_paths(ScanPaths): scan paths test instance
|
||||
passwd(Any): passwd structure test instance
|
||||
mocker(MockerFixture): mocker object
|
||||
|
||||
@ -92,7 +95,7 @@ def package_archive_ahriman(package_ahriman: Package, repository_paths: Reposito
|
||||
PackageArchive: package archive test instance
|
||||
"""
|
||||
mocker.patch("ahriman.models.repository_paths.getpwuid", return_value=passwd)
|
||||
return PackageArchive(repository_paths.build_directory, package_ahriman, pacman)
|
||||
return PackageArchive(repository_paths.build_directory, package_ahriman, pacman, scan_paths)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -158,3 +161,20 @@ def pyalpm_package_description_ahriman(package_description_ahriman: PackageDescr
|
||||
type(mock).provides = PropertyMock(return_value=package_description_ahriman.provides)
|
||||
type(mock).url = PropertyMock(return_value=package_description_ahriman.url)
|
||||
return mock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def scan_paths(configuration: Configuration) -> ScanPaths:
|
||||
"""
|
||||
scan paths fixture
|
||||
|
||||
Args:
|
||||
configuration(Configuration): configuration test instance
|
||||
|
||||
Returns:
|
||||
ScanPaths: scan paths test instance
|
||||
"""
|
||||
return ScanPaths(
|
||||
allowed_paths=configuration.getpathlist("build", "allowed_scan_paths"),
|
||||
blacklisted_paths=configuration.getpathlist("build", "blacklisted_scan_paths"),
|
||||
)
|
||||
|
@ -134,8 +134,10 @@ def test_refine_dependencies(package_archive_ahriman: PackageArchive, mocker: Mo
|
||||
|
||||
path1 = Path("usr") / "lib" / "python3.12"
|
||||
path2 = path1 / "site-packages"
|
||||
path3 = Path("etc")
|
||||
path4 = Path("var") / "lib" / "whatever"
|
||||
path3 = Path("usr") / "lib" / "path"
|
||||
path4 = Path("usr") / "lib" / "whatever"
|
||||
path5 = Path("usr") / "share" / "applications"
|
||||
path6 = Path("etc")
|
||||
|
||||
package1 = FilesystemPackage(package_name="package1", depends={"package5"}, opt_depends={"package2"})
|
||||
package2 = FilesystemPackage(package_name="package2", depends={"package1"}, opt_depends=set())
|
||||
@ -149,6 +151,8 @@ def test_refine_dependencies(package_archive_ahriman: PackageArchive, mocker: Mo
|
||||
path2: [package1, package2, package3, package5],
|
||||
path3: [package1, package4],
|
||||
path4: [package1],
|
||||
path5: [package1],
|
||||
path6: [package1],
|
||||
}) == {
|
||||
path1: [package6],
|
||||
path2: [package1, package5],
|
||||
|
42
tests/ahriman/models/test_scan_paths.py
Normal file
42
tests/ahriman/models/test_scan_paths.py
Normal file
@ -0,0 +1,42 @@
|
||||
from pathlib import Path
|
||||
|
||||
from ahriman.models.scan_paths import ScanPaths
|
||||
|
||||
|
||||
def test_post_init(scan_paths: ScanPaths) -> None:
|
||||
"""
|
||||
must convert paths to / relative
|
||||
"""
|
||||
assert all(not path.is_absolute() for path in scan_paths.allowed_paths)
|
||||
assert all(not path.is_absolute() for path in scan_paths.blacklisted_paths)
|
||||
|
||||
|
||||
def test_is_allowed() -> None:
|
||||
"""
|
||||
must check if path is subpath of one in allowed list
|
||||
"""
|
||||
assert ScanPaths(allowed_paths=[Path("/") / "usr"], blacklisted_paths=[]).is_allowed(Path("usr"))
|
||||
assert ScanPaths(allowed_paths=[Path("/") / "usr"], blacklisted_paths=[]).is_allowed(Path("usr") / "lib")
|
||||
assert not ScanPaths(allowed_paths=[Path("/") / "usr"], blacklisted_paths=[]).is_allowed(Path("var"))
|
||||
|
||||
|
||||
def test_is_blacklisted() -> None:
|
||||
"""
|
||||
must check if path is not subpath of one in blacklist
|
||||
"""
|
||||
assert ScanPaths(
|
||||
allowed_paths=[Path("/") / "usr"],
|
||||
blacklisted_paths=[Path("/") / "usr" / "lib"],
|
||||
).is_allowed(Path("usr"))
|
||||
assert ScanPaths(
|
||||
allowed_paths=[Path("/") / "usr", Path("/") / "var"],
|
||||
blacklisted_paths=[Path("/") / "usr" / "lib"],
|
||||
).is_allowed(Path("var"))
|
||||
assert not ScanPaths(
|
||||
allowed_paths=[Path("/") / "usr"],
|
||||
blacklisted_paths=[Path("/") / "usr" / "lib"],
|
||||
).is_allowed(Path(" usr") / "lib")
|
||||
assert not ScanPaths(
|
||||
allowed_paths=[Path("/") / "usr"],
|
||||
blacklisted_paths=[Path("/") / "usr" / "lib"],
|
||||
).is_allowed(Path("usr") / "lib" / "qt")
|
@ -20,7 +20,9 @@ salt = salt
|
||||
allow_read_only = no
|
||||
|
||||
[build]
|
||||
allowed_scan_paths = /usr/lib
|
||||
archbuild_flags =
|
||||
blacklisted_scan_paths = /usr/lib/cmake
|
||||
build_command = extra-x86_64-build
|
||||
ignore_packages =
|
||||
makechrootpkg_flags =
|
||||
|
Reference in New Issue
Block a user