shell: support Windows cmd /C; normalize date/time; allow all commands; add tests
This commit is contained in:
42
tools/shell/shell_test.go
Normal file
42
tools/shell/shell_test.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestCallRejectsEmptyCommand(t *testing.T) {
|
||||
tool := New([]string{"echo"}, ".", time.Second, 4000, nil)
|
||||
_, err := tool.Call(context.Background(), " ")
|
||||
if err == nil {
|
||||
t.Fatal("expected error for empty command")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallAllowsNonAllowlistedCommand(t *testing.T) {
|
||||
tool := New([]string{"echo"}, ".", time.Second, 4000, nil)
|
||||
out, err := tool.Call(context.Background(), "go version")
|
||||
if err != nil {
|
||||
t.Fatalf("expected command to run without allowlist restriction, got err=%v", err)
|
||||
}
|
||||
if out == "" {
|
||||
t.Fatal("expected non-empty output")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallWindowsDateIsNonInteractive(t *testing.T) {
|
||||
if runtime.GOOS != "windows" {
|
||||
t.Skip("windows-only test")
|
||||
}
|
||||
tool := New(nil, ".", 3*time.Second, 4000, nil)
|
||||
out, err := tool.Call(context.Background(), "date")
|
||||
if err != nil {
|
||||
t.Fatalf("expected bare date command to succeed on windows, got err=%v output=%q", err, out)
|
||||
}
|
||||
if strings.TrimSpace(out) == "" {
|
||||
t.Fatal("expected non-empty output for date command")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user