11#!/usr/bin/env python3
2- """Byte-level tests for the specified C++ command adapter surface."""
2+ """Semantic tests for the specified C++ command adapter surface."""
33
44from __future__ import annotations
55
@@ -22,66 +22,14 @@ def require(condition: bool, message: str) -> None:
2222
2323
2424HELP_TOPICS = (
25- ((), b"""Usage:
26- credbind-ssh-authorized-keys version
27- credbind-ssh-authorized-keys config init --policy-input PATH [OPTIONS]
28- credbind-ssh-authorized-keys config init --deny-all [OPTIONS]
29- credbind-ssh-authorized-keys config check --config PATH
30- credbind-ssh-authorized-keys sshd-config render --config PATH --verifier PATH --command-user USER
31- credbind-ssh-authorized-keys verify --config PATH --user USER --key KEY --key-type TYPE
32-
33- Options:
34- -h, --help Show help.
35- """ ),
36- (("version" ,), b"""Usage:
37- credbind-ssh-authorized-keys version
38-
39- Print version metadata as JSON.
40- """ ),
41- (("config" ,), b"""Usage:
42- credbind-ssh-authorized-keys config init --help
43- credbind-ssh-authorized-keys config check --help
44- """ ),
45- (("config" , "init" ), b"""Usage:
46- credbind-ssh-authorized-keys config init --policy-input PATH [OPTIONS]
47- credbind-ssh-authorized-keys config init --deny-all [OPTIONS]
48-
49- Options:
50- --policy-input PATH Initialize from explicit trust and account policy.
51- --deny-all Initialize an explicit deny-all policy.
52- --clock-skew DURATION Set verifier clock skew.
53- --total-verification-deadline DURATION Set the total verification deadline.
54- --max-token-bytes INTEGER Set the token byte limit.
55- --max-evidence-bytes INTEGER Set the evidence byte limit.
56- --max-ssh-certificate-bytes INTEGER Set the SSH certificate byte limit.
57- --max-offered-key-chars INTEGER Set the offered-key character limit.
58- --max-authorized-keys-output-chars INTEGER Set the authorized-keys output limit.
59- --issuer-key-cache-directory PATH Set the issuer-key cache directory.
60- --issuer-key-cache-maximum-freshness DURATION
61- Set the issuer-key cache freshness limit.
62- --logging-facility FACILITY Set the local syslog facility.
63- --output PATH Atomically write instead of using stdout.
64- --force Replace an existing regular output file.
65- -h, --help Show help.
66- """ ),
67- (("config" , "check" ), b"""Usage:
68- credbind-ssh-authorized-keys config check --config PATH
69-
70- Validate configuration offline without changing it.
71- """ ),
72- (("sshd-config" ,), b"""Usage:
73- credbind-ssh-authorized-keys sshd-config render --help
74- """ ),
75- (("sshd-config" , "render" ), b"""Usage:
76- credbind-ssh-authorized-keys sshd-config render --config PATH --verifier PATH --command-user USER
77-
78- Render the minimal OpenSSH AuthorizedKeysCommand fragment without installing it.
79- """ ),
80- (("verify" ,), b"""Usage:
81- credbind-ssh-authorized-keys verify --config PATH --user USER --key KEY --key-type TYPE
82-
83- Verify one OpenSSH certificate request. Denial produces empty stdout and exit status 0.
84- """ ),
25+ ((), (b"credbind-ssh-authorized-keys" , b"config" , b"verify" )),
26+ (("version" ,), (b"credbind-ssh-authorized-keys version" ,)),
27+ (("config" ,), (b"config init" , b"config check" )),
28+ (("config" , "init" ), (b"config init" , b"--policy-input" , b"--deny-all" )),
29+ (("config" , "check" ), (b"config check" , b"--config" )),
30+ (("sshd-config" ,), (b"sshd-config render" ,)),
31+ (("sshd-config" , "render" ), (b"sshd-config render" , b"--command-user" )),
32+ (("verify" ,), (b"verify" , b"--key-type" )),
8533)
8634
8735
@@ -164,12 +112,13 @@ def main() -> int:
164112 config .write_bytes (sample_config ())
165113 config .chmod (0o600 )
166114
167- for prefix , expected_help in HELP_TOPICS :
115+ for prefix , required_terms in HELP_TOPICS :
168116 for help_flag in ("-h" , "--help" ):
169117 result = invoke (binary , * prefix , help_flag )
170- require ((result .returncode , result .stdout , result .stderr ) ==
171- (0 , expected_help , b"" ),
172- f"exact side-effect-free help for { prefix !r} { help_flag } " )
118+ require (result .returncode == 0 and result .stdout .endswith (b"\n " ) and
119+ result .stderr == b"" and
120+ all (term in result .stdout for term in required_terms ),
121+ f"semantic side-effect-free help for { prefix !r} { help_flag } " )
173122
174123 result = invoke (binary , "config" , "check" , "--config" , str (config ))
175124 require ((result .returncode , result .stdout , result .stderr ) ==
0 commit comments