From de740cf686ff119c79388f0f7873d5b2c97bb5ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 28 Mar 2025 17:46:44 +0100 Subject: [PATCH] tests: add fake_sudo to sshd fixture This allows to use the same code for both testing and real-world. --- pkgs/clan-cli/clan_cli/ssh/upload.py | 2 +- pkgs/clan-cli/default.nix | 2 -- pkgs/clan-cli/tests/sshd.py | 19 +++++++++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/ssh/upload.py b/pkgs/clan-cli/clan_cli/ssh/upload.py index ec22df73f..8fd798677 100644 --- a/pkgs/clan-cli/clan_cli/ssh/upload.py +++ b/pkgs/clan-cli/clan_cli/ssh/upload.py @@ -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 -" diff --git a/pkgs/clan-cli/default.nix b/pkgs/clan-cli/default.nix index 101f872aa..a3214cb2d 100644 --- a/pkgs/clan-cli/default.nix +++ b/pkgs/clan-cli/default.nix @@ -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 diff --git a/pkgs/clan-cli/tests/sshd.py b/pkgs/clan-cli/tests/sshd.py index 82c9c1251..9245dd96b 100644 --- a/pkgs/clan-cli/tests/sshd.py +++ b/pkgs/clan-cli/tests/sshd.py @@ -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"