From 44ad224ecccf6487b7dff4830588ec436ce46be2 Mon Sep 17 00:00:00 2001 From: "nekomimi.pet" Date: Sun, 25 Oct 2026 19:30:29 -0400 Subject: [PATCH] ssh: the login-shell wrapper writes its script under $TMPDIR, so its leak test checks a directory of its own instead of the shared /tmp --- priv/python/albedo_ssh.py | 2 +- test/harness/ssh_login_shell_test.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/priv/python/albedo_ssh.py b/priv/python/albedo_ssh.py index 62f7b9514..6caaf005b 100644 --- a/priv/python/albedo_ssh.py +++ b/priv/python/albedo_ssh.py @@ -184,7 +184,7 @@ def in_login_shell(script: str) -> str: # whose command line still holds it. login = f'rm -f "$0"; exec 1>&3 2>&4 3>&- 4>&-; {script}' outer = ( - "f=$(mktemp /tmp/albedo-remote-XXXXXX 2>/dev/null) || exit 1\n" + 'f=$(mktemp "${TMPDIR:-/tmp}/albedo-remote-XXXXXX" 2>/dev/null) || exit 1\n' "trap 'rm -f -- \"$f\"' EXIT HUP INT TERM\n" "cat > \"$f\" <<'ALBEDO-REMOTE' || exit 1\n" f"{login}\n" diff --git a/test/harness/ssh_login_shell_test.py b/test/harness/ssh_login_shell_test.py index 174578cad..8411bd831 100644 --- a/test/harness/ssh_login_shell_test.py +++ b/test/harness/ssh_login_shell_test.py @@ -31,13 +31,13 @@ def stand_in_shell(directory: Path, *, motd: str = "") -> str: class LoginShellTest(unittest.TestCase): - def run_command(self, shell, command): + def run_command(self, shell, command, **env): return subprocess.run( ["/bin/sh", "-c", command], input="from-stdin\n", text=True, capture_output=True, - env={**os.environ, "SHELL": shell}, + env={**os.environ, "SHELL": shell, **env}, timeout=30, ) @@ -56,10 +56,13 @@ class LoginShellTest(unittest.TestCase): self.assertEqual(done.stderr, "to-stderr\n") def test_the_script_leaves_no_temporary_file(self): - command = albedo_ssh.in_login_shell("true") - before = set(Path("/tmp").glob("albedo-remote-*")) - self.run_command("/bin/sh", command) - self.assertEqual(set(Path("/tmp").glob("albedo-remote-*")), before) + # A directory of its own: other suites run these scripts in /tmp too. + with tempfile.TemporaryDirectory() as scratch: + done = self.run_command( + "/bin/sh", albedo_ssh.in_login_shell("true"), TMPDIR=scratch + ) + self.assertEqual(done.returncode, 0, done.stderr) + self.assertEqual(list(Path(scratch).iterdir()), []) if __name__ == "__main__": -- knotmirror 0.0.1