mariotoffia / FluentDocker

Use docker, docker-compose local and remote in tests and your .NET core/full framework apps via a FluentAPI
Apache License 2.0
1.33k stars 98 forks source link

StreamProcessExecutor fails if SudoMechanism Password is set #241

Open bradapeterson opened 2 years ago

bradapeterson commented 2 years ago

Issue

StreamProcessExecutor fails if SudoMechanism Password is set.

Exception

System.ComponentModel.Win32Exception
An error occurred trying to start process 'echo ******** | sudo -S /usr/bin/docker' with working directory '/mnt/data/dev/fluentdocker.demo/bin/Debug/net6.0'. No such file or directory
   at System.Diagnostics.Process.ForkAndExecProcess(ProcessStartInfo startInfo, String resolvedFilename, String[] argv, String[] envp, String cwd, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at Ductus.FluentDocker.Executors.ConsoleStream`1..ctor(ProcessStartInfo startInfo, IStreamMapper`1 mapper, CancellationToken token)
   at Ductus.FluentDocker.Executors.StreamProcessExecutor`2.Execute(CancellationToken token)

Potential Cause

The ConsoleStream's constructor on line 60 is trying to start a process with a FileName of "echo somepassword | sudo -S /usr/bin/docker... " and no arguments. Source: https://github.com/mariotoffia/FluentDocker/blob/master/Ductus.FluentDocker/Executors/ConsoleStream.cs#L60

The StreamProcessorExecutor does not seem to take the SudoMechanism Password into account, unlike the ProcessExecutor.

The StreamProcessExecutor's constructor:

public StreamProcessExecutor(string command, string arguments, string workingdir = null)
{
    _command = command;
    _arguments = arguments;
    _workingdir = workingdir;
}

Source: https://github.com/mariotoffia/FluentDocker/blob/master/Ductus.FluentDocker/Executors/StreamProcessExecutor.cs

The ProcessExecutor does not seem to have this issue.

The ProcessExecutor's constructor:

public ProcessExecutor(string command, string arguments, string workingdir = null)
{
    _workingdir = workingdir;
    if (command.StartsWith("echo") || command.StartsWith("sudo"))
    {
    _command = CommandExtensions.DefaultShell;
    _arguments = $"-c \"{command} {arguments}\"";

    return;
    }

    _command = command;
    _arguments = arguments;
}

Source: https://github.com/mariotoffia/FluentDocker/blob/master/Ductus.FluentDocker/Executors/ProcessExecutor.cs

mariotoffia commented 2 years ago

Thanks, @bradapeterson for your very well reported bug! I've added it to my TODO list.

Cheers, Mario :)