Test blocklist enforcement in security hook.
()
| 380 | |
| 381 | |
| 382 | def test_blocklist_enforcement(): |
| 383 | """Test blocklist enforcement in security hook.""" |
| 384 | print("\nTesting blocklist enforcement:\n") |
| 385 | passed = 0 |
| 386 | failed = 0 |
| 387 | |
| 388 | # All blocklisted commands should be rejected |
| 389 | for cmd in ["sudo apt install", "shutdown now", "dd if=/dev/zero", "aws s3 ls"]: |
| 390 | input_data = {"tool_name": "Bash", "tool_input": {"command": cmd}} |
| 391 | result = asyncio.run(bash_security_hook(input_data)) |
| 392 | if result.get("decision") == "block": |
| 393 | print(f" PASS: Blocked {cmd.split()[0]}") |
| 394 | passed += 1 |
| 395 | else: |
| 396 | print(f" FAIL: Should block {cmd.split()[0]}") |
| 397 | failed += 1 |
| 398 | |
| 399 | return passed, failed |
| 400 | |
| 401 | |
| 402 | def test_project_commands(): |
no test coverage detected