Fix some windows tests

This commit is contained in:
Viktor Liu
2025-07-03 10:18:08 +02:00
parent 9e51d2e8fb
commit a21f924b26
3 changed files with 9 additions and 3 deletions

View File

@@ -463,7 +463,7 @@ func TestSSHServer_WindowsShellHandling(t *testing.T) {
// Test Windows cmd.exe shell behavior
args := server.getShellCommandArgs("cmd.exe", "echo test")
assert.Equal(t, "cmd.exe", args[0])
assert.Equal(t, "/c", args[1])
assert.Equal(t, "-Command", args[1])
assert.Equal(t, "echo test", args[2])
// Test PowerShell behavior

View File

@@ -378,6 +378,10 @@ func TestCheckPrivileges_ComprehensiveMatrix(t *testing.T) {
}
func TestUsedFallback_MeansNoPrivilegeDropping(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Fallback mechanism is Unix-specific")
}
// Create test scenario where fallback should occur
server := &Server{allowRootLogin: true}

View File

@@ -282,7 +282,8 @@ func createConPtyProcess(commandLine string, userToken windows.Handle, userEnv [
// convertEnvironmentToUTF16 converts environment variables to Windows UTF16 format.
func convertEnvironmentToUTF16(userEnv []string) (*uint16, error) {
if len(userEnv) == 0 {
return nil, ErrEmptyEnvironment
// Return nil pointer for empty environment - Windows API will inherit parent environment
return nil, nil //nolint:nilnil // Intentional nil,nil for empty environment
}
var envUTF16 []uint16
@@ -302,7 +303,8 @@ func convertEnvironmentToUTF16(userEnv []string) (*uint16, error) {
if len(envUTF16) > 0 {
return &envUTF16[0], nil
}
return nil, ErrEmptyEnvironment
// Return nil pointer when no valid environment variables found
return nil, nil //nolint:nilnil // Intentional nil,nil for empty environment
}
// duplicateToPrimaryToken converts an impersonation token to a primary token.