Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions test/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import operator
import os
import tempfile
from io import StringIO

import pytest

Expand Down Expand Up @@ -621,6 +622,25 @@ def test_ssh_hostspec(hostspec, expected):
assert command == expected


def test_paramiko_ssh_config_does_not_override_explicit_user():
import paramiko

from testinfra.backend.paramiko import ParamikoBackend

ssh_config = paramiko.SSHConfig()
ssh_config.parse(StringIO("Host *\n User configuser\n"))

backend = ParamikoBackend("explicit@example.com")
cfg = {"username": backend.host.user}
backend._load_ssh_config(paramiko.SSHClient(), cfg, ssh_config)
assert cfg["username"] == "explicit"

backend = ParamikoBackend("example.com")
cfg = {"username": backend.host.user}
backend._load_ssh_config(paramiko.SSHClient(), cfg, ssh_config)
assert cfg["username"] == "configuser"


def test_get_hosts():
# Hosts returned by get_host must be deduplicated (by name & kwargs) and in
# same order as asked
Expand Down
3 changes: 2 additions & 1 deletion testinfra/backend/paramiko.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def _load_ssh_config(
if key == "hostname":
cfg[key] = value
elif key == "user":
cfg["username"] = value
if cfg.get("username") is None:
cfg["username"] = value
elif key == "port":
cfg[key] = int(value)
elif key == "identityfile":
Expand Down