mirror of
https://github.com/d9pouces/id_configurator.git
synced 2026-11-09 01:47:21 +01:00
feat: can specify several users to configure
Signed-off-by: d9pouces <github@19pouces.net>
This commit is contained in:
@@ -15,6 +15,12 @@ CONFIG_WITH_CERT = {
|
||||
**MINIMAL_CONFIG,
|
||||
"configurations": {"certificates": [{"name": "my-ca", "content": "fake"}]},
|
||||
}
|
||||
CONFIG_WITH_GO_REPO = {
|
||||
**MINIMAL_CONFIG,
|
||||
"configurations": {
|
||||
"go": {"repositories": [{"name": "demo", "url": "https://example.invalid/"}]}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def write_config(tmp_path, data) -> str:
|
||||
@@ -129,6 +135,66 @@ def test_apply_runs_relevant_module(tmp_path) -> None:
|
||||
assert (dst / "etc/ssl/certs/ca-certificates.crt").read_bytes() == b"fake\n"
|
||||
|
||||
|
||||
def test_apply_with_user_option_writes_per_user_config(tmp_path) -> None:
|
||||
config_path = write_config(tmp_path, CONFIG_WITH_GO_REPO)
|
||||
dst = tmp_path / "dst"
|
||||
result = runner.invoke(
|
||||
cli.app,
|
||||
[
|
||||
"apply",
|
||||
"--config",
|
||||
config_path,
|
||||
"--dst",
|
||||
str(dst),
|
||||
"--user",
|
||||
"alice",
|
||||
"--user",
|
||||
"root",
|
||||
],
|
||||
)
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert (dst / "home/alice/.config/go/env").read_text(encoding="utf-8") == (
|
||||
"GOPROXY=https://example.invalid/\nGOSUMDB=off\n"
|
||||
)
|
||||
assert (dst / "root/.config/go/env").read_text(encoding="utf-8") == (
|
||||
"GOPROXY=https://example.invalid/\nGOSUMDB=off\n"
|
||||
)
|
||||
|
||||
|
||||
def test_apply_with_auto_users_reads_passwd_from_src(tmp_path) -> None:
|
||||
config_path = write_config(tmp_path, CONFIG_WITH_GO_REPO)
|
||||
src = tmp_path / "src"
|
||||
(src / "etc").mkdir(parents=True)
|
||||
(src / "etc/passwd").write_text(
|
||||
"root:x:0:0:root:/root:/bin/bash\n"
|
||||
"alice:x:1000:1000:Alice:/home/alice:/bin/bash\n"
|
||||
"daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
dst = tmp_path / "dst"
|
||||
result = runner.invoke(
|
||||
cli.app,
|
||||
[
|
||||
"apply",
|
||||
"--config",
|
||||
config_path,
|
||||
"--dst",
|
||||
str(dst),
|
||||
"--src",
|
||||
str(src),
|
||||
"--auto-users",
|
||||
],
|
||||
)
|
||||
|
||||
assert result.exit_code == 0
|
||||
# root is always included despite its uid 0; daemon (nologin shell) is
|
||||
# a system account, excluded.
|
||||
assert (dst / "root/.config/go/env").exists()
|
||||
assert (dst / "home/alice/.config/go/env").exists()
|
||||
assert not (dst / "usr/sbin/.config/go/env").exists()
|
||||
|
||||
|
||||
def test_main_default_name_calls_app(monkeypatch) -> None:
|
||||
mock_app = MagicMock()
|
||||
monkeypatch.setattr(cli, "app", mock_app)
|
||||
|
||||
Reference in New Issue
Block a user