Marco Ricci commited on 2026-07-03 21:53:17
Zeige 1 geänderte Dateien mit 21 Einfügungen und 6 Löschungen.
All interaction with a "real" agent is stubbed out anyway, and there is no reason to run this test against multiple agents or conversely to skip it if the system cannot spawn/interface an agent at all.
| ... | ... |
@@ -187,6 +187,21 @@ for opt, config in SINGLES.items(): |
| 187 | 187 |
) |
| 188 | 188 |
|
| 189 | 189 |
|
| 190 |
+@pytest.fixture |
|
| 191 |
+def use_stub_agent_with_address() -> Generator[None, None, None]: |
|
| 192 |
+ """Enforce use of the stub SSH agent with socket address.""" |
|
| 193 |
+ with pytest.MonkeyPatch.context() as monkeypatch: |
|
| 194 |
+ monkeypatch.setattr( |
|
| 195 |
+ ssh_agent.SSHAgentClient, |
|
| 196 |
+ "SOCKET_PROVIDERS", |
|
| 197 |
+ (_types.BuiltinSSHAgentSocketProvider.STUB_AGENT_WITH_ADDRESS,), |
|
| 198 |
+ ) |
|
| 199 |
+ monkeypatch.setenv( |
|
| 200 |
+ "SSH_AUTH_SOCK", machinery.StubbedSSHAgentSocketWithAddress.ADDRESS |
|
| 201 |
+ ) |
|
| 202 |
+ yield |
|
| 203 |
+ |
|
| 204 |
+ |
|
| 190 | 205 |
def is_warning_line(line: str) -> bool: |
| 191 | 206 |
"""Return true if the line is a warning line.""" |
| 192 | 207 |
return " Warning: " in line or " Deprecation warning: " in line |
| ... | ... |
@@ -819,12 +834,12 @@ class TestPhraseAndKeyOverriding: |
| 819 | 834 |
@Parametrize.KEY_INDEX |
| 820 | 835 |
def test_key_override_on_command_line( |
| 821 | 836 |
self, |
| 822 |
- running_ssh_agent: data.RunningSSHAgentInfo, |
|
| 837 |
+ use_stub_agent_with_address: None, |
|
| 823 | 838 |
config: _types.VaultConfig, |
| 824 | 839 |
key_index: int, |
| 825 | 840 |
) -> None: |
| 826 | 841 |
"""A command-line SSH key will override the configured key.""" |
| 827 |
- del running_ssh_agent |
|
| 842 |
+ del use_stub_agent_with_address |
|
| 828 | 843 |
result = self._test( |
| 829 | 844 |
["-k", "--", DUMMY_SERVICE], |
| 830 | 845 |
config=config, |
| ... | ... |
@@ -838,10 +853,10 @@ class TestPhraseAndKeyOverriding: |
| 838 | 853 |
|
| 839 | 854 |
def test_service_phrase_if_key_in_global_config( |
| 840 | 855 |
self, |
| 841 |
- running_ssh_agent: data.RunningSSHAgentInfo, |
|
| 856 |
+ use_stub_agent_with_address: None, |
|
| 842 | 857 |
) -> None: |
| 843 | 858 |
"""A configured passphrase does not override a configured key.""" |
| 844 |
- del running_ssh_agent |
|
| 859 |
+ del use_stub_agent_with_address |
|
| 845 | 860 |
result = self._test( |
| 846 | 861 |
["--", DUMMY_SERVICE], |
| 847 | 862 |
config={
|
| ... | ... |
@@ -866,13 +881,13 @@ class TestPhraseAndKeyOverriding: |
| 866 | 881 |
@Parametrize.KEY_OVERRIDING_IN_CONFIG |
| 867 | 882 |
def test_setting_phrase_thus_overriding_key_in_config( |
| 868 | 883 |
self, |
| 869 |
- running_ssh_agent: data.RunningSSHAgentInfo, |
|
| 884 |
+ use_stub_agent_with_address: None, |
|
| 870 | 885 |
caplog: pytest.LogCaptureFixture, |
| 871 | 886 |
config: _types.VaultConfig, |
| 872 | 887 |
command_line: list[str], |
| 873 | 888 |
) -> None: |
| 874 | 889 |
"""Configuring a passphrase atop an SSH key works, but warns.""" |
| 875 |
- del running_ssh_agent |
|
| 890 |
+ del use_stub_agent_with_address |
|
| 876 | 891 |
result = self._test( |
| 877 | 892 |
command_line, config=config, input=DUMMY_PASSPHRASE |
| 878 | 893 |
) |
| 879 | 894 |