Check a single command against the security hook (helper function).
(command: str, should_block: bool)
| 72 | |
| 73 | |
| 74 | def check_hook(command: str, should_block: bool) -> bool: |
| 75 | """Check a single command against the security hook (helper function).""" |
| 76 | input_data = {"tool_name": "Bash", "tool_input": {"command": command}} |
| 77 | result = asyncio.run(bash_security_hook(input_data)) |
| 78 | was_blocked = result.get("decision") == "block" |
| 79 | |
| 80 | if was_blocked == should_block: |
| 81 | status = "PASS" |
| 82 | else: |
| 83 | status = "FAIL" |
| 84 | expected = "blocked" if should_block else "allowed" |
| 85 | actual = "blocked" if was_blocked else "allowed" |
| 86 | reason = result.get("reason", "") |
| 87 | print(f" {status}: {command!r}") |
| 88 | print(f" Expected: {expected}, Got: {actual}") |
| 89 | if reason: |
| 90 | print(f" Reason: {reason}") |
| 91 | return False |
| 92 | |
| 93 | print(f" {status}: {command!r}") |
| 94 | return True |
| 95 | |
| 96 | |
| 97 | def test_extract_commands(): |
no test coverage detected