Marco Ricci commited on 2026-07-03 21:50:35
Zeige 4 geänderte Dateien mit 25 Einfügungen und 24 Löschungen.
Typos, unwise variable names, and redundancies in the test logic or arguments.
| ... | ... |
@@ -1101,7 +1101,7 @@ class BuiltinSSHAgentSocketProvider(str, enum.Enum): |
| 1101 | 1101 |
) -> bool: # pragma: no cover [external] |
| 1102 | 1102 |
"""Return true if this SSH agent socket provider is available. |
| 1103 | 1103 |
|
| 1104 |
- This works by actually attempting to connet to an agent via the |
|
| 1104 |
+ This works by actually attempting to connect to an agent via the |
|
| 1105 | 1105 |
socket provider. |
| 1106 | 1106 |
|
| 1107 | 1107 |
""" |
| ... | ... |
@@ -1166,7 +1166,7 @@ class SSHAgentSocket(Protocol): |
| 1166 | 1166 |
|
| 1167 | 1167 |
def sendall(self, data: Buffer, flags: int = 0, /) -> None: ... |
| 1168 | 1168 |
|
| 1169 |
- def recv(self, data: int, flags: int = 0, /) -> bytes: ... |
|
| 1169 |
+ def recv(self, bufsize: int, flags: int = 0, /) -> bytes: ... |
|
| 1170 | 1170 |
|
| 1171 | 1171 |
|
| 1172 | 1172 |
SSHAgentSocketProvider: TypeAlias = "Callable[[], SSHAgentSocket]" |
| ... | ... |
@@ -329,7 +329,13 @@ class Parametrize(types.SimpleNamespace): |
| 329 | 329 |
], |
| 330 | 330 |
) |
| 331 | 331 |
KEY_INDEX = pytest.mark.parametrize( |
| 332 |
- "key_index", [1, 2, 3], ids=lambda i: f"index{i}"
|
|
| 332 |
+ "key_index", |
|
| 333 |
+ [ |
|
| 334 |
+ i |
|
| 335 |
+ for i, x in enumerate(data.ALL_KEYS.values(), start=1) |
|
| 336 |
+ if x.is_suitable() |
|
| 337 |
+ ], |
|
| 338 |
+ ids=lambda i: f"index{i}",
|
|
| 333 | 339 |
) |
| 334 | 340 |
EXPLICIT_SSH_AGENT_SOCKET_PROVIDER = pytest.mark.parametrize( |
| 335 | 341 |
["on_command_line", "in_config"], |
| ... | ... |
@@ -363,7 +369,7 @@ class Parametrize(types.SimpleNamespace): |
| 363 | 369 |
], |
| 364 | 370 |
) |
| 365 | 371 |
OPTION_COMBINATIONS_SERVICE_NEEDED = pytest.mark.parametrize( |
| 366 |
- ["options", "service", "input", "check_success"], |
|
| 372 |
+ ["options", "needs_service", "input", "check_success"], |
|
| 367 | 373 |
[ |
| 368 | 374 |
pytest.param( |
| 369 | 375 |
o.options, |
| ... | ... |
@@ -975,7 +981,7 @@ class TestInvalidCommandLines: |
| 975 | 981 |
def test_service_needed( |
| 976 | 982 |
self, |
| 977 | 983 |
options: list[str], |
| 978 |
- service: bool | None, |
|
| 984 |
+ needs_service: bool | None, |
|
| 979 | 985 |
input: str | None, |
| 980 | 986 |
check_success: bool, |
| 981 | 987 |
) -> None: |
| ... | ... |
@@ -985,14 +991,14 @@ class TestInvalidCommandLines: |
| 985 | 991 |
"services": {},
|
| 986 | 992 |
} |
| 987 | 993 |
result = self._call( |
| 988 |
- options if service else [*options, "--", DUMMY_SERVICE], |
|
| 994 |
+ options if needs_service else [*options, "--", DUMMY_SERVICE], |
|
| 989 | 995 |
config=config, |
| 990 | 996 |
input=input, |
| 991 | 997 |
) |
| 992 |
- if service is not None: |
|
| 998 |
+ if needs_service is not None: |
|
| 993 | 999 |
err_msg = ( |
| 994 | 1000 |
" requires a SERVICE" |
| 995 |
- if service |
|
| 1001 |
+ if needs_service |
|
| 996 | 1002 |
else " does not take a SERVICE argument" |
| 997 | 1003 |
) |
| 998 | 1004 |
assert result.error_exit(error=err_msg), ( |
| ... | ... |
@@ -1000,7 +1006,9 @@ class TestInvalidCommandLines: |
| 1000 | 1006 |
) |
| 1001 | 1007 |
if check_success: |
| 1002 | 1008 |
result = self._call( |
| 1003 |
- [*options, "--", DUMMY_SERVICE] if service else options, |
|
| 1009 |
+ [*options, "--", DUMMY_SERVICE] |
|
| 1010 |
+ if needs_service |
|
| 1011 |
+ else options, |
|
| 1004 | 1012 |
config=config, |
| 1005 | 1013 |
input=input, |
| 1006 | 1014 |
) |
| ... | ... |
@@ -161,13 +161,12 @@ class Parametrize(types.SimpleNamespace): |
| 161 | 161 |
], |
| 162 | 162 |
) |
| 163 | 163 |
SSH_UNSTRING_EXCEPTIONS = pytest.mark.parametrize( |
| 164 |
- ["input", "exc_type", "exc_pattern", "has_trailer", "parts"], |
|
| 164 |
+ ["input", "exc_type", "exc_pattern", "parts"], |
|
| 165 | 165 |
[ |
| 166 | 166 |
pytest.param( |
| 167 | 167 |
b"ssh", |
| 168 | 168 |
ValueError, |
| 169 | 169 |
"malformed SSH byte string", |
| 170 |
- False, |
|
| 171 | 170 |
None, |
| 172 | 171 |
id="unencoded", |
| 173 | 172 |
), |
| ... | ... |
@@ -175,7 +174,6 @@ class Parametrize(types.SimpleNamespace): |
| 175 | 174 |
b"\x00\x00\x00\x08ssh-rsa", |
| 176 | 175 |
ValueError, |
| 177 | 176 |
"malformed SSH byte string", |
| 178 |
- False, |
|
| 179 | 177 |
None, |
| 180 | 178 |
id="truncated", |
| 181 | 179 |
), |
| ... | ... |
@@ -183,7 +181,6 @@ class Parametrize(types.SimpleNamespace): |
| 183 | 181 |
b"\x00\x00\x00\x04XXX trailing text", |
| 184 | 182 |
ValueError, |
| 185 | 183 |
"malformed SSH byte string", |
| 186 |
- True, |
|
| 187 | 184 |
(b"XXX ", b"trailing text"), |
| 188 | 185 |
id="trailing-data", |
| 189 | 186 |
), |
| ... | ... |
@@ -691,19 +688,18 @@ class TestSSHProtocolDatatypes(TestStaticFunctionality): |
| 691 | 688 |
@Parametrize.SSH_UNSTRING_EXCEPTIONS |
| 692 | 689 |
def test_unstring_exceptions( |
| 693 | 690 |
self, |
| 694 |
- input: bytes | bytearray, |
|
| 691 |
+ input: bytes, |
|
| 695 | 692 |
exc_type: type[Exception], |
| 696 | 693 |
exc_pattern: str, |
| 697 |
- has_trailer: bool, |
|
| 698 |
- parts: tuple[bytes | bytearray, bytes | bytearray] | None, |
|
| 694 |
+ parts: tuple[bytes, bytes] | None, |
|
| 699 | 695 |
) -> None: |
| 700 | 696 |
"""SSH string decoding fails for invalid values.""" |
| 701 | 697 |
unstring = ssh_agent.SSHAgentClient.unstring |
| 702 | 698 |
unstring_prefix = ssh_agent.SSHAgentClient.unstring_prefix |
| 703 | 699 |
with pytest.raises(exc_type, match=exc_pattern): |
| 704 | 700 |
unstring(input) |
| 705 |
- if has_trailer: |
|
| 706 |
- assert tuple(bytes(x) for x in unstring_prefix(input)) == parts |
|
| 701 |
+ if parts is not None: |
|
| 702 |
+ assert unstring_prefix(input) == parts |
|
| 707 | 703 |
else: |
| 708 | 704 |
with pytest.raises(exc_type, match=exc_pattern): |
| 709 | 705 |
unstring_prefix(input) |
| ... | ... |
@@ -862,12 +862,9 @@ class TestUtilities(TestVault): |
| 862 | 862 |
def test_binary_strings(self, s: str | bytes | bytearray) -> None: |
| 863 | 863 |
"""Byte string conversion is idempotent.""" |
| 864 | 864 |
binstr = vault.Vault._get_binary_string |
| 865 |
- if isinstance(s, str): |
|
| 866 |
- assert binstr(s) == s.encode("UTF-8")
|
|
| 867 |
- assert binstr(binstr(s)) == s.encode("UTF-8")
|
|
| 868 |
- else: |
|
| 869 |
- assert binstr(s) == bytes(s) |
|
| 870 |
- assert binstr(binstr(s)) == bytes(s) |
|
| 865 |
+ expected = s.encode("UTF-8") if isinstance(s, str) else bytes(s)
|
|
| 866 |
+ assert binstr(s) == expected |
|
| 867 |
+ assert binstr(binstr(s)) == binstr(s) |
|
| 871 | 868 |
|
| 872 | 869 |
def test_too_many_symbols(self) -> None: |
| 873 | 870 |
"""Deriving short passphrases with large length constraints fails.""" |
| 874 | 871 |