From 0bb84bd03e808854c28f531acfc9f90e6b7fb787 Mon Sep 17 00:00:00 2001 From: vadvolo Date: Mon, 15 Jun 2026 22:48:19 +0100 Subject: [PATCH 1/6] fix proxy jump behavior --- pkg/server/devuath.go | 53 ++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/pkg/server/devuath.go b/pkg/server/devuath.go index fe2184d..cec387f 100644 --- a/pkg/server/devuath.go +++ b/pkg/server/devuath.go @@ -25,31 +25,48 @@ type authApp struct { log *zap.Logger } +type proxyConfig struct { + proxyJump string + controlPath string + connectHost string + ip netip.Addr +} + +func (m authApp) resolveProxyConfig(host string, ip netip.Addr) proxyConfig { + cfg := proxyConfig{ip: ip} + + switch { + case len(m.config.ProxyJump) > 0: + cfg.proxyJump = m.config.ProxyJump + case m.config.SshConfig: + cfg.proxyJump = ssh_config.Get(host, "ProxyJump") + cfg.controlPath = ssh_config.Get(host, "ControlPath") + if realHost := ssh_config.Get(host, "Hostname"); len(realHost) > 0 { + cfg.connectHost = realHost + cfg.ip = netip.Addr{} + } + } + return cfg +} + func (m authApp) GetHostParams(host string, params *pb.HostParams) (hostParams, error) { ip, port, err := makeHostConnectionParams(params) if err != nil { - return hostParams{}, err - } - proxyJump := "" - controlPath := "" - connectHost := "" - if len(m.config.ProxyJump) > 0 { - proxyJump = m.config.ProxyJump - } else if m.config.SshConfig { - proxyJump = ssh_config.Get(host, "ProxyJump") - controlPath = ssh_config.Get(host, "ControlPath") - realHost := ssh_config.Get(host, "Hostname") - if len(realHost) > 0 { - connectHost = realHost - ip = netip.Addr{} - } + return hostParams{}, fmt.Errorf("make host connection params: %w", err) } + + proxyCfg := m.resolveProxyConfig(host, ip) + creds, err := m.Get(host) if err != nil { - return hostParams{}, err + return hostParams{}, fmt.Errorf("get credentials for %q: %w", host, err) } - res := NewHostParams(creds, params.GetDevice(), ip, port, proxyJump, controlPath, connectHost) - return res, nil + + return NewHostParams( + creds, params.GetDevice(), + ip, port, + proxyCfg.proxyJump, proxyCfg.controlPath, proxyCfg.connectHost, + ), nil } func (m authApp) Get(host string) (credentials.Credentials, error) { From 0a4db466c3844195c705d2d567a637552f3c799d Mon Sep 17 00:00:00 2001 From: vadvolo Date: Thu, 2 Jul 2026 16:09:27 +0100 Subject: [PATCH 2/6] update proxy jump behavior --- pkg/server/devuath.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/server/devuath.go b/pkg/server/devuath.go index cec387f..a91d679 100644 --- a/pkg/server/devuath.go +++ b/pkg/server/devuath.go @@ -43,6 +43,7 @@ func (m authApp) resolveProxyConfig(host string, ip netip.Addr) proxyConfig { cfg.controlPath = ssh_config.Get(host, "ControlPath") if realHost := ssh_config.Get(host, "Hostname"); len(realHost) > 0 { cfg.connectHost = realHost + // Clear IP to ensure we connect to Hostname from config, not IP received from client cfg.ip = netip.Addr{} } } @@ -52,10 +53,10 @@ func (m authApp) resolveProxyConfig(host string, ip netip.Addr) proxyConfig { func (m authApp) GetHostParams(host string, params *pb.HostParams) (hostParams, error) { ip, port, err := makeHostConnectionParams(params) if err != nil { - return hostParams{}, fmt.Errorf("make host connection params: %w", err) + return hostParams{}, fmt.Errorf("host connection params: %w", err) } - proxyCfg := m.resolveProxyConfig(host, ip) + cfg := m.resolveProxyConfig(host, ip) creds, err := m.Get(host) if err != nil { @@ -64,8 +65,8 @@ func (m authApp) GetHostParams(host string, params *pb.HostParams) (hostParams, return NewHostParams( creds, params.GetDevice(), - ip, port, - proxyCfg.proxyJump, proxyCfg.controlPath, proxyCfg.connectHost, + cfg.ip, port, + cfg.proxyJump, cfg.controlPath, cfg.connectHost, ), nil } From 4b00cf2187777e7e2c03a545ac5ee38d6795a3c2 Mon Sep 17 00:00:00 2001 From: vadvolo Date: Thu, 2 Jul 2026 16:40:04 +0100 Subject: [PATCH 3/6] add tests --- pkg/server/devuath.go | 7 +- pkg/server/devuath_test.go | 332 +++++++++++++++++++++++++++++++++++++ 2 files changed, 336 insertions(+), 3 deletions(-) create mode 100644 pkg/server/devuath_test.go diff --git a/pkg/server/devuath.go b/pkg/server/devuath.go index a91d679..01409d4 100644 --- a/pkg/server/devuath.go +++ b/pkg/server/devuath.go @@ -35,10 +35,11 @@ type proxyConfig struct { func (m authApp) resolveProxyConfig(host string, ip netip.Addr) proxyConfig { cfg := proxyConfig{ip: ip} - switch { - case len(m.config.ProxyJump) > 0: + // Priority: explicit ProxyJump from app config > SSH config settings + if len(m.config.ProxyJump) > 0 { cfg.proxyJump = m.config.ProxyJump - case m.config.SshConfig: + } else if m.config.SshConfig { + // Read all SSH config settings when enabled cfg.proxyJump = ssh_config.Get(host, "ProxyJump") cfg.controlPath = ssh_config.Get(host, "ControlPath") if realHost := ssh_config.Get(host, "Hostname"); len(realHost) > 0 { diff --git a/pkg/server/devuath_test.go b/pkg/server/devuath_test.go new file mode 100644 index 0000000..c5ab502 --- /dev/null +++ b/pkg/server/devuath_test.go @@ -0,0 +1,332 @@ +package server + +import ( + "net/netip" + "os" + "path/filepath" + "testing" + + pb "github.com/annetutil/gnetcli/pkg/server/proto" + "go.uber.org/zap" +) + +func TestResolveProxyConfig(t *testing.T) { + logger := zap.NewNop() + testIP := netip.MustParseAddr("192.168.1.100") + + tests := []struct { + name string + appConfig authAppConfig + host string + inputIP netip.Addr + expectedConfig proxyConfig + }{ + { + name: "no_ssh_config_no_proxyjump", + appConfig: authAppConfig{ + SshConfig: false, + }, + host: "testhost", + inputIP: testIP, + expectedConfig: proxyConfig{ + ip: testIP, + }, + }, + { + name: "app_config_proxyjump_takes_priority_over_ssh", + appConfig: authAppConfig{ + ProxyJump: "app-proxy-host", + SshConfig: true, + }, + host: "host1", + inputIP: testIP, + expectedConfig: proxyConfig{ + proxyJump: "app-proxy-host", + ip: testIP, + }, + }, + { + name: "app_config_proxyjump_without_ssh_config", + appConfig: authAppConfig{ + ProxyJump: "direct-proxy", + SshConfig: false, + }, + host: "anyhost", + inputIP: testIP, + expectedConfig: proxyConfig{ + proxyJump: "direct-proxy", + ip: testIP, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + app := authApp{ + config: tt.appConfig, + log: logger, + } + + result := app.resolveProxyConfig(tt.host, tt.inputIP) + + // Check each field + if result.proxyJump != tt.expectedConfig.proxyJump { + t.Errorf("proxyJump: got %q, want %q", result.proxyJump, tt.expectedConfig.proxyJump) + } + if result.controlPath != tt.expectedConfig.controlPath { + t.Errorf("controlPath: got %q, want %q", result.controlPath, tt.expectedConfig.controlPath) + } + if result.connectHost != tt.expectedConfig.connectHost { + t.Errorf("connectHost: got %q, want %q", result.connectHost, tt.expectedConfig.connectHost) + } + if result.ip != tt.expectedConfig.ip { + t.Errorf("ip: got %v, want %v", result.ip, tt.expectedConfig.ip) + } + }) + } +} + +func TestResolveProxyConfigWithSSHConfig(t *testing.T) { + // Test configurations as strings + tests := []struct { + name string + sshConfig string + host string + inputIP netip.Addr + expectedConfig proxyConfig + }{ + { + name: "hostname_only_no_proxyjump", + sshConfig: ` +Host test-host1 + Hostname real.server.example.com + User admin + Port 22 +`, + host: "test-host1", + inputIP: netip.MustParseAddr("10.0.0.1"), + expectedConfig: proxyConfig{ + connectHost: "real.server.example.com", + ip: netip.Addr{}, // Should be cleared when Hostname is present + }, + }, + { + name: "test_case_hostname_with_ip", + sshConfig: ` +Host example.com + HostName 194.113.200.100 +`, + host: "example.com", + inputIP: netip.MustParseAddr("10.0.0.10"), + expectedConfig: proxyConfig{ + connectHost: "194.113.200.100", + ip: netip.Addr{}, // Should be cleared when Hostname is present + }, + }, + { + name: "proxyjump_and_hostname", + sshConfig: ` +Host test-host2 + Hostname internal.host.local + ProxyJump jumphost.example.com + ControlPath /tmp/test-ssh-%h-%p + User deploy +`, + host: "test-host2", + inputIP: netip.MustParseAddr("10.0.0.2"), + expectedConfig: proxyConfig{ + proxyJump: "jumphost.example.com", + controlPath: "/tmp/test-ssh-%h-%p", + connectHost: "internal.host.local", + ip: netip.Addr{}, // Should be cleared when Hostname is present + }, + }, + { + name: "proxyjump_only_no_hostname", + sshConfig: ` +Host test-host3 + ProxyJump bastion.example.com + User operator +`, + host: "test-host3", + inputIP: netip.MustParseAddr("10.0.0.3"), + expectedConfig: proxyConfig{ + proxyJump: "bastion.example.com", + ip: netip.MustParseAddr("10.0.0.3"), // Should NOT be cleared (no Hostname) + }, + }, + { + name: "controlpath_only", + sshConfig: ` +Host test-host4 + ControlPath /var/run/ssh-control-%h-%p + ControlMaster auto +`, + host: "test-host4", + inputIP: netip.MustParseAddr("10.0.0.4"), + expectedConfig: proxyConfig{ + controlPath: "/var/run/ssh-control-%h-%p", + ip: netip.MustParseAddr("10.0.0.4"), + }, + }, + { + name: "host_not_in_config", + sshConfig: ` +Host other-host + Hostname other.example.com +`, + host: "unknown-host", + inputIP: netip.MustParseAddr("10.0.0.5"), + expectedConfig: proxyConfig{ + ip: netip.MustParseAddr("10.0.0.5"), + }, + }, + { + name: "wildcard_host_match", + sshConfig: ` +Host *.internal + ProxyJump internal-gateway + Hostname %h.company.local +`, + host: "server1.internal", + inputIP: netip.MustParseAddr("10.0.0.6"), + expectedConfig: proxyConfig{ + proxyJump: "internal-gateway", + connectHost: "server1.internal.company.local", + ip: netip.Addr{}, // Should be cleared + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // Create temporary SSH config file + tmpDir := t.TempDir() + configPath := filepath.Join(tmpDir, "config") + + if err := os.WriteFile(configPath, []byte(tt.sshConfig), 0600); err != nil { + t.Fatalf("Failed to write test SSH config: %v", err) + } + + // Override SSH config path for this test + homeDir, err := os.UserHomeDir() + if err != nil { + t.Skip("Cannot get home directory") + } + + originalConfigPath := filepath.Join(homeDir, ".ssh", "config") + backupPath := originalConfigPath + ".test-backup" + + // Backup existing config if it exists + if _, err := os.Stat(originalConfigPath); err == nil { + if err := os.Rename(originalConfigPath, backupPath); err != nil { + t.Logf("Warning: could not backup SSH config: %v", err) + } else { + defer func() { + if err := os.Rename(backupPath, originalConfigPath); err != nil { + t.Errorf("Failed to restore SSH config: %v", err) + } + }() + } + } + + // Copy test config to SSH config location + sshDir := filepath.Join(homeDir, ".ssh") + if err := os.MkdirAll(sshDir, 0700); err != nil { + t.Skip("Cannot create .ssh directory") + } + + testConfigContent, _ := os.ReadFile(configPath) + if err := os.WriteFile(originalConfigPath, testConfigContent, 0600); err != nil { + t.Skip("Cannot write SSH config") + } + defer os.Remove(originalConfigPath) + + // Run the test + logger := zap.NewNop() + app := authApp{ + config: authAppConfig{ + SshConfig: true, + }, + log: logger, + } + + result := app.resolveProxyConfig(tt.host, tt.inputIP) + + // Verify results + if result.proxyJump != tt.expectedConfig.proxyJump { + t.Errorf("proxyJump: got %q, want %q", result.proxyJump, tt.expectedConfig.proxyJump) + } + if result.controlPath != tt.expectedConfig.controlPath { + t.Errorf("controlPath: got %q, want %q", result.controlPath, tt.expectedConfig.controlPath) + } + if result.connectHost != tt.expectedConfig.connectHost { + t.Errorf("connectHost: got %q, want %q", result.connectHost, tt.expectedConfig.connectHost) + } + if result.ip != tt.expectedConfig.ip { + t.Errorf("ip: got %v, want %v", result.ip, tt.expectedConfig.ip) + } + }) + } +} + +func TestGetHostParams(t *testing.T) { + // Create a temporary directory for test SSH config + tmpDir, err := os.MkdirTemp("", "devuath_test") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpDir) + + // Create a simple SSH config for testing + sshConfigPath := filepath.Join(tmpDir, "config") + sshConfigContent := ` +Host testhost + Hostname actual.server.com + ProxyJump jumpserver +` + if err := os.WriteFile(sshConfigPath, []byte(sshConfigContent), 0600); err != nil { + t.Fatal(err) + } + + // Set SSH_CONFIG environment variable + oldEnv := os.Getenv("SSH_CONFIG") + os.Setenv("SSH_CONFIG", sshConfigPath) + defer os.Setenv("SSH_CONFIG", oldEnv) + + logger := zap.NewNop() + app := authApp{ + config: authAppConfig{ + SshConfig: true, + Login: "testuser", + }, + log: logger, + } + + // Test GetHostParams + params := &pb.HostParams{ + Ip: "10.0.0.1", + Port: 22, + Device: "cisco_ios", + } + + result, err := app.GetHostParams("testhost", params) + if err != nil { + t.Fatalf("GetHostParams failed: %v", err) + } + + // Check that the host field is set to the Hostname from SSH config + if result.host != "actual.server.com" { + t.Errorf("host: got %q, want %q", result.host, "actual.server.com") + } + + // Check that IP is cleared when Hostname is present + if result.ip.IsValid() { + t.Errorf("IP should be cleared when Hostname is present, got: %v", result.ip) + } + + // Check ProxyJump is set + if result.proxyJump != "jumpserver" { + t.Errorf("proxyJump: got %q, want %q", result.proxyJump, "jumpserver") + } +} From db3873aa91ffca98ae164ea0f4156af70d6113f2 Mon Sep 17 00:00:00 2001 From: vadvolo Date: Thu, 2 Jul 2026 16:53:26 +0100 Subject: [PATCH 4/6] add tests --- pkg/server/devuath.go | 20 +++--- pkg/server/devuath_test.go | 135 +++++++++++-------------------------- pkg/server/sshconfig.go | 27 ++++++++ 3 files changed, 77 insertions(+), 105 deletions(-) create mode 100644 pkg/server/sshconfig.go diff --git a/pkg/server/devuath.go b/pkg/server/devuath.go index 01409d4..9683b01 100644 --- a/pkg/server/devuath.go +++ b/pkg/server/devuath.go @@ -7,7 +7,6 @@ import ( "github.com/annetutil/gnetcli/pkg/credentials" pb "github.com/annetutil/gnetcli/pkg/server/proto" - "github.com/kevinburke/ssh_config" "go.uber.org/zap" ) @@ -21,8 +20,9 @@ type authAppConfig struct { } type authApp struct { - config authAppConfig - log *zap.Logger + config authAppConfig + log *zap.Logger + sshConfig sshConfigReader } type proxyConfig struct { @@ -38,11 +38,11 @@ func (m authApp) resolveProxyConfig(host string, ip netip.Addr) proxyConfig { // Priority: explicit ProxyJump from app config > SSH config settings if len(m.config.ProxyJump) > 0 { cfg.proxyJump = m.config.ProxyJump - } else if m.config.SshConfig { + } else if m.config.SshConfig && m.sshConfig != nil { // Read all SSH config settings when enabled - cfg.proxyJump = ssh_config.Get(host, "ProxyJump") - cfg.controlPath = ssh_config.Get(host, "ControlPath") - if realHost := ssh_config.Get(host, "Hostname"); len(realHost) > 0 { + cfg.proxyJump = m.sshConfig.Get(host, "ProxyJump") + cfg.controlPath = m.sshConfig.Get(host, "ControlPath") + if realHost := m.sshConfig.Get(host, "Hostname"); len(realHost) > 0 { cfg.connectHost = realHost // Clear IP to ensure we connect to Hostname from config, not IP received from client cfg.ip = netip.Addr{} @@ -109,5 +109,9 @@ func (m authApp) Get(host string) (credentials.Credentials, error) { } func NewAuthApp(config authAppConfig, logger *zap.Logger) authApp { - return authApp{config: config, log: logger} + return authApp{ + config: config, + log: logger, + sshConfig: realSSHConfigReader{}, + } } diff --git a/pkg/server/devuath_test.go b/pkg/server/devuath_test.go index c5ab502..6600522 100644 --- a/pkg/server/devuath_test.go +++ b/pkg/server/devuath_test.go @@ -86,23 +86,23 @@ func TestResolveProxyConfig(t *testing.T) { } } -func TestResolveProxyConfigWithSSHConfig(t *testing.T) { - // Test configurations as strings +func TestResolveProxyConfigWithMockSSH(t *testing.T) { + logger := zap.NewNop() + tests := []struct { name string - sshConfig string + mockConfigs map[string]map[string]string host string inputIP netip.Addr expectedConfig proxyConfig }{ { name: "hostname_only_no_proxyjump", - sshConfig: ` -Host test-host1 - Hostname real.server.example.com - User admin - Port 22 -`, + mockConfigs: map[string]map[string]string{ + "test-host1": { + "Hostname": "real.server.example.com", + }, + }, host: "test-host1", inputIP: netip.MustParseAddr("10.0.0.1"), expectedConfig: proxyConfig{ @@ -112,10 +112,11 @@ Host test-host1 }, { name: "test_case_hostname_with_ip", - sshConfig: ` -Host example.com - HostName 194.113.200.100 -`, + mockConfigs: map[string]map[string]string{ + "example.com": { + "Hostname": "194.113.200.100", + }, + }, host: "example.com", inputIP: netip.MustParseAddr("10.0.0.10"), expectedConfig: proxyConfig{ @@ -125,13 +126,13 @@ Host example.com }, { name: "proxyjump_and_hostname", - sshConfig: ` -Host test-host2 - Hostname internal.host.local - ProxyJump jumphost.example.com - ControlPath /tmp/test-ssh-%h-%p - User deploy -`, + mockConfigs: map[string]map[string]string{ + "test-host2": { + "Hostname": "internal.host.local", + "ProxyJump": "jumphost.example.com", + "ControlPath": "/tmp/test-ssh-%h-%p", + }, + }, host: "test-host2", inputIP: netip.MustParseAddr("10.0.0.2"), expectedConfig: proxyConfig{ @@ -143,11 +144,11 @@ Host test-host2 }, { name: "proxyjump_only_no_hostname", - sshConfig: ` -Host test-host3 - ProxyJump bastion.example.com - User operator -`, + mockConfigs: map[string]map[string]string{ + "test-host3": { + "ProxyJump": "bastion.example.com", + }, + }, host: "test-host3", inputIP: netip.MustParseAddr("10.0.0.3"), expectedConfig: proxyConfig{ @@ -157,11 +158,11 @@ Host test-host3 }, { name: "controlpath_only", - sshConfig: ` -Host test-host4 - ControlPath /var/run/ssh-control-%h-%p - ControlMaster auto -`, + mockConfigs: map[string]map[string]string{ + "test-host4": { + "ControlPath": "/var/run/ssh-control-%h-%p", + }, + }, host: "test-host4", inputIP: netip.MustParseAddr("10.0.0.4"), expectedConfig: proxyConfig{ @@ -170,85 +171,25 @@ Host test-host4 }, }, { - name: "host_not_in_config", - sshConfig: ` -Host other-host - Hostname other.example.com -`, - host: "unknown-host", - inputIP: netip.MustParseAddr("10.0.0.5"), + name: "host_not_in_config", + mockConfigs: map[string]map[string]string{}, + host: "unknown-host", + inputIP: netip.MustParseAddr("10.0.0.5"), expectedConfig: proxyConfig{ ip: netip.MustParseAddr("10.0.0.5"), }, }, - { - name: "wildcard_host_match", - sshConfig: ` -Host *.internal - ProxyJump internal-gateway - Hostname %h.company.local -`, - host: "server1.internal", - inputIP: netip.MustParseAddr("10.0.0.6"), - expectedConfig: proxyConfig{ - proxyJump: "internal-gateway", - connectHost: "server1.internal.company.local", - ip: netip.Addr{}, // Should be cleared - }, - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - // Create temporary SSH config file - tmpDir := t.TempDir() - configPath := filepath.Join(tmpDir, "config") - - if err := os.WriteFile(configPath, []byte(tt.sshConfig), 0600); err != nil { - t.Fatalf("Failed to write test SSH config: %v", err) - } - - // Override SSH config path for this test - homeDir, err := os.UserHomeDir() - if err != nil { - t.Skip("Cannot get home directory") - } - - originalConfigPath := filepath.Join(homeDir, ".ssh", "config") - backupPath := originalConfigPath + ".test-backup" - - // Backup existing config if it exists - if _, err := os.Stat(originalConfigPath); err == nil { - if err := os.Rename(originalConfigPath, backupPath); err != nil { - t.Logf("Warning: could not backup SSH config: %v", err) - } else { - defer func() { - if err := os.Rename(backupPath, originalConfigPath); err != nil { - t.Errorf("Failed to restore SSH config: %v", err) - } - }() - } - } - - // Copy test config to SSH config location - sshDir := filepath.Join(homeDir, ".ssh") - if err := os.MkdirAll(sshDir, 0700); err != nil { - t.Skip("Cannot create .ssh directory") - } - - testConfigContent, _ := os.ReadFile(configPath) - if err := os.WriteFile(originalConfigPath, testConfigContent, 0600); err != nil { - t.Skip("Cannot write SSH config") - } - defer os.Remove(originalConfigPath) - - // Run the test - logger := zap.NewNop() + mockSSH := mockSSHConfigReader{configs: tt.mockConfigs} app := authApp{ config: authAppConfig{ SshConfig: true, }, - log: logger, + log: logger, + sshConfig: mockSSH, } result := app.resolveProxyConfig(tt.host, tt.inputIP) diff --git a/pkg/server/sshconfig.go b/pkg/server/sshconfig.go new file mode 100644 index 0000000..c190141 --- /dev/null +++ b/pkg/server/sshconfig.go @@ -0,0 +1,27 @@ +package server + +import "github.com/kevinburke/ssh_config" + +// sshConfigReader is an interface for reading SSH config values +type sshConfigReader interface { + Get(host, key string) string +} + +// realSSHConfigReader reads from actual SSH config file +type realSSHConfigReader struct{} + +func (r realSSHConfigReader) Get(host, key string) string { + return ssh_config.Get(host, key) +} + +// mockSSHConfigReader for testing +type mockSSHConfigReader struct { + configs map[string]map[string]string +} + +func (m mockSSHConfigReader) Get(host, key string) string { + if hostConfig, ok := m.configs[host]; ok { + return hostConfig[key] + } + return "" +} From 6941210570d1ca4a5a11e1b049a7b298c741ae5e Mon Sep 17 00:00:00 2001 From: vadvolo Date: Thu, 2 Jul 2026 18:29:17 +0100 Subject: [PATCH 5/6] update tests --- pkg/server/devuath_test.go | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/pkg/server/devuath_test.go b/pkg/server/devuath_test.go index 6600522..069de01 100644 --- a/pkg/server/devuath_test.go +++ b/pkg/server/devuath_test.go @@ -2,8 +2,6 @@ package server import ( "net/netip" - "os" - "path/filepath" "testing" pb "github.com/annetutil/gnetcli/pkg/server/proto" @@ -212,36 +210,25 @@ func TestResolveProxyConfigWithMockSSH(t *testing.T) { } func TestGetHostParams(t *testing.T) { - // Create a temporary directory for test SSH config - tmpDir, err := os.MkdirTemp("", "devuath_test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpDir) + logger := zap.NewNop() - // Create a simple SSH config for testing - sshConfigPath := filepath.Join(tmpDir, "config") - sshConfigContent := ` -Host testhost - Hostname actual.server.com - ProxyJump jumpserver -` - if err := os.WriteFile(sshConfigPath, []byte(sshConfigContent), 0600); err != nil { - t.Fatal(err) + // Setup mock SSH config + mockSSH := mockSSHConfigReader{ + configs: map[string]map[string]string{ + "testhost": { + "Hostname": "actual.server.com", + "ProxyJump": "jumpserver", + }, + }, } - // Set SSH_CONFIG environment variable - oldEnv := os.Getenv("SSH_CONFIG") - os.Setenv("SSH_CONFIG", sshConfigPath) - defer os.Setenv("SSH_CONFIG", oldEnv) - - logger := zap.NewNop() app := authApp{ config: authAppConfig{ SshConfig: true, Login: "testuser", }, - log: logger, + log: logger, + sshConfig: mockSSH, } // Test GetHostParams From b2d423a5ce4329a252f395109a43350988522fd6 Mon Sep 17 00:00:00 2001 From: vadvolo Date: Mon, 6 Jul 2026 15:05:57 +0100 Subject: [PATCH 6/6] add streamer type --- pkg/server/devuath.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/server/devuath.go b/pkg/server/devuath.go index 9683b01..591e2b2 100644 --- a/pkg/server/devuath.go +++ b/pkg/server/devuath.go @@ -68,6 +68,7 @@ func (m authApp) GetHostParams(host string, params *pb.HostParams) (hostParams, creds, params.GetDevice(), cfg.ip, port, cfg.proxyJump, cfg.controlPath, cfg.connectHost, + params.GetStreamerType(), ), nil }