mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-08-12 11:49:53 +00:00
feat: get rid of sudoers modification during setup command
This commit introduces small shell wrapper, which calls archbuild mimicing symlinked command. It allows to distribute static sudoers file. Additionally build_command option has been renamed to devtools_wrapper in order to allow to keep backward compatibility
This commit is contained in:
@@ -55,8 +55,6 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
||||
ahriman_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_ahriman")
|
||||
devtools_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_devtools")
|
||||
makepkg_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_makepkg")
|
||||
sudo_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_sudo")
|
||||
executable_mock = mocker.patch("ahriman.application.handlers.setup.Setup.executable_create")
|
||||
init_mock = mocker.patch("ahriman.core.alpm.repo.Repo.init")
|
||||
owner_guard_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.preserve_owner")
|
||||
|
||||
@@ -67,8 +65,6 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
||||
devtools_configuration_mock.assert_called_once_with(
|
||||
repository_id, args.from_configuration, args.mirror, args.multilib, f"file://{repository_paths.repository}")
|
||||
makepkg_configuration_mock.assert_called_once_with(args.packager, args.makeflags_jobs, repository_paths)
|
||||
sudo_configuration_mock.assert_called_once_with(repository_paths, repository_id)
|
||||
executable_mock.assert_called_once_with(repository_paths, repository_id)
|
||||
init_mock.assert_called_once_with()
|
||||
|
||||
|
||||
@@ -102,8 +98,6 @@ def test_run_with_server(args: argparse.Namespace, configuration: Configuration,
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_ahriman")
|
||||
mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_makepkg")
|
||||
mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_sudo")
|
||||
mocker.patch("ahriman.application.handlers.setup.Setup.executable_create")
|
||||
mocker.patch("ahriman.core.alpm.repo.Repo.init")
|
||||
devtools_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_devtools")
|
||||
|
||||
@@ -113,17 +107,6 @@ def test_run_with_server(args: argparse.Namespace, configuration: Configuration,
|
||||
repository_id, args.from_configuration, args.mirror, args.multilib, "server")
|
||||
|
||||
|
||||
def test_build_command(repository_id: RepositoryId) -> None:
|
||||
"""
|
||||
must generate correct build command name
|
||||
"""
|
||||
path = Path("local")
|
||||
|
||||
build_command = Setup.build_command(path, repository_id)
|
||||
assert build_command.name == f"{repository_id.name}-{repository_id.architecture}-build"
|
||||
assert build_command.parent == path
|
||||
|
||||
|
||||
def test_configuration_create_ahriman(args: argparse.Namespace, configuration: Configuration,
|
||||
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
@@ -135,12 +118,9 @@ def test_configuration_create_ahriman(args: argparse.Namespace, configuration: C
|
||||
write_mock = mocker.patch("ahriman.core.configuration.Configuration.write")
|
||||
remove_mock = mocker.patch("pathlib.Path.unlink", autospec=True)
|
||||
_, repository_id = configuration.check_loaded()
|
||||
command = Setup.build_command(repository_paths.root, repository_id)
|
||||
|
||||
Setup.configuration_create_ahriman(args, repository_id, configuration)
|
||||
set_option_mock.assert_has_calls([
|
||||
MockCall(Configuration.section_name("build", repository_id.name, repository_id.architecture), "build_command",
|
||||
str(command)),
|
||||
MockCall("repository", "name", repository_id.name),
|
||||
MockCall(Configuration.section_name("build", repository_id.name, repository_id.architecture),
|
||||
"makechrootpkg_flags", f"-U {args.build_as_user}"),
|
||||
@@ -251,34 +231,6 @@ def test_configuration_create_makepkg(args: argparse.Namespace, repository_paths
|
||||
Path("home") / ".makepkg.conf", pytest.helpers.anyvar(str, True), encoding="utf8")
|
||||
|
||||
|
||||
def test_configuration_create_sudo(configuration: Configuration, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create sudo configuration
|
||||
"""
|
||||
chmod_text_mock = mocker.patch("pathlib.Path.chmod")
|
||||
write_text_mock = mocker.patch("pathlib.Path.write_text")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Setup.configuration_create_sudo(repository_paths, repository_id)
|
||||
chmod_text_mock.assert_called_once_with(0o400)
|
||||
write_text_mock.assert_called_once_with(pytest.helpers.anyvar(str, True), encoding="utf8")
|
||||
|
||||
|
||||
def test_executable_create(configuration: Configuration, repository_paths: RepositoryPaths,
|
||||
mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must create executable
|
||||
"""
|
||||
symlink_mock = mocker.patch("pathlib.Path.symlink_to")
|
||||
unlink_mock = mocker.patch("pathlib.Path.unlink")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Setup.executable_create(repository_paths, repository_id)
|
||||
symlink_mock.assert_called_once_with(Setup.ARCHBUILD_COMMAND_PATH)
|
||||
unlink_mock.assert_called_once_with(missing_ok=True)
|
||||
|
||||
|
||||
def test_disallow_multi_architecture_run() -> None:
|
||||
"""
|
||||
must not allow multi architecture run
|
||||
|
||||
@@ -63,7 +63,7 @@ def test_run_default(args: argparse.Namespace, configuration: Configuration) ->
|
||||
|
||||
default = Configuration.from_path(Configuration.SYSTEM_CONFIGURATION_PATH, repository_id)
|
||||
# copy autogenerated values
|
||||
for section, key in (("build", "build_command"), ("repository", "root")):
|
||||
for section, key in (("repository", "root"),):
|
||||
value = configuration.get(section, key)
|
||||
default.set_option(section, key, value)
|
||||
|
||||
|
||||
@@ -53,8 +53,9 @@ def test_build(task_ahriman: Task, mocker: MockerFixture) -> None:
|
||||
|
||||
assert task_ahriman.build(local) == [task_ahriman.package.base]
|
||||
check_output_mock.assert_called_once_with(
|
||||
"extra-x86_64-build",
|
||||
"-r", str(task_ahriman.paths.chroot),
|
||||
"ahriman-archbuild",
|
||||
"-r", task_ahriman.repository_id.name, "-a", task_ahriman.repository_id.architecture,
|
||||
"--", "-r", str(task_ahriman.paths.chroot),
|
||||
"--", "-D", str(task_ahriman.paths.archive),
|
||||
"--", "--skippgpcheck",
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
@@ -79,8 +80,9 @@ def test_build_environment(task_ahriman: Task, mocker: MockerFixture) -> None:
|
||||
|
||||
task_ahriman.build(local, **environment, empty=None)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"extra-x86_64-build",
|
||||
"-r", str(task_ahriman.paths.chroot),
|
||||
"ahriman-archbuild",
|
||||
"-r", task_ahriman.repository_id.name, "-a", task_ahriman.repository_id.architecture,
|
||||
"--", "-r", str(task_ahriman.paths.chroot),
|
||||
"--", "-D", str(task_ahriman.paths.archive),
|
||||
"--", "--skippgpcheck",
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
@@ -101,12 +103,37 @@ def test_build_dry_run(task_ahriman: Task, mocker: MockerFixture) -> None:
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.task.check_output")
|
||||
|
||||
assert task_ahriman.build(local, dry_run=True) == [task_ahriman.package.base]
|
||||
check_output_mock.assert_called_once_with(
|
||||
"ahriman-archbuild",
|
||||
"-r", task_ahriman.repository_id.name, "-a", task_ahriman.repository_id.architecture,
|
||||
"--", "-r", str(task_ahriman.paths.chroot),
|
||||
"--", "-D", str(task_ahriman.paths.archive),
|
||||
"--", "--skippgpcheck",
|
||||
"--nobuild",
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
cwd=local,
|
||||
logger=task_ahriman.logger,
|
||||
user=task_ahriman.uid,
|
||||
environment={},
|
||||
)
|
||||
|
||||
|
||||
def test_build_legacy_subcommand(task_ahriman: Task, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must build package by using legacy subcommand if set
|
||||
"""
|
||||
local = Path("local")
|
||||
mocker.patch("pathlib.Path.iterdir", return_value=["file"])
|
||||
mocker.patch("ahriman.core.build_tools.task.Task._package_archives", return_value=[task_ahriman.package.base])
|
||||
check_output_mock = mocker.patch("ahriman.core.build_tools.task.check_output")
|
||||
task_ahriman._legacy_build_command = ["extra-x86_64-build"]
|
||||
|
||||
task_ahriman.build(local)
|
||||
check_output_mock.assert_called_once_with(
|
||||
"extra-x86_64-build",
|
||||
"-r", str(task_ahriman.paths.chroot),
|
||||
"--", "-D", str(task_ahriman.paths.archive),
|
||||
"--", "--skippgpcheck",
|
||||
"--nobuild",
|
||||
exception=pytest.helpers.anyvar(int),
|
||||
cwd=local,
|
||||
logger=task_ahriman.logger,
|
||||
|
||||
@@ -76,4 +76,5 @@ def task_ahriman(package_ahriman: Package, configuration: Configuration, reposit
|
||||
Returns:
|
||||
Task: built task test instance
|
||||
"""
|
||||
return Task(package_ahriman, configuration, "x86_64", repository_paths)
|
||||
_, repository_id = configuration.check_loaded()
|
||||
return Task(package_ahriman, configuration, repository_id, repository_paths)
|
||||
|
||||
Reference in New Issue
Block a user