Rename testing symbols in anticipation of The Annoying OS support
Marco Ricci

Marco Ricci commited on 2025-12-25 12:34:37
Zeige 3 geänderte Dateien mit 34 Einfügungen und 42 Löschungen.


Rename the `pageant` spawn handler to `unix-pageant`, the `ssh-agent`
handler to `openssh`, and the `(system)` handler to `(system-agent)`.
Similarly, rename the `Pageant` known SSH agent type to `UNIXPageant`,
for the same reason.  Since Pageant on The Annoying OS is the common
configuration, and Pageant on UNIX is the exceptional configuration,
Pageant on UNIX gets a decoration (the `unix-` or `UNIX` prefix).
OpenSSH, on the other hand, has its default configuration on UNIX, and
so gets no such decoration.

Rename the `MANGLE_SSH_AUTH_SOCK` and `UNSET_SSH_AUTH_SOCK` socket
address actions into `MANGLE_ADDRESS` and `UNSET_ADDRESS`, and add some
minor additional documentation.  Also subsume the
`MANGLE_WINDOWS_NAMED_PIPE` and `UNSET_WINDOWS_NAMED_PIPE` actions,
which are so far unused.  The desire to mangle or unset the address for
testing purposes is independent of the actual technology used to connect
to the SSH agent, so it makes no sense to have separate symbols per
connection technology.

Rename the `SpawnFunc` type to `SSHAgentSpawnFunc`.  A matching
`SSHAgentInterfaceFunc` is soon to follow, which would have a very
uninformative name if only named "Interface Func".
... ...
@@ -153,7 +153,7 @@ def skip_if_no_af_unix_support() -> None:  # pragma: no cover [external]
153 153
         pytest.skip("No Python or system support for UNIX domain sockets.")
154 154
 
155 155
 
156
-class SpawnFunc(Protocol):
156
+class SSHAgentSpawnFunc(Protocol):
157 157
     """Spawns an SSH agent, if possible."""
158 158
 
