feat: gpgtools ssh-config-summary - per-host table of gpg-enabled logins (v0.11.0)
- read-only: one row per marker-managed block in ~/.ssh/config (or --config PATH): alias, hostname, user, key id (first 8 chars of the identity's SHA256 fingerprint via ssh-keygen -lf, material digest as fallback), and the fallback identity's name - no managed blocks / missing config: fact + configure_ssh hint, exit 0 always (read-only command) - spec items 2.8 + section 13 first, then tests, then code (SPEC 6.12); 10 new tests (100 in test_gpgtools.py), registry description, README section, CHANGELOG 0.11.0, version pins Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -1029,6 +1029,125 @@ def test_main_initialize_wires_flow(monkeypatch):
|
||||
assert seen["runner"] is gpgtools.run_command
|
||||
|
||||
|
||||
# --- ssh-config-summary (gpgtools spec section 13)
|
||||
|
||||
|
||||
def summary_config(tmp_path):
|
||||
"""A config with one full managed block and one minimal one."""
|
||||
pubkey = tmp_path / "yubikey_auth.pub"
|
||||
fallback = tmp_path / "id_ed25519"
|
||||
full = gpgtools.build_block("vault1", "203.0.113.10", "admin",
|
||||
str(pubkey), str(fallback))
|
||||
minimal = gpgtools.build_block("host1", "host1", None,
|
||||
str(pubkey), None)
|
||||
config = gpgtools.merge_managed_block(
|
||||
gpgtools.merge_managed_block("", "vault1", full),
|
||||
"host1", minimal)
|
||||
return config, pubkey, fallback
|
||||
|
||||
|
||||
def test_parse_managed_blocks_fields(tmp_path):
|
||||
"""Each block yields alias, hostname, user, identities in order."""
|
||||
config, pubkey, fallback = summary_config(tmp_path)
|
||||
blocks = gpgtools.parse_managed_blocks(config)
|
||||
assert [(b.alias, b.hostname, b.user) for b in blocks] == \
|
||||
[("vault1", "203.0.113.10", "admin"), ("host1", "host1", None)]
|
||||
assert blocks[0].identities == (pubkey, fallback)
|
||||
assert blocks[1].identities == (pubkey,)
|
||||
|
||||
|
||||
def test_parse_managed_blocks_without_markers():
|
||||
"""A config without managed blocks parses to an empty list."""
|
||||
assert gpgtools.parse_managed_blocks(
|
||||
"Host other\n HostName 10.0.0.1\n") == []
|
||||
|
||||
|
||||
def test_ssh_key_id_from_ssh_keygen(tmp_path):
|
||||
"""sshd-style ssh-keygen output yields the bare fingerprint."""
|
||||
pubkey = tmp_path / "yubikey_auth.pub"
|
||||
pubkey.write_text(GOOD_KEY + "\n", encoding="utf-8")
|
||||
runner = make_runner({("ssh-keygen", "-lf"):
|
||||
(0, "256 SHA256:AAAA1111BBBB2222 "
|
||||
"cardno:12 (ED25519)\n")})
|
||||
assert gpgtools.ssh_key_id(pubkey, runner) == "AAAA1111BBBB2222"
|
||||
|
||||
|
||||
def test_ssh_key_id_falls_back_to_digest(tmp_path):
|
||||
"""Without ssh-keygen, a readable key yields the material digest."""
|
||||
pubkey = tmp_path / "yubikey_auth.pub"
|
||||
pubkey.write_text(GOOD_KEY + "\n", encoding="utf-8")
|
||||
runner = make_runner({("ssh-keygen", "-lf"): (127, "not found")})
|
||||
digest = gpgtools.material_digest(GOOD_KEY)
|
||||
assert gpgtools.ssh_key_id(pubkey, runner) == digest
|
||||
|
||||
|
||||
def test_ssh_key_id_missing_file(tmp_path):
|
||||
"""A missing identity file yields None (row prints -)."""
|
||||
runner = make_runner({("ssh-keygen", "-lf"): (1, "no such file\n")})
|
||||
assert gpgtools.ssh_key_id(tmp_path / "nope.pub", runner) is None
|
||||
|
||||
|
||||
def test_cmd_summary_prints_the_table(tmp_path, capsys):
|
||||
"""Two blocks render with header, 8-char ids, and fallbacks."""
|
||||
config, pubkey, fallback = summary_config(tmp_path)
|
||||
target = tmp_path / "config"
|
||||
target.write_text(config, encoding="utf-8")
|
||||
runner = make_runner({("ssh-keygen", "-lf"):
|
||||
(0, "256 SHA256:AAAA1111BBBB2222 "
|
||||
"cardno:12 (ED25519)\n")})
|
||||
args = gpgtools.parse_args(["ssh-config-summary",
|
||||
"--config", str(target)])
|
||||
assert gpgtools.cmd_ssh_config_summary(
|
||||
args, runner) == gpgtools.EXIT_OK
|
||||
out = capsys.readouterr().out
|
||||
assert "alias" in out and "hostname" in out and "key id" in out
|
||||
assert "vault1" in out and "203.0.113.10" in out and "admin" in out
|
||||
assert "host1" in out
|
||||
assert "AAAA1111" in out # truncated id
|
||||
assert "BBBB2222" not in out # only the first 8 chars
|
||||
assert fallback.name in out # vault1's fallback
|
||||
assert "-" in out # host1's missing fallback/user
|
||||
|
||||
|
||||
def test_cmd_summary_empty_config(tmp_path, capsys):
|
||||
"""No managed blocks: fact plus configure_ssh hint, exit 0."""
|
||||
target = tmp_path / "config"
|
||||
target.write_text("Host other\n HostName 10.0.0.1\n",
|
||||
encoding="utf-8")
|
||||
args = gpgtools.parse_args(["ssh-config-summary",
|
||||
"--config", str(target)])
|
||||
assert gpgtools.cmd_ssh_config_summary(
|
||||
args, make_runner({})) == gpgtools.EXIT_OK
|
||||
out = capsys.readouterr().out
|
||||
assert "no daedalus gpgtools" in out
|
||||
assert "configure_ssh" in out
|
||||
|
||||
|
||||
def test_cmd_summary_missing_config(tmp_path, capsys):
|
||||
"""A missing config file is the same empty case, exit 0."""
|
||||
args = gpgtools.parse_args(["ssh-config-summary",
|
||||
"--config",
|
||||
str(tmp_path / "nope")])
|
||||
assert gpgtools.cmd_ssh_config_summary(
|
||||
args, make_runner({})) == gpgtools.EXIT_OK
|
||||
assert "no daedalus gpgtools" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_cli_summary_wires_flow(monkeypatch):
|
||||
"""The CLI dispatches the summary with the runner."""
|
||||
seen = {}
|
||||
|
||||
def fake_summary(args, run_cmd):
|
||||
seen["args"] = args
|
||||
seen["runner"] = run_cmd
|
||||
return gpgtools.EXIT_OK
|
||||
|
||||
monkeypatch.setattr(gpgtools, "cmd_ssh_config_summary",
|
||||
fake_summary)
|
||||
assert gpgtools.main(["ssh-config-summary"]) == 0
|
||||
assert seen["runner"] is gpgtools.run_command
|
||||
|
||||
|
||||
# --- configure_ssh: block building, merge, guards, file writes
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user