41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
//go:build windows
|
|
|
|
package compose
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"path/filepath"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestWindowsTreeKillCommandUsesTrustedAbsoluteSystemPathAndExactPIDArgumentArray(t *testing.T) {
|
|
original := windowsSystemDirectory
|
|
windowsSystemDirectory = func() (string, error) { return `C:\\Windows\\System32`, nil }
|
|
t.Cleanup(func() { windowsSystemDirectory = original })
|
|
|
|
taskkillPath, err := systemTaskkillPath()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !filepath.IsAbs(taskkillPath) {
|
|
t.Fatalf("taskkill path = %q, want absolute trusted system path", taskkillPath)
|
|
}
|
|
command := windowsTreeKillCommand(context.Background(), taskkillPath, 4242)
|
|
want := []string{taskkillPath, "/PID", "4242", "/T", "/F"}
|
|
if !reflect.DeepEqual(command.Args, want) {
|
|
t.Fatalf("taskkill args = %#v, want %#v", command.Args, want)
|
|
}
|
|
}
|
|
|
|
func TestWindowsSystemTaskkillPathRejectsRelativeSystemDirectory(t *testing.T) {
|
|
original := windowsSystemDirectory
|
|
windowsSystemDirectory = func() (string, error) { return `System32`, nil }
|
|
t.Cleanup(func() { windowsSystemDirectory = original })
|
|
|
|
if _, err := systemTaskkillPath(); !errors.Is(err, ErrProcessReap) {
|
|
t.Fatalf("systemTaskkillPath() error = %v, want ErrProcessReap", err)
|
|
}
|
|
}
|