GeezerVison is showing github.com — test(util[lifecycle]): Cover hook command log redaction · tmux-python/tmuxp@250222d
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: tests/test_util.py +26Lines changed: 26 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -213,6 +213,32 @@ def test_run_hook_commands_logs_failure( |
213 | 213 | assert records[0].tmux_exit_code == 7 |
214 | 214 |
|
215 | 215 |
|
| 216 | +def test_run_hook_commands_redacts_logged_command( |
| 217 | + caplog: pytest.LogCaptureFixture, |
| 218 | +) -> None: |
| 219 | + """run_hook_commands() keeps expanded hook commands out of logs.""" |
| 220 | + secret = "secret-token-for-hook-log" |
| 221 | + |
| 222 | + with caplog.at_level(logging.INFO, logger="tmuxp.util"): |
| 223 | + run_hook_commands(f"false # {secret}") |
| 224 | + |
| 225 | + for record in caplog.records: |
| 226 | + assert secret not in record.getMessage() |
| 227 | + assert secret not in str(record.__dict__) |
| 228 | + |
| 229 | + hook_records = [ |
| 230 | + record for record in caplog.records if hasattr(record, "tmux_hook_cmd") |
| 231 | + ] |
| 232 | + assert hook_records |
| 233 | + assert all(record.tmux_hook_cmd == "<redacted>" for record in hook_records) |
| 234 | + |
| 235 | + failure_records = [ |
| 236 | + record for record in caplog.records if hasattr(record, "tmux_exit_code") |
| 237 | + ] |
| 238 | + assert len(failure_records) == 1 |
| 239 | + assert failure_records[0].tmux_exit_code == 1 |
| 240 | + |
| 241 | + |
216 | 242 | def test_get_session_should_default_to_local_attached_session( |
217 | 243 | server: Server, |
218 | 244 | monkeypatch: pytest.MonkeyPatch, |
|