Skip to content
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

Don't correctly parse contain @ ssh password #752

Open
SouthFox-D opened this issue Dec 28, 2023 · 2 comments
Open

Don't correctly parse contain @ ssh password #752

SouthFox-D opened this issue Dec 28, 2023 · 2 comments

Comments

@SouthFox-D
Copy link

version: testinfra-10.0.0

pytest --hosts=ssh://root:foo@bar@192.168.100.1 test.py -vvv

Captured log:

DEBUG testinfra:base.py:328 RUN CommandResult(backend=<testinfra.backend.ssh.SshBackend object at 0x7f1514287490>, exit_status=5, command=b"sshpass -p foo ssh -o User=root -o ConnectTimeout=10 -o ControlMaster=auto -o ControlPersist=60s bar@192.168.100.1 'uname -s'", _stdout=b'', _stderr=b'Permission denied, please try again.\r\n')

@philpep
Copy link
Contributor

philpep commented Dec 28, 2023

Did you try to urlencode the password ? e.g.:

pytest --hosts 'ssh://root:foo%40bar@192.168.100.1' test.py -vvv

@SouthFox-D
Copy link
Author

Did you try to urlencode the password ? e.g.:

pytest --hosts 'ssh://root:foo%40bar@192.168.100.1' test.py -vvv

Thanks, it works, and it works in ansible as well.

But I'm handling passwords via environment variables, so I can't use urlencode anywhere (unless maintained separately).

Is it a good idea to use rspilt instead of spilt for parse_hostspec?

def parse_hostspec(hostspec: str) -> HostSpec:
name = hostspec
port = None
user = None
password = None
if "@" in name:
user, name = name.split("@", 1)

        if "@" in name:
            user, name = name.rsplit("@", 1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants