show email alongside CN in TUI main menu cert list

CertInfo.email was already populated from index.txt but never
rendered; add it as a fixed-width column next to CN in the cert
list rows (blank when unknown).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Vlad Doloman
2026-07-08 16:43:29 +03:00
parent f7ce56a6d4
commit 92d512f0d2
2 changed files with 25 additions and 2 deletions

View File

@@ -938,7 +938,7 @@ def show_main_screen(
cert = certs[i] cert = certs[i]
box = "[X]" if cert.cn in checked else "[ ]" box = "[X]" if cert.cn in checked else "[ ]"
lbl = _expiry_label(cert) lbl = _expiry_label(cert)
line = f" {box} {lbl:<18} {cert.cn}" line = f" {box} {lbl:<18} {cert.cn:<20} {cert.email}"
try: try:
stdscr.addstr(row_y, 0, line.ljust(sw - 1)[:sw - 1], sel_attr) stdscr.addstr(row_y, 0, line.ljust(sw - 1)[:sw - 1], sel_attr)
except curses.error: except curses.error:

View File

@@ -28,12 +28,13 @@ from openvpncertupdate import (
# Helpers # Helpers
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
def _cert(cn: str, days_left: int) -> CertInfo: def _cert(cn: str, days_left: int, email: str = "") -> CertInfo:
"""Build a minimal CertInfo; expires value is a plausible UTC datetime.""" """Build a minimal CertInfo; expires value is a plausible UTC datetime."""
return CertInfo( return CertInfo(
cn=cn, cn=cn,
expires=datetime(2030, 1, 1, tzinfo=timezone.utc), expires=datetime(2030, 1, 1, tzinfo=timezone.utc),
days_left=days_left, days_left=days_left,
email=email,
) )
@@ -121,6 +122,28 @@ def test_cursor_row_has_reverse_attribute():
assert alice_calls and not (alice_calls[0].args[3] & _curses.A_REVERSE) assert alice_calls and not (alice_calls[0].args[3] & _curses.A_REVERSE)
def test_cert_row_shows_email():
certs = [_cert("alice", 10, email="alice@example.com"), _cert("bob", 3)]
stdscr = _make_stdscr()
stdscr.getch.side_effect = [ord("q")]
with patch("openvpncertupdate.init_colors"):
show_main_screen(stdscr, certs)
alice_calls = [c for c in stdscr.addstr.call_args_list if "alice" in str(c.args[2])]
assert alice_calls
assert "alice@example.com" in alice_calls[0].args[2]
def test_cert_row_blank_when_no_email():
certs = [_cert("bob", 3)] # email defaults to ""
stdscr = _make_stdscr()
stdscr.getch.side_effect = [ord("q")]
with patch("openvpncertupdate.init_colors"):
show_main_screen(stdscr, certs)
bob_calls = [c for c in stdscr.addstr.call_args_list if "bob" in str(c.args[2])]
assert bob_calls
assert "(none)" not in bob_calls[0].args[2]
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Enter on cert → RENEW_SELECTED # Enter on cert → RENEW_SELECTED
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------