Add preliminary test fixes
Marco Ricci

Marco Ricci commited on 2025-12-17 16:20:13
Zeige 5 geänderte Dateien mit 61 Einfügungen und 40 Löschungen.

... ...
@@ -757,7 +757,7 @@ class SocketProvider:
757 757
             dist = (
758 758
                 entry_point.dist.name  # type: ignore[union-attr]
759 759
                 if getattr(entry_point, "dist", None) is not None
760
-                else None
760
+                else "<unknown>"
761 761
             )
762 762
             origin = origins.get(key, "derivepassphrase")
763 763
             if not callable(provider_entry.provider):
... ...
@@ -295,13 +295,13 @@ def spawn_noop(  # pragma: no cover [unused]
295 295
 
296 296
 
297 297
 spawn_handlers: dict[str, tuple[str, SpawnFunc, tests.data.KnownSSHAgent]] = {
298
-    "pageant": (
299
-        "pageant",
298
+    "unix-pageant": (
299
+        "unix-pageant",
300 300
         spawn_pageant_on_posix,
301
-        tests.data.KnownSSHAgent.Pageant,
301
+        tests.data.KnownSSHAgent.UNIXPageant,
302 302
     ),
303
-    "ssh-agent": (
304
-        "ssh-agent",
303
+    "openssh-agent": (
304
+        "openssh-agent",
305 305
         spawn_openssh_agent_on_posix,
306 306
         tests.data.KnownSSHAgent.OpenSSHAgent,
307 307
     ),
... ...
@@ -414,7 +414,7 @@ def spawn_named_agent(
414 414
         ):
415 415
             ssh_auth_sock = None
416 416
         elif spawn_func is spawn_noop:
417
-            ssh_auth_sock = os.environ["SSH_AUTH_SOCK"]
417
+            ssh_auth_sock = os.environ.get("SSH_AUTH_SOCK")
418 418
         elif proc is None:  # pragma: no cover [external]
419 419
             err_msg = f"Cannot spawn usable {exec_name}"
420 420
             raise CannotSpawnError(err_msg)
... ...
@@ -535,7 +535,8 @@ for key, handler in spawn_handlers.items():
535 535
             reason="agent excluded via PERMITTED_AGENTS environment variable",
536 536
         ),
537 537
     ]
538
-    if key in {"pageant", "ssh-agent", "(system)"}:
538
+    # Some agents require UNIX domain socket support.
539
+    if key in {"unix-pageant", "openssh-agent"}:
539 540
         marks.append(
540 541
             pytest.mark.skipif(
541 542
                 not hasattr(socket, "AF_UNIX"),
... ...
@@ -656,7 +657,13 @@ def spawn_ssh_agent(
656 657
             monkeypatch.delenv("SSH_AUTH_SOCK", raising=False)
657 658
         try:
658 659
             yield from spawn_named_agent(*request.param)
659
-        except (KeyError, OSError, CannotSpawnError) as exc:
660
+        except KeyError as exc:
661
+            pytest.skip(
662
+                f"The environment variable {exc.args[0]!r} was not found"
663
+                if exc.__class__ is KeyError
664
+                else exc.args[0]
665
+            )
666
+        except (OSError, CannotSpawnError) as exc:
660 667
             pytest.skip(exc.args[0])
661 668
         return
662 669
 
... ...
@@ -756,12 +763,13 @@ def ssh_agent_client_with_test_keys_loaded(  # noqa: C901
756 763
                     current_loaded_keys = frozenset({
757 764
                         pair.key for pair in client.list_keys()
758 765
                     })
759
-                    if agent_type == tests.data.KnownSSHAgent.Pageant and (
766
+                    if agent_type == tests.data.KnownSSHAgent.UNIXPageant and (
760 767
                         key_struct.public_key_data in current_loaded_keys
761 768
                     ):
762 769
                         pass
763
-                    elif agent_type == tests.data.KnownSSHAgent.Pageant and (
764
-                        not isolated
770
+                    elif (
771
+                        agent_type == tests.data.KnownSSHAgent.UNIXPageant
772
+                        and (not isolated)
765 773
                     ):
766 774
                         request_code, payload = prepare_payload(
767 775
                             private_key_data, isolated=True
... ...
@@ -163,10 +163,16 @@ class KnownSSHAgent(str, enum.Enum):
163 163
     Attributes:
164 164
         UNKNOWN (str):
165 165
             Not a known agent, or not known statically.
166
-        Pageant (str):
167
-            The agent from Simon Tatham's PuTTY suite.
166
+        UNIXPageant (str):
167
+            The agent from Simon Tatham's PuTTY suite (on
168
+            UNIX/BSD/POSIX).
168 169
         OpenSSHAgent (str):
169
-            The agent from OpenBSD's OpenSSH suite.
170
+            The agent from OpenBSD's OpenSSH suite (on UNIX/BSD/POSIX).
171
+        Pageant (str):
172
+            The agent from Simon Tatham's PuTTY suite (on Windows).
173
+        OpenSSHAgentOnWindows (str):
174
+            The agent from OpenBSD's OpenSSH suite (Powershell/Windows
175
+            version, on Windows).
170 176
         StubbedSSHAgent (str):
171 177
             The stubbed, fake agent pseudo-socket defined in this test
172 178
             suite.
... ...
@@ -175,10 +181,14 @@ class KnownSSHAgent(str, enum.Enum):
175 181
 
176 182
     UNKNOWN = "(unknown)"
177 183
     """"""
178
-    Pageant = "Pageant"
184
+    UNIXPageant = "UNIXPageant"
179 185
     """"""
180 186
     OpenSSHAgent = "OpenSSHAgent"
181 187
     """"""
188
+    Pageant = "Pageant"
189
+    """"""
190
+    OpenSSHAgentOnWindows = "OpenSSHAgentOnWindows"
191
+    """"""
182 192
     StubbedSSHAgent = "StubbedSSHAgent"
183 193
     """"""
184 194
 
... ...
@@ -342,22 +352,25 @@ class VaultTestConfig(NamedTuple):
342 352
 # ------------------------------
343 353
 
344 354
 
345
-posix_entry = _types.SSHAgentSocketProviderEntry(
346
-    socketprovider.SocketProvider.resolve("posix"), "posix", ()
355
+ssh_auth_sock_on_posix_entry = _types.SSHAgentSocketProviderEntry(
356
+    socketprovider.SocketProvider.resolve("ssh_auth_sock_on_posix"),
357
+    "ssh_auth_sock_on_posix",
358
+    (),
347 359
 )
348 360
 """
349 361
 The standard [`_types.SSHAgentSocketProviderEntry`][] for the UNIX
350 362
 domain socket handler on POSIX systems.
351 363
 """
352 364
 
353
-the_annoying_os_entry = _types.SSHAgentSocketProviderEntry(
354
-    socketprovider.SocketProvider.resolve("the_annoying_os"),
355
-    "the_annoying_os",
365
+pageant_on_the_annoying_os_entry = _types.SSHAgentSocketProviderEntry(
366
+    socketprovider.SocketProvider.resolve("pageant_on_the_annoying_os"),
367
+    "pageant_on_the_annoying_os",
356 368
     (),
357 369
 )
358 370
 """
359 371
 The standard [`_types.SSHAgentSocketProviderEntry`][] for the Windows
360
-named pipe handler on The Annoying Operating System.
372
+named pipe handler (connecting to Pageant) on The Annoying Operating
373
+System.
361 374
 """
362 375
 
363 376
 faulty_entry_callable = _types.SSHAgentSocketProviderEntry(
... ...
@@ -500,7 +500,7 @@ class Parametrize(types.SimpleNamespace):
500 500
                 SignAction.FAIL,
501 501
                 "does not support communicating with it",
502 502
                 [],
503
-                id="no-agent-support",
503
+                id="no-native-agent-available",
504 504
             ),
505 505
             pytest.param(
506 506
                 None,
... ...
@@ -509,7 +509,7 @@ class Parametrize(types.SimpleNamespace):
509 509
                 SignAction.FAIL,
510 510
                 "does not support communicating with it",
511 511
                 [],
512
-                id="no-agent-support",
512
+                id="no-agents-in-agent-provider-list",
513 513
             ),
514 514
             pytest.param(
515 515
                 None,
... ...
@@ -518,7 +518,7 @@ class Parametrize(types.SimpleNamespace):
518 518
                 SignAction.FAIL,
519 519
                 "does not support communicating with it",
520 520
                 ["Cannot connect to an SSH agent via UNIX domain sockets"],
521
-                id="no-agent-support",
521
+                id="no-unix-domain-sockets",
522 522
             ),
523 523
             pytest.param(
524 524
                 None,
... ...
@@ -527,7 +527,7 @@ class Parametrize(types.SimpleNamespace):
527 527
                 SignAction.FAIL,
528 528
                 "does not support communicating with it",
529 529
                 ["Cannot connect to an SSH agent via Windows named pipes"],
530
-                id="no-agent-support",
530
+                id="no-windows-named-pipes",
531 531
             ),
532 532
             pytest.param(
533 533
                 None,
... ...
@@ -80,14 +80,14 @@ class Parametrize(types.SimpleNamespace):
80 80
             pytest.param(
81 81
                 [
82 82
                     importlib.metadata.EntryPoint(
83
-                        name=data.posix_entry.key,
83
+                        name=data.ssh_auth_sock_on_posix_entry.key,
84 84
                         group=socketprovider.SocketProvider.ENTRY_POINT_GROUP_NAME,
85
-                        value="tests.data: posix_entry",
85
+                        value="tests.data: ssh_auth_sock_on_posix_entry",
86 86
                     ),
87 87
                     importlib.metadata.EntryPoint(
88
-                        name=data.the_annoying_os_entry.key,
88
+                        name=data.pageant_on_the_annoying_os_entry.key,
89 89
                         group=socketprovider.SocketProvider.ENTRY_POINT_GROUP_NAME,
90
-                        value="tests.data: the_annoying_os_entry",
90
+                        value="tests.data: pageant_on_the_annoying_os_entry",
91 91
                     ),
92 92
                 ],
93 93
                 id="existing-entries",
... ...
@@ -818,10 +818,10 @@ class TestSSHAgentSocketProviderRegistry:
818 818
     ) -> None:
819 819
         """Resolving a non-existant entry fails."""
820 820
         new_registry = {
821
-            "posix": socketprovider.SocketProvider.registry["posix"],
822
-            "the_annoying_os": socketprovider.SocketProvider.registry[
821
+            "posix": socketprovider.SocketProvider.resolve("posix"),
822
+            "the_annoying_os": socketprovider.SocketProvider.resolve(
823 823
                 "the_annoying_os"
824
-            ],
824
+            ),
825 825
         }
826 826
         with pytest.MonkeyPatch.context() as monkeypatch:
827 827
             monkeypatch.setattr(
... ...
@@ -840,10 +840,10 @@ class TestSSHAgentSocketProviderRegistry:
840 840
 
841 841
         names = ["spam", "ham", "eggs", "parrot"]
842 842
         new_registry = {
843
-            "posix": socketprovider.SocketProvider.registry["posix"],
844
-            "the_annoying_os": socketprovider.SocketProvider.registry[
843
+            "posix": socketprovider.SocketProvider.resolve("posix"),
844
+            "the_annoying_os": socketprovider.SocketProvider.resolve(
845 845
                 "the_annoying_os"
846
-            ],
846
+            ),
847 847
         }
848 848
         with pytest.MonkeyPatch.context() as monkeypatch:
849 849
             monkeypatch.setattr(
... ...
@@ -873,12 +873,12 @@ class TestSSHAgentSocketProviderRegistry:
873 873
 
874 874
         provider = socketprovider.SocketProvider.resolve(existing)
875 875
         new_registry = {
876
-            "posix": socketprovider.SocketProvider.registry["posix"],
877
-            "the_annoying_os": socketprovider.SocketProvider.registry[
876
+            "posix": socketprovider.SocketProvider.resolve("posix"),
877
+            "the_annoying_os": socketprovider.SocketProvider.resolve(
878 878
                 "the_annoying_os"
879
-            ],
879
+            ),
880 880
             "unix_domain": "posix",
881
-            "the_annoying_os_named_pipe": "the_annoying_os",
881
+            "windows_named_pipe": "the_annoying_os",
882 882
         }
883 883
         names = [
884 884
             k
885 885