Test project command validation.
()
| 334 | |
| 335 | |
| 336 | def test_command_validation(): |
| 337 | """Test project command validation.""" |
| 338 | print("\nTesting command validation:\n") |
| 339 | passed = 0 |
| 340 | failed = 0 |
| 341 | |
| 342 | # Test cases: (cmd_config, should_be_valid, description) |
| 343 | test_cases = [ |
| 344 | # Valid commands |
| 345 | ({"name": "swift", "description": "Swift compiler"}, True, "valid command"), |
| 346 | ({"name": "swift"}, True, "command without description"), |
| 347 | ({"name": "swift*", "description": "All Swift tools"}, True, "pattern command"), |
| 348 | ({"name": "./scripts/build.sh", "description": "Build script"}, True, "local script"), |
| 349 | |
| 350 | # Invalid commands |
| 351 | ({}, False, "missing name"), |
| 352 | ({"description": "No name"}, False, "missing name field"), |
| 353 | ({"name": ""}, False, "empty name"), |
| 354 | ({"name": 123}, False, "non-string name"), |
| 355 | |
| 356 | # Security: Bare wildcard not allowed |
| 357 | ({"name": "*"}, False, "bare wildcard rejected"), |
| 358 | |
| 359 | # Blocklisted commands |
| 360 | ({"name": "sudo"}, False, "blocklisted sudo"), |
| 361 | ({"name": "shutdown"}, False, "blocklisted shutdown"), |
| 362 | ({"name": "dd"}, False, "blocklisted dd"), |
| 363 | ] |
| 364 | |
| 365 | for cmd_config, should_be_valid, description in test_cases: |
| 366 | valid, error = validate_project_command(cmd_config) |
| 367 | if valid == should_be_valid: |
| 368 | print(f" PASS: {description}") |
| 369 | passed += 1 |
| 370 | else: |
| 371 | expected = "valid" if should_be_valid else "invalid" |
| 372 | actual = "valid" if valid else "invalid" |
| 373 | print(f" FAIL: {description}") |
| 374 | print(f" Expected: {expected}, Got: {actual}") |
| 375 | if error: |
| 376 | print(f" Error: {error}") |
| 377 | failed += 1 |
| 378 | |
| 379 | return passed, failed |
| 380 | |
| 381 | |
| 382 | def test_blocklist_enforcement(): |
no test coverage detected