carletes / mock-ssh-server

Python mock SSH server for testing purposes
MIT License
56 stars 32 forks source link

Windows support is broken for executing commands received in bytes #22

Open isidentical opened 3 years ago

isidentical commented 3 years ago

I am not sure if there is an explicit windows support (since the CI only tests Linux), but when executing commands it fails with this error;

INFO     asyncssh:logging.py:79 [conn=0, chan=1]   Command: cp '\Users\RUNNER~1\AppData\Local\Temp\dvc-test.6736.o8cti5un.KpcCKHkfHUgi4gWYYHpDcK\.nb8p42n9d235B6AdAhbcQR.tmp' '\Users\RUNNER~1\AppData\Local\Temp\dvc-test.6736.o8cti5un.KpcCKHkfHUgi4gWYYHpDcK\foo'
DEBUG    mockssh.server:server.py:57 Executing b"cp '\\Users\\RUNNER~1\\AppData\\Local\\Temp\\dvc-test.6736.o8cti5un.KpcCKHkfHUgi4gWYYHpDcK\\.nb8p42n9d235B6AdAhbcQR.tmp' '\\Users\\RUNNER~1\\AppData\\Local\\Temp\\dvc-test.6736.o8cti5un.KpcCKHkfHUgi4gWYYHpDcK\\foo'"
ERROR    mockssh.server:server.py:67 Error handling client (channel: <paramiko.Channel 1 (open) window=2097152 -> <paramiko.Transport at 0x430e80a0 (cipher aes256-ctr, 256 bits) (active; 2 open channel(s))>>)
Traceback (most recent call last):
  File "C:\hostedtoolcache\windows\Python\3.9.6\x64\lib\site-packages\mockssh\server.py", line 58, in handle_client
    p = subprocess.Popen(command, shell=True,
  File "C:\hostedtoolcache\windows\Python\3.9.6\x64\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\hostedtoolcache\windows\Python\3.9.6\x64\lib\subprocess.py", line 1352, in _execute_child

I was able to get around it with subclassing the Handler, and adding a .decode() to the handle_client() method. If it is applicable, I can convert it to a PR and submit here.

Spitfire1900 commented 1 year ago

Upvoted, I think a PR is applicable.