Marco Ricci commited on 2025-01-24 23:20:17
Zeige 2 geänderte Dateien mit 25 Einfügungen und 25 Löschungen.
This includes the JavaScript sources of the broken storeroom sample vault configurations, and all remaining functions in the `tests.conftest` module.
... | ... |
@@ -1304,7 +1304,7 @@ The parsed vault configuration stored in |
1304 | 1304 |
[`VAULT_STOREROOM_CONFIG_ZIPPED`][]. |
1305 | 1305 |
""" |
1306 | 1306 |
|
1307 |
-_VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED_JAVASCRIPT_SOURCE = """ |
|
1307 |
+VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED_JAVASCRIPT_SOURCE = """ |
|
1308 | 1308 |
// Executed in the top-level directory of the vault project code, in Node.js. |
1309 | 1309 |
const storeroom = require('storeroom') |
1310 | 1310 |
const Store = require('./lib/store.js') |
... | ... |
@@ -1360,11 +1360,11 @@ and then encoded in base64. |
1360 | 1360 |
The archive contains a directory `/services/array/` that claims to have |
1361 | 1361 |
two child items 'entry1' and 'entry2', but no such child items are |
1362 | 1362 |
present in the archive. See |
1363 |
-[`_VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED_JAVASCRIPT_SOURCE`][] for |
|
1363 |
+[`VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED_JAVASCRIPT_SOURCE`][] for |
|
1364 | 1364 |
the exact script that created this archive. |
1365 | 1365 |
""" |
1366 | 1366 |
|
1367 |
-_VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED2_JAVASCRIPT_SOURCE = """ |
|
1367 |
+VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED2_JAVASCRIPT_SOURCE = """ |
|
1368 | 1368 |
// Executed in the top-level directory of the vault project code, in Node.js. |
1369 | 1369 |
const storeroom = require('storeroom') |
1370 | 1370 |
const Store = require('./lib/store.js') |
... | ... |
@@ -1424,11 +1424,11 @@ and then encoded in base64. |
1424 | 1424 |
|
1425 | 1425 |
The archive contains a directory `/services/array/` whose list of child |
1426 | 1426 |
items does not adhere to the serialization format. See |
1427 |
-[`_VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED2_JAVASCRIPT_SOURCE`][] for |
|
1427 |
+[`VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED2_JAVASCRIPT_SOURCE`][] for |
|
1428 | 1428 |
the exact script that created this archive. |
1429 | 1429 |
""" |
1430 | 1430 |
|
1431 |
-_VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED3_JAVASCRIPT_SOURCE = """ |
|
1431 |
+VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED3_JAVASCRIPT_SOURCE = """ |
|
1432 | 1432 |
// Executed in the top-level directory of the vault project code, in Node.js. |
1433 | 1433 |
const storeroom = require('storeroom') |
1434 | 1434 |
const Store = require('./lib/store.js') |
... | ... |
@@ -1488,11 +1488,11 @@ and then encoded in base64. |
1488 | 1488 |
|
1489 | 1489 |
The archive contains a directory `/services/array/` whose list of child |
1490 | 1490 |
items are not all valid item names. See |
1491 |
-[`_VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED3_JAVASCRIPT_SOURCE`][] for |
|
1491 |
+[`VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED3_JAVASCRIPT_SOURCE`][] for |
|
1492 | 1492 |
the exact script that created this archive. |
1493 | 1493 |
""" |
1494 | 1494 |
|
1495 |
-_VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED4_JAVASCRIPT_SOURCE = """ |
|
1495 |
+VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED4_JAVASCRIPT_SOURCE = """ |
|
1496 | 1496 |
// Executed in the top-level directory of the vault project code, in Node.js. |
1497 | 1497 |
const storeroom = require('storeroom') |
1498 | 1498 |
const Store = require('./lib/store.js') |
... | ... |
@@ -1554,7 +1554,7 @@ and then encoded in base64. |
1554 | 1554 |
The archive contains two directories `/dir/` and `/dir/subdir/`, where |
1555 | 1555 |
`/dir/subdir/` is a correctly serialized directory, but `/dir/` does not |
1556 | 1556 |
contain `/dir/subdir/` in its list of child items. See |
1557 |
-[`_VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED4_JAVASCRIPT_SOURCE`][] for |
|
1557 |
+[`VAULT_STOREROOM_BROKEN_DIR_CONFIG_ZIPPED4_JAVASCRIPT_SOURCE`][] for |
|
1558 | 1558 |
the exact script that created this archive. |
1559 | 1559 |
""" |
1560 | 1560 |
|
... | ... |
@@ -21,7 +21,7 @@ import tests |
21 | 21 |
from derivepassphrase import _types, ssh_agent |
22 | 22 |
|
23 | 23 |
if TYPE_CHECKING: |
24 |
- from collections.abc import Iterator |
|
24 |
+ from collections.abc import Iterator, Sequence |
|
25 | 25 |
|
26 | 26 |
startup_ssh_auth_sock = os.environ.get('SSH_AUTH_SOCK', None) |
27 | 27 |
|
... | ... |
@@ -94,7 +94,7 @@ class SpawnFunc(Protocol): |
94 | 94 |
""" |
95 | 95 |
|
96 | 96 |
|
97 |
-def _spawn_pageant( # pragma: no cover |
|
97 |
+def spawn_pageant( # pragma: no cover |
|
98 | 98 |
executable: str | None, env: dict[str, str] |
99 | 99 |
) -> subprocess.Popen[str] | None: |
100 | 100 |
"""Spawn an isolated Pageant, if possible. |
... | ... |
@@ -166,7 +166,7 @@ def _spawn_pageant( # pragma: no cover |
166 | 166 |
) |
167 | 167 |
|
168 | 168 |
|
169 |
-def _spawn_openssh_agent( # pragma: no cover |
|
169 |
+def spawn_openssh_agent( # pragma: no cover |
|
170 | 170 |
executable: str | None, env: dict[str, str] |
171 | 171 |
) -> subprocess.Popen[str] | None: |
172 | 172 |
"""Spawn an isolated OpenSSH agent, if possible. |
... | ... |
@@ -200,16 +200,16 @@ def _spawn_openssh_agent( # pragma: no cover |
200 | 200 |
) |
201 | 201 |
|
202 | 202 |
|
203 |
-def _spawn_noop( # pragma: no cover |
|
203 |
+def spawn_noop( # pragma: no cover |
|
204 | 204 |
executable: str | None, env: dict[str, str] |
205 | 205 |
) -> None: |
206 | 206 |
"""Placeholder function. Does nothing.""" |
207 | 207 |
|
208 | 208 |
|
209 |
-_spawn_handlers = [ |
|
210 |
- ('pageant', _spawn_pageant, tests.KnownSSHAgent.Pageant), |
|
211 |
- ('ssh-agent', _spawn_openssh_agent, tests.KnownSSHAgent.OpenSSHAgent), |
|
212 |
- ('(system)', _spawn_noop, tests.KnownSSHAgent.UNKNOWN), |
|
209 |
+spawn_handlers: Sequence[tuple[str, SpawnFunc, tests.KnownSSHAgent]] = [ |
|
210 |
+ ('pageant', spawn_pageant, tests.KnownSSHAgent.Pageant), |
|
211 |
+ ('ssh-agent', spawn_openssh_agent, tests.KnownSSHAgent.OpenSSHAgent), |
|
212 |
+ ('(system)', spawn_noop, tests.KnownSSHAgent.UNKNOWN), |
|
213 | 213 |
] |
214 | 214 |
""" |
215 | 215 |
The standard registry of agent spawning functions. |
... | ... |
@@ -219,7 +219,7 @@ Popen = TypeVar('Popen', bound=subprocess.Popen) |
219 | 219 |
|
220 | 220 |
|
221 | 221 |
@contextlib.contextmanager |
222 |
-def _terminate_on_exit(proc: Popen) -> Iterator[Popen]: |
|
222 |
+def terminate_on_exit(proc: Popen) -> Iterator[Popen]: |
|
223 | 223 |
"""Terminate and wait for the subprocess upon exiting the context. |
224 | 224 |
|
225 | 225 |
Args: |
... | ... |
@@ -243,7 +243,7 @@ class CannotSpawnError(RuntimeError): |
243 | 243 |
"""Cannot spawn the SSH agent.""" |
244 | 244 |
|
245 | 245 |
|
246 |
-def _spawn_named_agent( |
|
246 |
+def spawn_named_agent( |
|
247 | 247 |
exec_name: str, |
248 | 248 |
spawn_func: SpawnFunc, |
249 | 249 |
agent_type: tests.KnownSSHAgent, |
... | ... |
@@ -301,13 +301,13 @@ def _spawn_named_agent( |
301 | 301 |
ssh_auth_sock = agent_env.pop('SSH_AUTH_SOCK', None) |
302 | 302 |
proc = spawn_func(executable=shutil.which(exec_name), env=agent_env) |
303 | 303 |
with exit_stack: |
304 |
- if spawn_func is _spawn_noop: |
|
304 |
+ if spawn_func is spawn_noop: |
|
305 | 305 |
ssh_auth_sock = os.environ['SSH_AUTH_SOCK'] |
306 | 306 |
elif proc is None: # pragma: no cover |
307 | 307 |
err_msg = f'Cannot spawn usable {exec_name}' |
308 | 308 |
raise CannotSpawnError(err_msg) |
309 | 309 |
else: |
310 |
- exit_stack.enter_context(_terminate_on_exit(proc)) |
|
310 |
+ exit_stack.enter_context(terminate_on_exit(proc)) |
|
311 | 311 |
assert os.environ.get('SSH_AUTH_SOCK') == startup_ssh_auth_sock, ( |
312 | 312 |
f'SSH_AUTH_SOCK mismatch after spawning {exec_name}' |
313 | 313 |
) |
... | ... |
@@ -334,7 +334,7 @@ def _spawn_named_agent( |
334 | 334 |
) |
335 | 335 |
client.list_keys() # sanity test |
336 | 336 |
yield tests.SpawnedSSHAgentInfo( |
337 |
- agent_type, client, spawn_func is not _spawn_noop |
|
337 |
+ agent_type, client, spawn_func is not spawn_noop |
|
338 | 338 |
) |
339 | 339 |
assert os.environ.get('SSH_AUTH_SOCK', None) == startup_ssh_auth_sock, ( |
340 | 340 |
f'SSH_AUTH_SOCK mismatch after tearing down {exec_name}' |
... | ... |
@@ -379,9 +379,9 @@ def running_ssh_agent( # pragma: no cover |
379 | 379 |
monkeypatch.setenv('SSH_AUTH_SOCK', startup_ssh_auth_sock) |
380 | 380 |
else: |
381 | 381 |
monkeypatch.delenv('SSH_AUTH_SOCK', raising=False) |
382 |
- for exec_name, spawn_func, agent_type in _spawn_handlers: |
|
382 |
+ for exec_name, spawn_func, agent_type in spawn_handlers: |
|
383 | 383 |
try: |
384 |
- for _agent_info in _spawn_named_agent( |
|
384 |
+ for _agent_info in spawn_named_agent( |
|
385 | 385 |
exec_name, spawn_func, agent_type |
386 | 386 |
): |
387 | 387 |
yield tests.RunningSSHAgentInfo( |
... | ... |
@@ -393,7 +393,7 @@ def running_ssh_agent( # pragma: no cover |
393 | 393 |
pytest.skip('No SSH agent running or spawnable') |
394 | 394 |
|
395 | 395 |
|
396 |
-@pytest.fixture(params=_spawn_handlers, ids=operator.itemgetter(0)) |
|
396 |
+@pytest.fixture(params=spawn_handlers, ids=operator.itemgetter(0)) |
|
397 | 397 |
def spawn_ssh_agent( |
398 | 398 |
request: pytest.FixtureRequest, |
399 | 399 |
skip_if_no_af_unix_support: None, |
... | ... |
@@ -429,7 +429,7 @@ def spawn_ssh_agent( |
429 | 429 |
else: # pragma: no cover |
430 | 430 |
monkeypatch.delenv('SSH_AUTH_SOCK', raising=False) |
431 | 431 |
try: |
432 |
- yield from _spawn_named_agent(*request.param) |
|
432 |
+ yield from spawn_named_agent(*request.param) |
|
433 | 433 |
except (KeyError, OSError, CannotSpawnError) as exc: |
434 | 434 |
pytest.skip(exc.args[0]) |
435 | 435 |
return |
436 | 436 |