87 lines
1.5 KiB
Python
87 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from sshctl.core.config import SshctlConfig
|
|
from sshctl.core.models import HostBlock
|
|
|
|
|
|
@pytest.fixture
|
|
def ssh_dir(tmp_path: Path) -> Path:
|
|
d = tmp_path / ".ssh"
|
|
d.mkdir()
|
|
return d
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_config(ssh_dir: Path) -> Path:
|
|
content = """Host *
|
|
User root
|
|
Port 22
|
|
StrictHostKeyChecking accept-new
|
|
|
|
Host server1
|
|
HostName 10.0.0.1
|
|
User admin
|
|
Port 2222
|
|
|
|
Host server2
|
|
HostName 10.0.0.2
|
|
ProxyJump server1
|
|
|
|
Host *.example.com
|
|
HostName example.com
|
|
User deploy
|
|
"""
|
|
path = ssh_dir / "config"
|
|
path.write_text(content)
|
|
return path
|
|
|
|
|
|
@pytest.fixture
|
|
def config_with_includes(ssh_dir: Path) -> Path:
|
|
conf_d = ssh_dir / "conf.d"
|
|
conf_d.mkdir()
|
|
|
|
jumps = conf_d / "98-jumpservers.conf"
|
|
jumps.write_text("""Host gw
|
|
HostName 10.0.0.254
|
|
User jumpuser
|
|
""")
|
|
|
|
creds = conf_d / "99-cred.conf"
|
|
creds.write_text("""Host *
|
|
IdentityFile ~/.ssh/keys.d/fallback
|
|
""")
|
|
|
|
main = ssh_dir / "config"
|
|
main.write_text("""Host *
|
|
User root
|
|
Port 22
|
|
|
|
Include conf.d/98-jumpservers.conf
|
|
Include conf.d/99-cred.conf
|
|
|
|
Host app1
|
|
HostName 10.0.0.10
|
|
ProxyJump gw
|
|
""")
|
|
return main
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_host() -> HostBlock:
|
|
host = HostBlock(alias="test-box")
|
|
host.set("HostName", "10.0.0.1")
|
|
host.set("User", "admin")
|
|
host.set("Port", "2222")
|
|
host.set("ProxyJump", "gw")
|
|
return host
|
|
|
|
|
|
@pytest.fixture
|
|
def cfg() -> SshctlConfig:
|
|
return SshctlConfig()
|