clan-cli: add update command
This commit is contained in:
@@ -5,7 +5,7 @@ import time
|
||||
from pathlib import Path
|
||||
from sys import platform
|
||||
from tempfile import TemporaryDirectory
|
||||
from typing import TYPE_CHECKING, Iterator, Optional
|
||||
from typing import TYPE_CHECKING, Iterator
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -22,8 +22,11 @@ class Sshd:
|
||||
|
||||
|
||||
class SshdConfig:
|
||||
def __init__(self, path: str, key: str, preload_lib: Optional[str]) -> None:
|
||||
def __init__(
|
||||
self, path: Path, login_shell: Path, key: str, preload_lib: Path
|
||||
) -> None:
|
||||
self.path = path
|
||||
self.login_shell = login_shell
|
||||
self.key = key
|
||||
self.preload_lib = preload_lib
|
||||
|
||||
@@ -53,28 +56,51 @@ def sshd_config(project_root: Path, test_root: Path) -> Iterator[SshdConfig]:
|
||||
HostKey {host_key}
|
||||
LogLevel DEBUG3
|
||||
# In the nix build sandbox we don't get any meaningful PATH after login
|
||||
SetEnv PATH={os.environ.get("PATH", "")}
|
||||
MaxStartups 64:30:256
|
||||
AuthorizedKeysFile {host_key}.pub
|
||||
AcceptEnv REALPATH
|
||||
"""
|
||||
)
|
||||
login_shell = dir / "shell"
|
||||
|
||||
bash = shutil.which("bash")
|
||||
path = os.environ["PATH"]
|
||||
assert bash is not None
|
||||
|
||||
login_shell.write_text(
|
||||
f"""#!{bash}
|
||||
if [[ -f /etc/profile ]]; then
|
||||
source /etc/profile
|
||||
fi
|
||||
if [[ -n "$REALPATH" ]]; then
|
||||
export PATH="$REALPATH:${path}"
|
||||
else
|
||||
export PATH="${path}"
|
||||
fi
|
||||
exec {bash} -l "${{@}}"
|
||||
"""
|
||||
)
|
||||
login_shell.chmod(0o755)
|
||||
|
||||
lib_path = None
|
||||
if platform == "linux":
|
||||
# This enforces a login shell by overriding the login shell of `getpwnam(3)`
|
||||
lib_path = str(dir / "libgetpwnam-preload.so")
|
||||
subprocess.run(
|
||||
[
|
||||
os.environ.get("CC", "cc"),
|
||||
"-shared",
|
||||
"-o",
|
||||
lib_path,
|
||||
str(test_root / "getpwnam-preload.c"),
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
assert (
|
||||
platform == "linux"
|
||||
), "we do not support the ld_preload trick on non-linux just now"
|
||||
|
||||
yield SshdConfig(str(sshd_config), str(host_key), lib_path)
|
||||
# This enforces a login shell by overriding the login shell of `getpwnam(3)`
|
||||
lib_path = dir / "libgetpwnam-preload.so"
|
||||
subprocess.run(
|
||||
[
|
||||
os.environ.get("CC", "cc"),
|
||||
"-shared",
|
||||
"-o",
|
||||
lib_path,
|
||||
str(test_root / "getpwnam-preload.c"),
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
|
||||
yield SshdConfig(sshd_config, login_shell, str(host_key), lib_path)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -83,12 +109,12 @@ def sshd(sshd_config: SshdConfig, command: "Command", ports: "Ports") -> Iterato
|
||||
sshd = shutil.which("sshd")
|
||||
assert sshd is not None, "no sshd binary found"
|
||||
env = {}
|
||||
if sshd_config.preload_lib is not None:
|
||||
bash = shutil.which("bash")
|
||||
assert bash is not None
|
||||
env = dict(LD_PRELOAD=str(sshd_config.preload_lib), LOGIN_SHELL=bash)
|
||||
env = dict(
|
||||
LD_PRELOAD=str(sshd_config.preload_lib),
|
||||
LOGIN_SHELL=str(sshd_config.login_shell),
|
||||
)
|
||||
proc = command.run(
|
||||
[sshd, "-f", sshd_config.path, "-D", "-p", str(port)], extra_env=env
|
||||
[sshd, "-f", str(sshd_config.path), "-D", "-p", str(port)], extra_env=env
|
||||
)
|
||||
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user