Skip to content

Commit 95f57ff

Browse files
committed
ENH: check-sign command prints a single line result
1 parent dad4696 commit 95f57ff

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

pdfly/check_sign.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,25 @@ def main(filename: Path, pem: Path, verbose: Optional[bool]) -> None:
2424
if len(results) == 0:
2525
raise typer.BadParameter("Signature missing")
2626

27+
details: list[str] = []
2728
for hash_ok, signature_ok, cert_ok in results:
2829
if not signature_ok:
29-
print(f"Signature ok: {signature_ok}", file=sys.stderr)
30+
details.append("Signature not ok")
3031
elif verbose:
31-
print(f"Signature ok: {signature_ok}")
32+
details.append("Signature ok")
3233
if not hash_ok:
33-
print(f"Content hash ok: {hash_ok}", file=sys.stderr)
34+
details.append("Content hash not ok")
3435
elif verbose:
35-
print(f"Content hash ok: {hash_ok}")
36+
details.append("Content hash ok")
3637
if not cert_ok:
37-
print(f"Certificate ok: {cert_ok}", file=sys.stderr)
38+
details.append("Certificate not ok")
3839
elif verbose:
39-
print(f"Certificate ok: {cert_ok}")
40+
details.append("Certificate ok")
4041

42+
details_str = "" if len(details) == 0 else " (" + ", ".join(details) + ")"
4143
for hash_ok, signature_ok, cert_ok in results:
4244
if not signature_ok or not hash_ok or not cert_ok:
43-
print("Failure", file=sys.stderr)
45+
print(f"Check failed{details_str}.", file=sys.stderr)
4446
raise typer.Exit(code=1)
4547

46-
print("Success")
48+
print(f"Check succeeded{details_str}.")

tests/test_check_sign.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def test_check_sign_manipulated_content(capsys, tmp_path):
3636

3737
# Assert
3838
assert exit_code == 1
39-
assert "Content hash ok: False" in captured.err
39+
assert "Check failed" in captured.err
40+
assert "Content hash not ok" in captured.err
4041

4142

4243
def test_check_sign_missing_signature(capsys, tmp_path):
@@ -74,7 +75,8 @@ def test_check_sign_signature_not_matching_to_certificate(capsys, tmp_path):
7475

7576
# Assert
7677
assert exit_code == 1
77-
assert "Certificate ok: False" in captured.err
78+
assert "Check failed" in captured.err
79+
assert "Certificate not ok" in captured.err
7880

7981

8082
def test_check_sign_pem(capsys, tmp_path):

0 commit comments

Comments
 (0)