MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / Connect

Method Connect

internal/sshserver/testClientImpl.go:20–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18}
19
20func (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
43func (t *testClientImpl) MustConnect() TestClientConnection {
44 connection, err := t.Connect()

Callers 1

MustConnectMethod · 0.95

Calls 5

GetAuthMethodsMethod · 0.80
DebugMethod · 0.65
UsernameMethod · 0.65
MarshalMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected