Marco Ricci commited on 2025-08-08 22:58:55
Zeige 7 geänderte Dateien mit 115 Einfügungen und 39 Löschungen.
... | ... |
@@ -435,7 +435,8 @@ def spawn_named_agent( |
435 | 435 |
) |
436 | 436 |
else: |
437 | 437 |
monkeypatch.setenv( |
438 |
- "SSH_AUTH_SOCK", tests.machinery.StubbedSSHAgentSocketWithAddress.ADDRESS |
|
438 |
+ "SSH_AUTH_SOCK", |
|
439 |
+ tests.machinery.StubbedSSHAgentSocketWithAddress.ADDRESS, |
|
439 | 440 |
) |
440 | 441 |
monkeypatch.setattr( |
441 | 442 |
ssh_agent.SSHAgentClient, |
... | ... |
@@ -53,7 +53,9 @@ def get_concurrency_step_count( |
53 | 53 |
""" |
54 | 54 |
if settings is None: # pragma: no cover |
55 | 55 |
settings = hypothesis.settings() |
56 |
- return min(tests.machinery.get_concurrency_limit(), settings.stateful_step_count) |
|
56 |
+ return min( |
|
57 |
+ tests.machinery.get_concurrency_limit(), settings.stateful_step_count |
|
58 |
+ ) |
|
57 | 59 |
|
58 | 60 |
|
59 | 61 |
# Hypothesis strategies |
... | ... |
@@ -165,4 +167,6 @@ def smudged_vault_test_config( |
165 | 167 |
if not _types.js_truthiness(value) and value != 0: |
166 | 168 |
service[key] = draw(strategies.sampled_from(falsy_no_zero)) |
167 | 169 |
hypothesis.assume(obj != conf.config) |
168 |
- return tests.data.VaultTestConfig(obj, conf.comment, conf.validation_settings) |
|
170 |
+ return tests.data.VaultTestConfig( |
|
171 |
+ obj, conf.comment, conf.validation_settings |
|
172 |
+ ) |
... | ... |
@@ -138,7 +138,9 @@ class Parametrize: |
138 | 138 |
"""Common test parametrizations.""" |
139 | 139 |
|
140 | 140 |
TEST_KEYS = pytest.mark.parametrize( |
141 |
- ["keyname", "key"], tests.data.ALL_KEYS.items(), ids=tests.data.ALL_KEYS.keys() |
|
141 |
+ ["keyname", "key"], |
|
142 |
+ tests.data.ALL_KEYS.items(), |
|
143 |
+ ids=tests.data.ALL_KEYS.keys(), |
|
142 | 144 |
) |
143 | 145 |
|
144 | 146 |
|
... | ... |
@@ -278,7 +278,9 @@ def is_harmless_config_import_warning(record: tuple[str, int, str]) -> bool: |
278 | 278 |
"because a key is also set:" |
279 | 279 |
), |
280 | 280 |
] |
281 |
- return any(tests.machinery.warning_emitted(w, [record]) for w in possible_warnings) |
|
281 |
+ return any( |
|
282 |
+ tests.machinery.warning_emitted(w, [record]) for w in possible_warnings |
|
283 |
+ ) |
|
282 | 284 |
|
283 | 285 |
|
284 | 286 |
def assert_vault_config_is_indented_and_line_broken( |
... | ... |
@@ -2490,7 +2492,9 @@ class TestCLI: |
2490 | 2492 |
) |
2491 | 2493 |
) |
2492 | 2494 |
monkeypatch.setattr( |
2493 |
- cli_helpers, "prompt_for_passphrase", tests.data.callables.auto_prompt |
|
2495 |
+ cli_helpers, |
|
2496 |
+ "prompt_for_passphrase", |
|
2497 |
+ tests.data.callables.auto_prompt, |
|
2494 | 2498 |
) |
2495 | 2499 |
result = runner.invoke( |
2496 | 2500 |
cli.derivepassphrase_vault, |
... | ... |
@@ -2521,7 +2525,9 @@ class TestCLI: |
2521 | 2525 |
) |
2522 | 2526 |
) |
2523 | 2527 |
monkeypatch.setattr( |
2524 |
- cli_helpers, "prompt_for_passphrase", tests.data.callables.auto_prompt |
|
2528 |
+ cli_helpers, |
|
2529 |
+ "prompt_for_passphrase", |
|
2530 |
+ tests.data.callables.auto_prompt, |
|
2525 | 2531 |
) |
2526 | 2532 |
result = runner.invoke( |
2527 | 2533 |
cli.derivepassphrase_vault, |
... | ... |
@@ -2561,7 +2567,9 @@ class TestCLI: |
2561 | 2567 |
) |
2562 | 2568 |
) |
2563 | 2569 |
monkeypatch.setattr( |
2564 |
- vault.Vault, "phrase_from_key", tests.data.callables.phrase_from_key |
|
2570 |
+ vault.Vault, |
|
2571 |
+ "phrase_from_key", |
|
2572 |
+ tests.data.callables.phrase_from_key, |
|
2565 | 2573 |
) |
2566 | 2574 |
result = runner.invoke( |
2567 | 2575 |
cli.derivepassphrase_vault, |
... | ... |
@@ -2602,10 +2610,14 @@ class TestCLI: |
2602 | 2610 |
) |
2603 | 2611 |
) |
2604 | 2612 |
monkeypatch.setattr( |
2605 |
- cli_helpers, "get_suitable_ssh_keys", tests.data.callables.suitable_ssh_keys |
|
2613 |
+ cli_helpers, |
|
2614 |
+ "get_suitable_ssh_keys", |
|
2615 |
+ tests.data.callables.suitable_ssh_keys, |
|
2606 | 2616 |
) |
2607 | 2617 |
monkeypatch.setattr( |
2608 |
- vault.Vault, "phrase_from_key", tests.data.callables.phrase_from_key |
|
2618 |
+ vault.Vault, |
|
2619 |
+ "phrase_from_key", |
|
2620 |
+ tests.data.callables.phrase_from_key, |
|
2609 | 2621 |
) |
2610 | 2622 |
result = runner.invoke( |
2611 | 2623 |
cli.derivepassphrase_vault, |
... | ... |
@@ -2647,9 +2659,13 @@ class TestCLI: |
2647 | 2659 |
) |
2648 | 2660 |
) |
2649 | 2661 |
monkeypatch.setattr( |
2650 |
- ssh_agent.SSHAgentClient, "list_keys", tests.data.callables.list_keys |
|
2662 |
+ ssh_agent.SSHAgentClient, |
|
2663 |
+ "list_keys", |
|
2664 |
+ tests.data.callables.list_keys, |
|
2665 |
+ ) |
|
2666 |
+ monkeypatch.setattr( |
|
2667 |
+ ssh_agent.SSHAgentClient, "sign", tests.data.callables.sign |
|
2651 | 2668 |
) |
2652 |
- monkeypatch.setattr(ssh_agent.SSHAgentClient, "sign", tests.data.callables.sign) |
|
2653 | 2669 |
result = runner.invoke( |
2654 | 2670 |
cli.derivepassphrase_vault, |
2655 | 2671 |
["-k", "--", DUMMY_SERVICE], |
... | ... |
@@ -2690,9 +2706,13 @@ class TestCLI: |
2690 | 2706 |
) |
2691 | 2707 |
) |
2692 | 2708 |
monkeypatch.setattr( |
2693 |
- ssh_agent.SSHAgentClient, "list_keys", tests.data.callables.list_keys |
|
2709 |
+ ssh_agent.SSHAgentClient, |
|
2710 |
+ "list_keys", |
|
2711 |
+ tests.data.callables.list_keys, |
|
2712 |
+ ) |
|
2713 |
+ monkeypatch.setattr( |
|
2714 |
+ ssh_agent.SSHAgentClient, "sign", tests.data.callables.sign |
|
2694 | 2715 |
) |
2695 |
- monkeypatch.setattr(ssh_agent.SSHAgentClient, "sign", tests.data.callables.sign) |
|
2696 | 2716 |
result = runner.invoke( |
2697 | 2717 |
cli.derivepassphrase_vault, |
2698 | 2718 |
["--", DUMMY_SERVICE], |
... | ... |
@@ -2732,9 +2752,13 @@ class TestCLI: |
2732 | 2752 |
) |
2733 | 2753 |
) |
2734 | 2754 |
monkeypatch.setattr( |
2735 |
- ssh_agent.SSHAgentClient, "list_keys", tests.data.callables.list_keys |
|
2755 |
+ ssh_agent.SSHAgentClient, |
|
2756 |
+ "list_keys", |
|
2757 |
+ tests.data.callables.list_keys, |
|
2758 |
+ ) |
|
2759 |
+ monkeypatch.setattr( |
|
2760 |
+ ssh_agent.SSHAgentClient, "sign", tests.data.callables.sign |
|
2736 | 2761 |
) |
2737 |
- monkeypatch.setattr(ssh_agent.SSHAgentClient, "sign", tests.data.callables.sign) |
|
2738 | 2762 |
result = runner.invoke( |
2739 | 2763 |
cli.derivepassphrase_vault, |
2740 | 2764 |
command_line, |
... | ... |
@@ -2866,7 +2890,9 @@ class TestCLI: |
2866 | 2890 |
) |
2867 | 2891 |
) |
2868 | 2892 |
monkeypatch.setattr( |
2869 |
- cli_helpers, "prompt_for_passphrase", tests.data.callables.auto_prompt |
|
2893 |
+ cli_helpers, |
|
2894 |
+ "prompt_for_passphrase", |
|
2895 |
+ tests.data.callables.auto_prompt, |
|
2870 | 2896 |
) |
2871 | 2897 |
result = runner.invoke( |
2872 | 2898 |
cli.derivepassphrase_vault, |
... | ... |
@@ -2904,7 +2930,9 @@ class TestCLI: |
2904 | 2930 |
) |
2905 | 2931 |
) |
2906 | 2932 |
monkeypatch.setattr( |
2907 |
- cli_helpers, "prompt_for_passphrase", tests.data.callables.auto_prompt |
|
2933 |
+ cli_helpers, |
|
2934 |
+ "prompt_for_passphrase", |
|
2935 |
+ tests.data.callables.auto_prompt, |
|
2908 | 2936 |
) |
2909 | 2937 |
result = runner.invoke( |
2910 | 2938 |
cli.derivepassphrase_vault, |
... | ... |
@@ -2945,7 +2973,9 @@ class TestCLI: |
2945 | 2973 |
) |
2946 | 2974 |
) |
2947 | 2975 |
monkeypatch.setattr( |
2948 |
- cli_helpers, "prompt_for_passphrase", tests.data.callables.auto_prompt |
|
2976 |
+ cli_helpers, |
|
2977 |
+ "prompt_for_passphrase", |
|
2978 |
+ tests.data.callables.auto_prompt, |
|
2949 | 2979 |
) |
2950 | 2980 |
result = runner.invoke( |
2951 | 2981 |
cli.derivepassphrase_vault, |
... | ... |
@@ -3940,7 +3970,9 @@ class TestCLI: |
3940 | 3970 |
) |
3941 | 3971 |
) |
3942 | 3972 |
monkeypatch.setattr( |
3943 |
- cli_helpers, "get_suitable_ssh_keys", tests.data.callables.suitable_ssh_keys |
|
3973 |
+ cli_helpers, |
|
3974 |
+ "get_suitable_ssh_keys", |
|
3975 |
+ tests.data.callables.suitable_ssh_keys, |
|
3944 | 3976 |
) |
3945 | 3977 |
result = runner.invoke( |
3946 | 3978 |
cli.derivepassphrase_vault, |
... | ... |
@@ -3980,7 +4012,9 @@ class TestCLI: |
3980 | 4012 |
) |
3981 | 4013 |
) |
3982 | 4014 |
monkeypatch.setattr( |
3983 |
- cli_helpers, "get_suitable_ssh_keys", tests.data.callables.suitable_ssh_keys |
|
4015 |
+ cli_helpers, |
|
4016 |
+ "get_suitable_ssh_keys", |
|
4017 |
+ tests.data.callables.suitable_ssh_keys, |
|
3984 | 4018 |
) |
3985 | 4019 |
result = runner.invoke( |
3986 | 4020 |
cli.derivepassphrase_vault, |
... | ... |
@@ -4021,7 +4055,9 @@ class TestCLI: |
4021 | 4055 |
# Also patch the list of suitable SSH keys, lest we be at |
4022 | 4056 |
# the mercy of whatever SSH agent may be running. |
4023 | 4057 |
monkeypatch.setattr( |
4024 |
- cli_helpers, "get_suitable_ssh_keys", tests.data.callables.suitable_ssh_keys |
|
4058 |
+ cli_helpers, |
|
4059 |
+ "get_suitable_ssh_keys", |
|
4060 |
+ tests.data.callables.suitable_ssh_keys, |
|
4025 | 4061 |
) |
4026 | 4062 |
result = runner.invoke( |
4027 | 4063 |
cli.derivepassphrase_vault, |
... | ... |
@@ -4497,9 +4533,9 @@ class TestCLI: |
4497 | 4533 |
input=input, |
4498 | 4534 |
) |
4499 | 4535 |
assert result.clean_exit(), "expected clean exit" |
4500 |
- assert tests.machinery.warning_emitted(warning_message, caplog.record_tuples), ( |
|
4501 |
- "expected known warning message in stderr" |
|
4502 |
- ) |
|
4536 |
+ assert tests.machinery.warning_emitted( |
|
4537 |
+ warning_message, caplog.record_tuples |
|
4538 |
+ ), "expected known warning message in stderr" |
|
4503 | 4539 |
|
4504 | 4540 |
@Parametrize.UNICODE_NORMALIZATION_ERROR_INPUTS |
4505 | 4541 |
def test_301_unicode_normalization_form_error( |
... | ... |
@@ -5504,7 +5540,9 @@ Will replace with spam, okay? (Please say "y" or "n".): Boo. |
5504 | 5540 |
"""[`cli_helpers.get_suitable_ssh_keys`][] works.""" |
5505 | 5541 |
with pytest.MonkeyPatch.context() as monkeypatch: |
5506 | 5542 |
monkeypatch.setattr( |
5507 |
- ssh_agent.SSHAgentClient, "list_keys", tests.data.callables.list_keys |
|
5543 |
+ ssh_agent.SSHAgentClient, |
|
5544 |
+ "list_keys", |
|
5545 |
+ tests.data.callables.list_keys, |
|
5508 | 5546 |
) |
5509 | 5547 |
hint: ssh_agent.SSHAgentClient | _types.SSHAgentSocket | None |
5510 | 5548 |
# TODO(the-13th-letter): Rewrite using structural pattern |
... | ... |
@@ -5783,7 +5821,9 @@ class TestCLITransition: |
5783 | 5821 |
) |
5784 | 5822 |
) |
5785 | 5823 |
monkeypatch.setattr( |
5786 |
- cli_helpers, "prompt_for_passphrase", tests.data.callables.auto_prompt |
|
5824 |
+ cli_helpers, |
|
5825 |
+ "prompt_for_passphrase", |
|
5826 |
+ tests.data.callables.auto_prompt, |
|
5787 | 5827 |
) |
5788 | 5828 |
result = runner.invoke( |
5789 | 5829 |
cli.derivepassphrase, |
... | ... |
@@ -6727,7 +6767,9 @@ class FakeConfigurationMutexStateMachine(stateful.RuleBasedStateMachine): |
6727 | 6767 |
settings = FakeConfigurationMutexStateMachine.TestCase.settings |
6728 | 6768 |
except AttributeError: # pragma: no cover |
6729 | 6769 |
settings = None |
6730 |
- self.step_count = tests.machinery.hypothesis.get_concurrency_step_count(settings) |
|
6770 |
+ self.step_count = ( |
|
6771 |
+ tests.machinery.hypothesis.get_concurrency_step_count(settings) |
|
6772 |
+ ) |
|
6731 | 6773 |
|
6732 | 6774 |
@stateful.initialize( |
6733 | 6775 |
target=configuration, |
... | ... |
@@ -7232,9 +7274,11 @@ class FakeConfigurationMutexStateMachine(stateful.RuleBasedStateMachine): |
7232 | 7274 |
raise AssertionError() |
7233 | 7275 |
|
7234 | 7276 |
|
7235 |
-TestFakedConfigurationMutex = tests.machinery.pytest.skip_if_no_multiprocessing_support( |
|
7277 |
+TestFakedConfigurationMutex = ( |
|
7278 |
+ tests.machinery.pytest.skip_if_no_multiprocessing_support( |
|
7236 | 7279 |
FakeConfigurationMutexStateMachine.TestCase |
7237 | 7280 |
) |
7281 |
+) |
|
7238 | 7282 |
"""The [`unittest.TestCase`][] class that will actually be run.""" |
7239 | 7283 |
|
7240 | 7284 |
|
... | ... |
@@ -137,7 +137,9 @@ class Parametrize(types.SimpleNamespace): |
137 | 137 |
[ |
138 | 138 |
None, |
139 | 139 |
pytest.param(tests.data.VAULT_MASTER_KEY, id="str"), |
140 |
- pytest.param(tests.data.VAULT_MASTER_KEY.encode("ascii"), id="bytes"), |
|
140 |
+ pytest.param( |
|
141 |
+ tests.data.VAULT_MASTER_KEY.encode("ascii"), id="bytes" |
|
142 |
+ ), |
|
141 | 143 |
pytest.param( |
142 | 144 |
bytearray(tests.data.VAULT_MASTER_KEY.encode("ascii")), |
143 | 145 |
id="bytearray", |
... | ... |
@@ -259,7 +261,13 @@ class TestCLI: |
259 | 261 |
) |
260 | 262 |
result = runner.invoke( |
261 | 263 |
cli.derivepassphrase_export_vault, |
262 |
- ["-f", format, "-k", tests.data.VAULT_MASTER_KEY, "VAULT_PATH"], |
|
264 |
+ [ |
|
265 |
+ "-f", |
|
266 |
+ format, |
|
267 |
+ "-k", |
|
268 |
+ tests.data.VAULT_MASTER_KEY, |
|
269 |
+ "VAULT_PATH", |
|
270 |
+ ], |
|
263 | 271 |
) |
264 | 272 |
assert result.clean_exit(empty_stderr=True), "expected clean exit" |
265 | 273 |
assert json.loads(result.stdout) == config_data |
... | ... |
@@ -517,7 +517,8 @@ class TestTestingMachineryStubbedSSHAgentSocket: |
517 | 517 |
with contextlib.ExitStack() as stack: |
518 | 518 |
monkeypatch = stack.enter_context(pytest.MonkeyPatch.context()) |
519 | 519 |
monkeypatch.setenv( |
520 |
- "SSH_AUTH_SOCK", tests.machinery.StubbedSSHAgentSocketWithAddress.ADDRESS |
|
520 |
+ "SSH_AUTH_SOCK", |
|
521 |
+ tests.machinery.StubbedSSHAgentSocketWithAddress.ADDRESS, |
|
521 | 522 |
) |
522 | 523 |
agent = stack.enter_context( |
523 | 524 |
tests.machinery.StubbedSSHAgentSocketWithAddress() |
... | ... |
@@ -545,7 +546,8 @@ class TestTestingMachineryStubbedSSHAgentSocket: |
545 | 546 |
with contextlib.ExitStack() as stack: |
546 | 547 |
monkeypatch = stack.enter_context(pytest.MonkeyPatch.context()) |
547 | 548 |
monkeypatch.setenv( |
548 |
- "SSH_AUTH_SOCK", tests.machinery.StubbedSSHAgentSocketWithAddress.ADDRESS |
|
549 |
+ "SSH_AUTH_SOCK", |
|
550 |
+ tests.machinery.StubbedSSHAgentSocketWithAddress.ADDRESS, |
|
549 | 551 |
) |
550 | 552 |
agent = stack.enter_context( |
551 | 553 |
tests.machinery.StubbedSSHAgentSocketWithAddressAndDeterministicDSA() |
... | ... |
@@ -659,7 +661,9 @@ class TestTestingMachineryStubbedSSHAgentSocket: |
659 | 661 |
query_response = b"" |
660 | 662 |
with pytest.raises( |
661 | 663 |
ValueError, |
662 |
- match=re.escape(tests.machinery.StubbedSSHAgentSocket._SOCKET_IS_CLOSED), |
|
664 |
+ match=re.escape( |
|
665 |
+ tests.machinery.StubbedSSHAgentSocket._SOCKET_IS_CLOSED |
|
666 |
+ ), |
|
663 | 667 |
): |
664 | 668 |
agent.sendall(query_request) |
665 | 669 |
assert agent.recv(100) == query_response |
... | ... |
@@ -797,10 +801,17 @@ class TestStaticFunctionality: |
797 | 801 |
) -> None: |
798 | 802 |
"""[`tests.parse_sh_export_line`][] works.""" |
799 | 803 |
if value is not None: |
800 |
- assert tests.data.callables.parse_sh_export_line(line, env_name=env_name) == value |
|
804 |
+ assert ( |
|
805 |
+ tests.data.callables.parse_sh_export_line( |
|
806 |
+ line, env_name=env_name |
|
807 |
+ ) |
|
808 |
+ == value |
|
809 |
+ ) |
|
801 | 810 |
else: |
802 | 811 |
with pytest.raises(ValueError, match="Cannot parse sh line:"): |
803 |
- tests.data.callables.parse_sh_export_line(line, env_name=env_name) |
|
812 |
+ tests.data.callables.parse_sh_export_line( |
|
813 |
+ line, env_name=env_name |
|
814 |
+ ) |
|
804 | 815 |
|
805 | 816 |
def test_200_constructor_posix_no_ssh_auth_sock( |
806 | 817 |
self, |
... | ... |
@@ -1324,7 +1335,9 @@ class TestAgentInteraction: |
1324 | 1335 |
|
1325 | 1336 |
def key_is_suitable(key: bytes) -> bool: |
1326 | 1337 |
"""Stub out [`vault.Vault.key_is_suitable`][].""" |
1327 |
- always = {v.public_key_data for v in tests.data.SUPPORTED_KEYS.values()} |
|
1338 |
+ always = { |
|
1339 |
+ v.public_key_data for v in tests.data.SUPPORTED_KEYS.values() |
|
1340 |
+ } |
|
1328 | 1341 |
dsa = { |
1329 | 1342 |
v.public_key_data |
1330 | 1343 |
for k, v in tests.data.UNSUITABLE_KEYS.items() |
... | ... |
@@ -1354,7 +1367,9 @@ class TestAgentInteraction: |
1354 | 1367 |
text = "Use this key? yes\n" |
1355 | 1368 |
else: |
1356 | 1369 |
monkeypatch.setattr( |
1357 |
- ssh_agent.SSHAgentClient, "list_keys", tests.data.callables.list_keys |
|
1370 |
+ ssh_agent.SSHAgentClient, |
|
1371 |
+ "list_keys", |
|
1372 |
+ tests.data.callables.list_keys, |
|
1358 | 1373 |
) |
1359 | 1374 |
keys = [ |
1360 | 1375 |
pair.key |
... | ... |
@@ -159,7 +159,9 @@ def test_200a_is_vault_config_smudged( |
159 | 159 |
|
160 | 160 |
|
161 | 161 |
@Parametrize.VAULT_TEST_CONFIGS |
162 |
-def test_400_validate_vault_config(test_config: tests.data.VaultTestConfig) -> None: |
|
162 |
+def test_400_validate_vault_config( |
|
163 |
+ test_config: tests.data.VaultTestConfig, |
|
164 |
+) -> None: |
|
163 | 165 |
"""Validate this vault configuration. |
164 | 166 |
|
165 | 167 |
Check all test configurations, including those with non-standard |
166 | 168 |