I'm using crypto/ssh package and I'm trying to write a unit test for a method that constructs the ClientConfig.
One of the assertions in the unit is that the returned ClientConfig
is deeply equal to the expected.
The assertion fails because both Auth
and HostKeyCallback
fields of ClientConfig
are not deeply equal.
The HostKeyCallback
is hardcoded to be ssh.InsecureIgnoreHostKey()
.
The only authentication method I'm testing right now is with password and I have verified that the password string is picked up correctly.
I tried to mess around in playground (see here) and I don't understand why there is no deep equality in these cases.
package main
import (
"fmt"
"reflect"
"golang.org/x/crypto/ssh"
)
func main() {
pass := "bar"
auth := []ssh.AuthMethod{ssh.Password(pass)}
authLiteral := []ssh.AuthMethod{ssh.Password("bar")}
if reflect.DeepEqual(authLiteral, auth) {
fmt.Println("authentication methods are equal")
} else {
fmt.Println("authentication methods are not equal")
}
callback1 := ssh.InsecureIgnoreHostKey()
callback2 := ssh.InsecureIgnoreHostKey()
if reflect.DeepEqual(callback1, callback2) {
fmt.Println("callbacks are equal")
} else {
fmt.Println("callbacks are not equal")
}
}
authentication methods are not equal
callbacks are not equal
Could someone please explain these results? I would also be grateful if you could suggest how I could unit test this case.