-
Notifications
You must be signed in to change notification settings - Fork 33
Adds password support #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
known_hosts file.
adding more information to the users dictionary. (The old scheme is also supported, but does not allow for passwords.) Tests were extended to cover users using either passwords or keys with the new scheme.
|
For the purposes of using this with a mock server password credentials seems irrelevant; instead create a set of credentials just for running the tests against, through either or fixture or as a command you invoke via tox prior to running pytest. |
|
Is there a reason as not to merge this? I would be really interested in this feature as well! I just checked and saw the tests failing right now but the fix for them to pass again is very straight forward: diff --git a/mockssh/test_server.py b/mockssh/test_server.py
index 15108b7..1740f53 100644
--- a/mockssh/test_server.py
+++ b/mockssh/test_server.py
@@ -104,6 +104,8 @@ def test_overwrite_handler(server: Server, monkeypatch: MonkeyPatch):
if username == "foo" and password == "bar":
return paramiko.AUTH_SUCCESSFUL
return paramiko.AUTH_FAILED
+ def get_allowed_auths(self, username):
+ return "password"
monkeypatch.setattr(server, 'handler_cls', MyHandler)
with paramiko.SSHClient() as client:
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) |
|
@ut-adamc , I don't see any stand-out issues with the implementation. Can you please update README.rst to include a password example? |
|
@ut-adamc please add documentation for this on the README, the following test case fails: import os
import tempfile
from pytest import yield_fixture
import mockssh
@yield_fixture()
def server():
users = {
"type": "password",
"password": "mypassword",
}
with mockssh.Server(users) as s:
yield s
def test_ssh_session(server):
for uid in server.users:
with server.client(uid) as c:
_, stdout, _ = c.exec_command("ls /")
assert stdout.read()
def test_sftp_session(server):
for uid in server.users:
target_dir = tempfile.mkdtemp()
target_fname = os.path.join(target_dir, "foo")
assert not os.access(target_fname, os.F_OK)
with server.client(uid) as c:
sftp = c.open_sftp()
sftp.put(__file__, target_fname, confirm=True)
assert os.access(target_fname, os.F_OK)outputs: |
|
Also test_overwrite_handler fails |
Useful for those of us who sometimes have password credentials.
I don't know how close this would be to a viable solution, but I wanted to run it by you and get feedback. It works in local testing. It relies on changing the data structure for users to accommodate having more than one kind of credential. See the doc string for UserData in mockssh.server.