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:
@@ -63,7 +63,7 @@ def upload(
|
|||||||
tar.addfile(tarinfo, f)
|
tar.addfile(tarinfo, f)
|
||||||
|
|
||||||
sudo = ""
|
sudo = ""
|
||||||
if host.user != "root" and os.environ.get("IN_PYTEST") is None:
|
if host.user != "root":
|
||||||
sudo = "sudo -- "
|
sudo = "sudo -- "
|
||||||
|
|
||||||
cmd = "rm -rf $0 && mkdir -m $1 -p $0 && tar -C $0 -xzf -"
|
cmd = "rm -rf $0 && mkdir -m $1 -p $0 && tar -C $0 -xzf -"
|
||||||
|
|||||||
@@ -147,7 +147,6 @@ pythonRuntime.pkgs.buildPythonApplication {
|
|||||||
cd ./src
|
cd ./src
|
||||||
|
|
||||||
export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1 PYTHONWARNINGS=error
|
export NIX_STATE_DIR=$TMPDIR/nix IN_NIX_SANDBOX=1 PYTHONWARNINGS=error
|
||||||
export IN_PYTEST=1
|
|
||||||
|
|
||||||
# required to prevent concurrent 'nix flake lock' operations
|
# required to prevent concurrent 'nix flake lock' operations
|
||||||
export CLAN_TEST_STORE=$TMPDIR/store
|
export CLAN_TEST_STORE=$TMPDIR/store
|
||||||
@@ -199,7 +198,6 @@ pythonRuntime.pkgs.buildPythonApplication {
|
|||||||
export NIX_STATE_DIR=$TMPDIR/nix
|
export NIX_STATE_DIR=$TMPDIR/nix
|
||||||
export IN_NIX_SANDBOX=1
|
export IN_NIX_SANDBOX=1
|
||||||
export PYTHONWARNINGS=error
|
export PYTHONWARNINGS=error
|
||||||
export IN_PYTEST=1
|
|
||||||
export CLAN_TEST_STORE=$TMPDIR/store
|
export CLAN_TEST_STORE=$TMPDIR/store
|
||||||
# required to prevent concurrent 'nix flake lock' operations
|
# required to prevent concurrent 'nix flake lock' operations
|
||||||
export LOCK_NIX=$TMPDIR/nix_lock
|
export LOCK_NIX=$TMPDIR/nix_lock
|
||||||
|
|||||||
@@ -57,7 +57,10 @@ def sshd_config(test_root: Path) -> Iterator[SshdConfig]:
|
|||||||
)
|
)
|
||||||
config = tmpdir / "sshd_config"
|
config = tmpdir / "sshd_config"
|
||||||
config.write_text(content)
|
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")
|
bash = shutil.which("bash")
|
||||||
path = os.environ["PATH"]
|
path = os.environ["PATH"]
|
||||||
@@ -65,19 +68,23 @@ def sshd_config(test_root: Path) -> Iterator[SshdConfig]:
|
|||||||
|
|
||||||
login_shell.write_text(
|
login_shell.write_text(
|
||||||
f"""#!{bash}
|
f"""#!{bash}
|
||||||
|
set -x
|
||||||
if [[ -f /etc/profile ]]; then
|
if [[ -f /etc/profile ]]; then
|
||||||
source /etc/profile
|
source /etc/profile
|
||||||
fi
|
fi
|
||||||
if [[ -n "$REALPATH" ]]; then
|
export PATH="{bin_path}:{path}"
|
||||||
export PATH="$REALPATH:${path}"
|
|
||||||
else
|
|
||||||
export PATH="${path}"
|
|
||||||
fi
|
|
||||||
exec {bash} -l "${{@}}"
|
exec {bash} -l "${{@}}"
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
login_shell.chmod(0o755)
|
login_shell.chmod(0o755)
|
||||||
|
|
||||||
|
fake_sudo.write_text(
|
||||||
|
f"""#!{bash}
|
||||||
|
exec "${{@}}"
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
fake_sudo.chmod(0o755)
|
||||||
|
|
||||||
lib_path = None
|
lib_path = None
|
||||||
|
|
||||||
extension = ".so"
|
extension = ".so"
|
||||||
|
|||||||
Reference in New Issue
Block a user