test(terminal): cover sudo cache invalidation and multi-invocation piping
This commit is contained in:
parent
8278d82e17
commit
d93abd75d1
1 changed files with 56 additions and 0 deletions
|
|
@ -243,3 +243,59 @@ def test_get_env_config_still_rejects_bad_docker_json_for_docker_backend(monkeyp
|
|||
assert "TERMINAL_DOCKER_VOLUMES" in str(exc)
|
||||
else:
|
||||
raise AssertionError("Docker backend must validate TERMINAL_DOCKER_VOLUMES")
|
||||
|
||||
|
||||
def test_sudo_wrong_password_failure_detects_rejection_output():
|
||||
output = (
|
||||
"sudo: Authentication failed, try again.\n\n"
|
||||
"sudo: maximum 3 incorrect authentication attempts\n"
|
||||
)
|
||||
assert terminal_tool._sudo_wrong_password_failure(output) is True
|
||||
|
||||
|
||||
def test_sudo_wrong_password_failure_ignores_tty_required_message():
|
||||
output = "sudo: a terminal is required to authenticate"
|
||||
assert terminal_tool._sudo_wrong_password_failure(output) is False
|
||||
|
||||
|
||||
def test_invalidate_cached_sudo_on_auth_failure_clears_session_cache(monkeypatch):
|
||||
monkeypatch.delenv("SUDO_PASSWORD", raising=False)
|
||||
terminal_tool._set_cached_sudo_password("wrong-pass")
|
||||
|
||||
cleared = terminal_tool._invalidate_cached_sudo_on_auth_failure(
|
||||
"sudo apt install fprintd",
|
||||
"sudo: Authentication failed, try again.",
|
||||
)
|
||||
|
||||
assert cleared is True
|
||||
assert terminal_tool._get_cached_sudo_password() == ""
|
||||
|
||||
|
||||
def test_invalidate_cached_sudo_on_auth_failure_keeps_env_password(monkeypatch):
|
||||
monkeypatch.setenv("SUDO_PASSWORD", "from-env")
|
||||
terminal_tool._set_cached_sudo_password("wrong-pass")
|
||||
|
||||
cleared = terminal_tool._invalidate_cached_sudo_on_auth_failure(
|
||||
"sudo true",
|
||||
"sudo: Authentication failed, try again.",
|
||||
)
|
||||
|
||||
assert cleared is False
|
||||
assert terminal_tool._get_cached_sudo_password() == "wrong-pass"
|
||||
|
||||
|
||||
def test_transform_sudo_command_pipes_one_password_line_per_invocation(monkeypatch):
|
||||
monkeypatch.setenv("SUDO_PASSWORD", "testpass")
|
||||
monkeypatch.delenv("HERMES_INTERACTIVE", raising=False)
|
||||
|
||||
transformed, sudo_stdin = terminal_tool._transform_sudo_command(
|
||||
"sudo true && sudo whoami"
|
||||
)
|
||||
|
||||
assert transformed == "sudo -S -p '' true && sudo -S -p '' whoami"
|
||||
assert sudo_stdin == "testpass\ntestpass\n"
|
||||
|
||||
|
||||
def test_count_real_sudo_invocations_ignores_mentions(monkeypatch):
|
||||
assert terminal_tool._count_real_sudo_invocations("grep sudo README.md") == 0
|
||||
assert terminal_tool._count_real_sudo_invocations("sudo a; sudo b") == 2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue