()
| 18 | } |
| 19 | |
| 20 | func (t *testClientImpl) Connect() (TestClientConnection, error) { |
| 21 | t.logger.Debug(messageCodes.NewMessage(messageCodes.MTest, "Connecting SSH server...")) |
| 22 | sshConfig := &ssh.ClientConfig{ |
| 23 | User: t.user.Username(), |
| 24 | Auth: t.user.GetAuthMethods(), |
| 25 | } |
| 26 | sshConfig.HostKeyCallback = func(hostname string, remote net.Addr, key ssh.PublicKey) error { |
| 27 | if bytes.Equal(key.Marshal(), t.hostKey) { |
| 28 | return nil |
| 29 | } |
| 30 | return fmt.Errorf("invalid host") |
| 31 | } |
| 32 | sshConnection, err := ssh.Dial("tcp", t.server, sshConfig) |
| 33 | if err != nil { |
| 34 | return nil, fmt.Errorf("handshake failed (%w)", err) |
| 35 | } |
| 36 | |
| 37 | return &testClientConnectionImpl{ |
| 38 | logger: t.logger, |
| 39 | sshConnection: sshConnection, |
| 40 | }, nil |
| 41 | } |
| 42 | |
| 43 | func (t *testClientImpl) MustConnect() TestClientConnection { |
| 44 | connection, err := t.Connect() |
no test coverage detected