fix(auth): harden diagnostic cleanup races
This commit is contained in:
@@ -4,14 +4,37 @@ package compose
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWindowsTreeKillCommandUsesExactPIDArgumentArray(t *testing.T) {
|
||||
command := windowsTreeKillCommand(context.Background(), 4242)
|
||||
want := []string{"taskkill.exe", "/PID", "4242", "/T", "/F"}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user