From f36e6f8702816cc8611e897922d6b0fd427a37a0 Mon Sep 17 00:00:00 2001 From: Ryo Ota Date: Fri, 11 Aug 2023 01:37:40 +0900 Subject: [PATCH] test: use `HostKeyCallback: ssh.InsecureIgnoreHostKey()` --- cmd/root_test.go | 54 ++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/cmd/root_test.go b/cmd/root_test.go index 34de772..27c4b76 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -45,11 +45,9 @@ func TestAllPermissionsAllowed(t *testing.T) { }() waitTCPServer(port) sshClientConfig := &ssh.ClientConfig{ - User: "john", - Auth: []ssh.AuthMethod{ssh.Password("mypassword")}, - HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error { - return nil - }, + User: "john", + Auth: []ssh.AuthMethod{ssh.Password("mypassword")}, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), } address := net.JoinHostPort("127.0.0.1", strconv.Itoa(port)) @@ -77,10 +75,8 @@ func TestEmptyPassword(t *testing.T) { }() waitTCPServer(port) sshClientConfig := &ssh.ClientConfig{ - User: "john", - HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error { - return nil - }, + User: "john", + HostKeyCallback: ssh.InsecureIgnoreHostKey(), } address := net.JoinHostPort("127.0.0.1", strconv.Itoa(port)) @@ -133,11 +129,9 @@ func TestWrongPassword(t *testing.T) { }() waitTCPServer(port) sshClientConfig := &ssh.ClientConfig{ - User: "john", - Auth: []ssh.AuthMethod{ssh.Password("mywrongpassword")}, - HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error { - return nil - }, + User: "john", + Auth: []ssh.AuthMethod{ssh.Password("mywrongpassword")}, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), } address := net.JoinHostPort("127.0.0.1", strconv.Itoa(port)) _, err := ssh.Dial("tcp", address, sshClientConfig) @@ -158,11 +152,9 @@ func TestAllowExecute(t *testing.T) { }() waitTCPServer(port) sshClientConfig := &ssh.ClientConfig{ - User: "john", - Auth: []ssh.AuthMethod{ssh.Password("mypassword")}, - HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error { - return nil - }, + User: "john", + Auth: []ssh.AuthMethod{ssh.Password("mypassword")}, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), } address := net.JoinHostPort("127.0.0.1", strconv.Itoa(port)) client, err := ssh.Dial("tcp", address, sshClientConfig) @@ -189,11 +181,9 @@ func TestAllowTcpipForward(t *testing.T) { }() waitTCPServer(port) sshClientConfig := &ssh.ClientConfig{ - User: "john", - Auth: []ssh.AuthMethod{ssh.Password("mypassword")}, - HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error { - return nil - }, + User: "john", + Auth: []ssh.AuthMethod{ssh.Password("mypassword")}, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), } address := net.JoinHostPort("127.0.0.1", strconv.Itoa(port)) client, err := ssh.Dial("tcp", address, sshClientConfig) @@ -220,11 +210,9 @@ func TestAllowDirectTcpip(t *testing.T) { }() waitTCPServer(port) sshClientConfig := &ssh.ClientConfig{ - User: "john", - Auth: []ssh.AuthMethod{ssh.Password("mypassword")}, - HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error { - return nil - }, + User: "john", + Auth: []ssh.AuthMethod{ssh.Password("mypassword")}, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), } address := net.JoinHostPort("127.0.0.1", strconv.Itoa(port)) client, err := ssh.Dial("tcp", address, sshClientConfig) @@ -251,11 +239,9 @@ func TestAllowSftp(t *testing.T) { }() waitTCPServer(port) sshClientConfig := &ssh.ClientConfig{ - User: "john", - Auth: []ssh.AuthMethod{ssh.Password("mypassword")}, - HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error { - return nil - }, + User: "john", + Auth: []ssh.AuthMethod{ssh.Password("mypassword")}, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), } address := net.JoinHostPort("127.0.0.1", strconv.Itoa(port)) client, err := ssh.Dial("tcp", address, sshClientConfig)