package sshx import "testing" func TestParseSSHG(t *testing.T) { // Representative `ssh -G` output (abridged, real keys/casing). out := `host web1 hostname 10.0.0.5 user deploy port 2222 proxyjump bastion identityfile ~/.ssh/id_ed25519 identityfile ~/.ssh/id_rsa userknownhostsfile ~/.ssh/known_hosts ~/.ssh/known_hosts2 stricthostkeychecking accept-new identityagent SSH_AUTH_SOCK ` p := parseSSHG("web1", out) if p.HostName != "10.0.0.5" { t.Errorf("hostname = %q", p.HostName) } if p.User != "deploy" || p.Port != "2222" { t.Errorf("user/port = %q/%q", p.User, p.Port) } if p.ProxyJump != "bastion" { t.Errorf("proxyjump = %q", p.ProxyJump) } if len(p.IdentityFiles) != 2 { t.Errorf("identityfiles = %v", p.IdentityFiles) } if len(p.KnownHostsFile) != 2 { t.Errorf("knownhosts = %v", p.KnownHostsFile) } if p.StrictHostKey != "accept-new" { t.Errorf("stricthostkey = %q", p.StrictHostKey) } if p.Addr() != "10.0.0.5:2222" { t.Errorf("addr = %q", p.Addr()) } } func TestParseSSHGIdentitiesOnly(t *testing.T) { p := parseSSHG("h", "hostname h\nidentitiesonly yes\nidentityfile ~/.ssh/special\n") if !p.IdentitiesOnly { t.Error("identitiesonly yes should parse true") } q := parseSSHG("h", "hostname h\nidentitiesonly no\n") if q.IdentitiesOnly { t.Error("identitiesonly no should parse false") } } func TestParseSSHGProxyJumpNone(t *testing.T) { p := parseSSHG("h", "hostname h.example.com\nproxyjump none\nport 22\n") if p.ProxyJump != "" { t.Errorf("proxyjump 'none' should be empty, got %q", p.ProxyJump) } if p.Addr() != "h.example.com:22" { t.Errorf("addr = %q", p.Addr()) } } func TestParseSSHGFallbackHostname(t *testing.T) { p := parseSSHG("myhost", "user bob\n") if p.HostName != "myhost" { t.Errorf("hostname should fall back to alias, got %q", p.HostName) } }