-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
d761a1f
commit b4f2dcc
Showing
1 changed file
with
28 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
import textwrap | ||
|
||
from pathlib import Path | ||
from sshfs.config import parse_config | ||
|
||
|
||
def make_config(tmpdir, host, source): | ||
with open(tmpdir / "ssh_config", "w") as stream: | ||
def make_config(tmpdir: Path, host: str, source: str): | ||
"""Create and parse an SSH config file for a given host.""" | ||
config_path = tmpdir / "ssh_config" | ||
with config_path.open("w") as stream: | ||
stream.write(textwrap.dedent(source)) | ||
|
||
return parse_config(host=host, config_files=[tmpdir / "ssh_config"]) | ||
|
||
return parse_config(host=host, config_files=[config_path]) | ||
|
||
def test_config(tmpdir): | ||
def test_config(tmpdir: Path): | ||
"""Test parsing of a simple SSH configuration.""" | ||
config = make_config( | ||
tmpdir, | ||
"iterative.ai", | ||
""" | ||
Host iterative.ai | ||
HostName ssh.iterative.ai | ||
User batuhan | ||
Port 888 | ||
IdentityFile ~/.ssh/id_rsa_it | ||
""", | ||
Host iterative.ai | ||
HostName ssh.iterative.ai | ||
User batuhan | ||
Port 888 | ||
IdentityFile ~/.ssh/id_rsa_it | ||
""", | ||
) | ||
|
||
assert config.get("Hostname") == "ssh.iterative.ai" | ||
assert config.get("User") == "batuhan" | ||
assert config.get("Port") == 888 | ||
assert config.get("IdentityFile") == ["~/.ssh/id_rsa_it"] | ||
|
||
|
||
def test_config_expansions(tmpdir): | ||
def test_config_expansions(tmpdir: Path): | ||
"""Test parsing of SSH configuration with ProxyCommand and expansions.""" | ||
config = make_config( | ||
tmpdir, | ||
"base", | ||
""" | ||
Host proxy | ||
User user_proxy | ||
HostName proxy.dvc.org | ||
Host base | ||
User user_base | ||
HostName base.dvc.org | ||
Port 222 | ||
ProxyCommand ssh proxy nc %h %p | ||
""", | ||
Host proxy | ||
User user_proxy | ||
HostName proxy.dvc.org | ||
Host base | ||
User user_base | ||
HostName base.dvc.org | ||
Port 222 | ||
ProxyCommand ssh proxy nc %h %p | ||
""", | ||
) | ||
|
||
assert ( | ||
config.get("ProxyCommand").split() == "ssh proxy nc base.dvc.org 222".split() | ||
) | ||
expected_command = "ssh proxy nc base.dvc.org 222".split() | ||
assert config.get("ProxyCommand").split() == expected_command |