/
wax_boy
/
semaphore_custom
Обзор
Документация
Войти
/
wax_boy
/
semaphore_custom
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
pkg/ssh/agent_test.go
92 строки
3 KB
Denis Gukov
fix(ssh): ensure ssh aget socket folder exists
09 июл 2026, 11:38
Не верифицирован
09 июл 2026, 11:38
20ebe7c
Код
Авторство
О чём код?
package ssh import ( "os" "path/filepath" "testing" "github.com/stretchr/testify/require" ) // TestAgent_Listen_CreatesSocketDir tests that Listen() creates the socket's // parent directory if it doesn't exist (e.g. project tmp dir not yet created). func TestAgent_Listen_CreatesSocketDir(t *testing.T) { // Not t.TempDir(): its path exceeds the ~104-byte unix socket limit on macOS. tmp, err := os.MkdirTemp("/tmp", "ssh") require.NoError(t, err) t.Cleanup(func() { os.RemoveAll(tmp) }) //nolint:errcheck agent := Agent{ SocketFile: filepath.Join(tmp, "project_2", "agent.sock"), } err = agent.Listen() require.NoError(t, err) require.NoError(t, agent.Close()) } // TestAgent_Close_WithNilListener tests that Close() doesn't panic when listener is nil func TestAgent_Close_WithNilListener(t *testing.T) { // Create agent with nil listener (simulates failed initialization) agent := Agent{} // This should not panic err := agent.Close() if err != nil { t.Errorf("Expected no error when closing agent with nil listener, got: %v", err) } } // TestAgent_Close_WithNilDone tests that Close() doesn't panic when done channel is nil func TestAgent_Close_WithNilDone(t *testing.T) { // Create agent with nil done channel agent := Agent{ done: nil, } // This should not panic err := agent.Close() if err != nil { t.Errorf("Expected no error when closing agent with nil done channel, got: %v", err) } } // TestAgent_Close_WithAllNil tests that Close() doesn't panic when both fields are nil func TestAgent_Close_WithAllNil(t *testing.T) { // Create completely empty agent (simulates NewAgent() result) agent := NewAgent() // This should not panic err := agent.Close() if err != nil { t.Errorf("Expected no error when closing empty agent, got: %v", err) } } // TestAgent_Close_FailedInitialization simulates the exact scenario from issue #3232 // where agent initialization fails but the agent is still assigned to installation func TestAgent_Close_FailedInitialization(t *testing.T) { // Simulate the scenario described in the issue: // 1. StartSSHAgent() fails during Listen() but returns incomplete agent // 2. Install() method assigns the incomplete agent to installation.SSHAgent // 3. Later, destroyKeys() calls Destroy() which calls Close() on incomplete agent // Create an agent that would be returned by StartSSHAgent() if Listen() failed incompleteAgent := Agent{ Keys: []AgentKey{ { Key: []byte("test-private-key"), Passphrase: []byte(""), }, }, SocketFile: "/tmp/test-socket.sock", // listener and done are nil because Listen() failed } // This simulates the destroyKeys() -> Destroy() -> Close() call chain // that was causing the panic err := incompleteAgent.Close() if err != nil { t.Errorf("Expected no error when closing incomplete agent, got: %v", err) } }