Marco Ricci commited on 2025-12-25 14:13:42
Zeige 1 geänderte Dateien mit 52 Einfügungen und 52 Löschungen.
In the testing machinery, move the "SSH agent spawn handler params" table, closer to the "SSH agent spawn handlers" table. The former is used as a parametrization set for some pytest fixtures, and is further filtered by both environment variables as well as pytest marks. Keeping these two tables closer together makes it easier to debug the SSH agent spawning machinery.
| ... | ... |
@@ -362,6 +362,58 @@ spawn_handlers: dict[str, SpawnHandler] = {
|
| 362 | 362 |
The standard registry of agent spawning functions. |
| 363 | 363 |
""" |
| 364 | 364 |
|
| 365 |
+ |
|
| 366 |
+def is_agent_permitted( |
|
| 367 |
+ agent_type: tests.data.KnownSSHAgent, |
|
| 368 |
+) -> bool: # pragma: no cover [external] |
|
| 369 |
+ """May the given SSH agent be spawned by the test harness? |
|
| 370 |
+ |
|
| 371 |
+ If the environment variable `PERMITTED_SSH_AGENTS` is given, it |
|
| 372 |
+ names a comma-separated list of known SSH agent names that the test |
|
| 373 |
+ harness may spawn. Invalid names are silently ignored. If not |
|
| 374 |
+ given, or empty, then any agent may be spawned. |
|
| 375 |
+ |
|
| 376 |
+ (To not allow any agent to be spawned, specify a single comma as the |
|
| 377 |
+ list. But see below.) |
|
| 378 |
+ |
|
| 379 |
+ The stubbed agents cannot be restricted in this manner, as the test |
|
| 380 |
+ suite depends on their availability. |
|
| 381 |
+ |
|
| 382 |
+ """ |
|
| 383 |
+ if not os.environ.get("PERMITTED_SSH_AGENTS"):
|
|
| 384 |
+ return True |
|
| 385 |
+ permitted_agents = {tests.data.KnownSSHAgent.StubbedSSHAgent}
|
|
| 386 |
+ permitted_agents.update({
|
|
| 387 |
+ tests.data.KnownSSHAgent(x) |
|
| 388 |
+ for x in os.environ["PERMITTED_SSH_AGENTS"].split(",")
|
|
| 389 |
+ if x in tests.data.KnownSSHAgent.__members__ |
|
| 390 |
+ }) |
|
| 391 |
+ return agent_type in permitted_agents |
|
| 392 |
+ |
|
| 393 |
+ |
|
| 394 |
+spawn_handlers_params: list[Sequence] = [] |
|
| 395 |
+""" |
|
| 396 |
+The standard registry of agent spawning functions, annotated as |
|
| 397 |
+a `pytest` parameter set. (In particular, this includes the conditional |
|
| 398 |
+skip marks.) Used by some test fixtures. |
|
| 399 |
+""" |
|
| 400 |
+for key, handler in spawn_handlers.items(): |
|
| 401 |
+ marks = [ |
|
| 402 |
+ pytest.mark.skipif( |
|
| 403 |
+ not is_agent_permitted(handler.agent_type), |
|
| 404 |
+ reason="SSH agent excluded via PERMITTED_AGENTS " |
|
| 405 |
+ "environment variable.", |
|
| 406 |
+ ), |
|
| 407 |
+ ] |
|
| 408 |
+ if key in {"unix-pageant", "openssh", "(system-agent)"}:
|
|
| 409 |
+ marks.append( |
|
| 410 |
+ pytest.mark.skipif( |
|
| 411 |
+ not hasattr(socket, "AF_UNIX"), |
|
| 412 |
+ reason="No Python or system support for UNIX domain sockets.", |
|
| 413 |
+ ) |
|
| 414 |
+ ) |
|
| 415 |
+ spawn_handlers_params.append(pytest.param(handler, id=key, marks=marks)) |
|
| 416 |
+ |
|
| 365 | 417 |
Popen = TypeVar("Popen", bound=subprocess.Popen)
|
| 366 | 418 |
|
| 367 | 419 |
|
| ... | ... |
@@ -545,58 +597,6 @@ def spawn_named_agent( |
| 545 | 597 |
) |
| 546 | 598 |
|
| 547 | 599 |
|
| 548 |
-def is_agent_permitted( |
|
| 549 |
- agent_type: tests.data.KnownSSHAgent, |
|
| 550 |
-) -> bool: # pragma: no cover [external] |
|
| 551 |
- """May the given SSH agent be spawned by the test harness? |
|
| 552 |
- |
|
| 553 |
- If the environment variable `PERMITTED_SSH_AGENTS` is given, it |
|
| 554 |
- names a comma-separated list of known SSH agent names that the test |
|
| 555 |
- harness may spawn. Invalid names are silently ignored. If not |
|
| 556 |
- given, or empty, then any agent may be spawned. |
|
| 557 |
- |
|
| 558 |
- (To not allow any agent to be spawned, specify a single comma as the |
|
| 559 |
- list. But see below.) |
|
| 560 |
- |
|
| 561 |
- The stubbed agents cannot be restricted in this manner, as the test |
|
| 562 |
- suite depends on their availability. |
|
| 563 |
- |
|
| 564 |
- """ |
|
| 565 |
- if not os.environ.get("PERMITTED_SSH_AGENTS"):
|
|
| 566 |
- return True |
|
| 567 |
- permitted_agents = {tests.data.KnownSSHAgent.StubbedSSHAgent}
|
|
| 568 |
- permitted_agents.update({
|
|
| 569 |
- tests.data.KnownSSHAgent(x) |
|
| 570 |
- for x in os.environ["PERMITTED_SSH_AGENTS"].split(",")
|
|
| 571 |
- if x in tests.data.KnownSSHAgent.__members__ |
|
| 572 |
- }) |
|
| 573 |
- return agent_type in permitted_agents |
|
| 574 |
- |
|
| 575 |
- |
|
| 576 |
-spawn_handlers_params: list[Sequence] = [] |
|
| 577 |
-""" |
|
| 578 |
-The standard registry of agent spawning functions, annotated as |
|
| 579 |
-a `pytest` parameter set. (In particular, this includes the conditional |
|
| 580 |
-skip marks.) Used by some test fixtures. |
|
| 581 |
-""" |
|
| 582 |
-for key, handler in spawn_handlers.items(): |
|
| 583 |
- marks = [ |
|
| 584 |
- pytest.mark.skipif( |
|
| 585 |
- not is_agent_permitted(handler.agent_type), |
|
| 586 |
- reason="SSH agent excluded via PERMITTED_AGENTS " |
|
| 587 |
- "environment variable.", |
|
| 588 |
- ), |
|
| 589 |
- ] |
|
| 590 |
- if key in {"unix-pageant", "openssh", "(system-agent)"}:
|
|
| 591 |
- marks.append( |
|
| 592 |
- pytest.mark.skipif( |
|
| 593 |
- not hasattr(socket, "AF_UNIX"), |
|
| 594 |
- reason="No Python or system support for UNIX domain sockets.", |
|
| 595 |
- ) |
|
| 596 |
- ) |
|
| 597 |
- spawn_handlers_params.append(pytest.param(handler, id=key, marks=marks)) |
|
| 598 |
- |
|
| 599 |
- |
|
| 600 | 600 |
@pytest.fixture |
| 601 | 601 |
def running_ssh_agent( # pragma: no cover [external] |
| 602 | 602 |
) -> Iterator[tests.data.RunningSSHAgentInfo]: |
| 603 | 603 |