tests: add fake_sudo to sshd fixture

This allows to use the same code for both testing and real-world.
This commit is contained in:
Jörg Thalheim
2025-03-28 17:46:44 +01:00
parent 2406a62ce0
commit eaf20ae09a
3 changed files with 14 additions and 9 deletions

View File

@@ -63,7 +63,7 @@ def upload(
tar.addfile(tarinfo, f)
sudo = ""
if host.user != "root" and os.environ.get("IN_PYTEST") is None:
if host.user != "root":
sudo = "sudo -- "
cmd = "rm -rf $0 && mkdir -m $1 -p $0 && tar -C $0 -xzf -"

View File

@@ -147,7 +147,6 @@ pythonRuntime.pkgs.buildPythonApplication {
cd ./src
export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1 PYTHONWARNINGS=error
export IN_PYTEST=1
# required to prevent concurrent 'nix flake lock' operations
export CLAN_TEST_STORE=$TMPDIR/store
@@ -199,7 +198,6 @@ pythonRuntime.pkgs.buildPythonApplication {
export NIX_STATE_DIR=$TMPDIR/nix
export IN_NIX_SANDBOX=1
export PYTHONWARNINGS=error
export IN_PYTEST=1
export CLAN_TEST_STORE=$TMPDIR/store
# required to prevent concurrent 'nix flake lock' operations
export LOCK_NIX=$TMPDIR/nix_lock

View File

@@ -57,7 +57,10 @@ def sshd_config(test_root: Path) -> Iterator[SshdConfig]:
)
config = tmpdir / "sshd_config"
config.write_text(content)
login_shell = tmpdir / "shell"
bin_path = tmpdir / "bin"
login_shell = bin_path / "shell"
fake_sudo = bin_path / "sudo"
login_shell.parent.mkdir(parents=True)
bash = shutil.which("bash")
path = os.environ["PATH"]
@@ -65,19 +68,23 @@ def sshd_config(test_root: Path) -> Iterator[SshdConfig]:
login_shell.write_text(
f"""#!{bash}
set -x
if [[ -f /etc/profile ]]; then
source /etc/profile
fi
if [[ -n "$REALPATH" ]]; then
export PATH="$REALPATH:${path}"
else
export PATH="${path}"
fi
export PATH="{bin_path}:{path}"
exec {bash} -l "${{@}}"
"""
)
login_shell.chmod(0o755)
fake_sudo.write_text(
f"""#!{bash}
exec "${{@}}"
"""
)
fake_sudo.chmod(0o755)
lib_path = None
extension = ".so"