159 159
     def __call__(
... ...
@@ -315,21 +315,21 @@ class SpawnHandler(NamedTuple):
315 315
 
316 316
     key: str
317 317
     executable: str | None
318
-    spawn_func: SpawnFunc
318
+    spawn_func: SSHAgentSpawnFunc
319 319
     agent_type: tests.data.KnownSSHAgent
320 320
     agent_name: str | None
321 321
 
322 322
 
323 323
 spawn_handlers: dict[str, SpawnHandler] = {
324
-    "pageant": SpawnHandler(
325
-        "pageant",
324
+    "unix-pageant": SpawnHandler(
325
+        "unix-pageant",
326 326
         None,
327 327
         spawn_pageant_on_posix,
328
-        tests.data.KnownSSHAgent.Pageant,
328
+        tests.data.KnownSSHAgent.UNIXPageant,
329 329
         "Pageant (UNIX)",
330 330
     ),
331
-    "ssh-agent": SpawnHandler(
332
-        "ssh-agent",
331
+    "openssh": SpawnHandler(
332
+        "openssh",
333 333
         None,
334 334
         spawn_openssh_agent_on_posix,
335 335
         tests.data.KnownSSHAgent.OpenSSHAgent,
... ...
@@ -350,8 +350,8 @@ spawn_handlers: dict[str, SpawnHandler] = {
350 350
         "stub_agent_with_address_and_deterministic_dsa "
351 351
         "(derivepassphrase test suite)",
352 352
     ),
353
-    "(system)": SpawnHandler(
354
-        "(system)",
353
+    "(system-agent)": SpawnHandler(
354
+        "(system-agent)",
355 355
         None,
356 356
         spawn_noop,
357 357
         tests.data.KnownSSHAgent.UNKNOWN,
... ...
@@ -392,7 +392,7 @@ class CannotSpawnError(RuntimeError):
392 392
 
393 393
 def spawn_named_agent(
394 394
     executable: str | None,
395
-    spawn_func: SpawnFunc,
395
+    spawn_func: SSHAgentSpawnFunc,
396 396
     agent_type: tests.data.KnownSSHAgent,
397 397
     agent_name: str,
398 398
 ) -> Iterator[tests.data.SpawnedSSHAgentInfo]:  # pragma: no cover [external]
... ...
@@ -587,7 +587,7 @@ for key, handler in spawn_handlers.items():
587 587
             "environment variable.",
588 588
         ),
589 589
     ]
590
-    if key in {"pageant", "ssh-agent", "(system)"}:
590
+    if key in {"unix-pageant", "openssh", "(system-agent)"}:
591 591
         marks.append(
592 592
             pytest.mark.skipif(
593 593
                 not hasattr(socket, "AF_UNIX"),
... ...
@@ -824,12 +824,12 @@ def ssh_agent_client_with_test_keys_loaded(  # noqa: C901
824 824
                         pair.key for pair in client.list_keys()
825 825
                     })
826 826
                     if (
827
-                        agent_type == tests.data.KnownSSHAgent.Pageant
827
+                        agent_type == tests.data.KnownSSHAgent.UNIXPageant
828 828
                         and key_struct.public_key_data in current_loaded_keys
829 829
                     ):
830 830
                         pass
831 831
                     elif (
832
-                        agent_type == tests.data.KnownSSHAgent.Pageant
832
+                        agent_type == tests.data.KnownSSHAgent.UNIXPageant
833 833
                         and not isolated
834 834
                     ):
835 835
                         request_code, payload = prepare_payload(
... ...
@@ -163,10 +163,11 @@ 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).
170 171
         StubbedSSHAgent (str):
171 172
             The stubbed, fake agent pseudo-socket defined in this test
172 173
             suite.
... ...
@@ -175,7 +176,7 @@ class KnownSSHAgent(str, enum.Enum):
175 176
 
176 177
     UNKNOWN = "(unknown)"
177 178
     """"""
178
-    Pageant = "Pageant"
179
+    UNIXPageant = "UNIXPageant"
179 180
     """"""
180 181
     OpenSSHAgent = "OpenSSHAgent"
181 182
     """"""
... ...
@@ -199,26 +199,22 @@ class SocketAddressAction(str, enum.Enum):
199 199
     """Test fixture settings for the SSH agent socket address.
200 200
 
201 201
     Attributes:
202
-        MANGLE_WINDOWS_NAMED_PIPE:
203
-            Mangle the address for the Windows named pipe endpoint.
204
-        MANGLE_SSH_AUTH_SOCK:
205
-            Mangle the address for the UNIX domain socket (the
206
-            `SSH_AUTH_SOCK` environment variable).
207
-        UNSET_WINDOWS_NAMED_PIPE:
208
-            Unset the address for the Windows named pipe endpoint.
209
-        UNSET_SSH_AUTH_SOCK:
210
-            Unset the `SSH_AUTH_SOCK` environment variable (the address
211
-            for the UNIX domain socket).
202
+        MANGLE_ADDRESS:
203
+            Mangle the socket address.
204
+
205
+            For UNIX domain sockets, mangle the `SSH_AUTH_SOCK`
206
+            environment variable.
207
+        UNSET_ADDRESS:
208
+            Unset the socket address.
209
+
210
+            For UNIX domain sockets, unset the `SSH_AUTH_SOCK`
211
+            environment variable.
212 212
 
213 213
     """
214 214
 
215
-    MANGLE_WINDOWS_NAMED_PIPE = enum.auto()
216
-    """"""
217
-    MANGLE_SSH_AUTH_SOCK = enum.auto()
215
+    MANGLE_ADDRESS = enum.auto()
218 216
     """"""
219
-    UNSET_WINDOWS_NAMED_PIPE = enum.auto()
220
-    """"""
221
-    UNSET_SSH_AUTH_SOCK = enum.auto()
217
+    UNSET_ADDRESS = enum.auto()
222 218
     """"""
223 219
 
224 220
     def __call__(
... ...
@@ -228,19 +224,14 @@ class SocketAddressAction(str, enum.Enum):
228 224
         # TODO(the-13th-letter): Rewrite using structural pattern
229 225
         # matching.
230 226
         # https://the13thletter.info/derivepassphrase/latest/pycompatibility/#after-eol-py3.9
231
-        if self in {
232
-            self.MANGLE_WINDOWS_NAMED_PIPE,
233
-            self.UNSET_WINDOWS_NAMED_PIPE,
234
-        }:  # pragma: no cover [unused]
235
-            pass
236
-        elif self == self.MANGLE_SSH_AUTH_SOCK:
227
+        if self == self.MANGLE_ADDRESS:
237 228
             monkeypatch.setenv(
238 229
                 "SSH_AUTH_SOCK",
239 230
                 os.environ["SSH_AUTH_SOCK"] + "~"
240 231
                 if "SSH_AUTH_SOCK" in os.environ
241 232
                 else "/",
242 233
             )
243
-        elif self == self.UNSET_SSH_AUTH_SOCK:
234
+        elif self == self.UNSET_ADDRESS:
244 235
             monkeypatch.delenv("SSH_AUTH_SOCK", raising=False)
245 236
         else:
246 237
             raise AssertionError()
... ...
@@ -480,7 +471,7 @@ class Parametrize(types.SimpleNamespace):
480 471
             ),
481 472
             pytest.param(
482 473
                 None,
483
-                SocketAddressAction.MANGLE_SSH_AUTH_SOCK,
474
+                SocketAddressAction.MANGLE_ADDRESS,
484 475
                 None,
485 476
                 SignAction.FAIL,
486 477
                 "Cannot connect to the SSH agent",
... ...
@@ -489,7 +480,7 @@ class Parametrize(types.SimpleNamespace):
489 480
             ),
490 481
             pytest.param(
491 482
                 None,
492
-                SocketAddressAction.UNSET_SSH_AUTH_SOCK,
483
+                SocketAddressAction.UNSET_ADDRESS,
493 484
                 None,
494 485
                 SignAction.FAIL,
495 486
                 "Cannot find any running SSH agent",
496 487