(t *testing.T)
| 55 | } |
| 56 | |
| 57 | func TestAuthFailed(t *testing.T) { |
| 58 | //t.Parallel()() |
| 59 | port := test.GetNextPort(t, "SSH") |
| 60 | server := newServerHelper( |
| 61 | t, |
| 62 | fmt.Sprintf("127.0.0.1:%d", port), |
| 63 | map[string][]byte{ |
| 64 | "foo": []byte("bar"), |
| 65 | }, |
| 66 | map[string]string{}, |
| 67 | ) |
| 68 | hostKey, err := server.start(t) |
| 69 | if err != nil { |
| 70 | assert.Fail(t, "failed to start ssh server", err) |
| 71 | return |
| 72 | } |
| 73 | defer func() { |
| 74 | server.stop() |
| 75 | <-server.shutdownChannel |
| 76 | }() |
| 77 | |
| 78 | sshConfig := &ssh.ClientConfig{ |
| 79 | User: "foo", |
| 80 | Auth: []ssh.AuthMethod{ssh.Password("invalid")}, |
| 81 | } |
| 82 | sshConfig.HostKeyCallback = func(hostname string, remote net.Addr, key ssh.PublicKey) error { |
| 83 | marshaledKey := key.Marshal() |
| 84 | if bytes.Equal(marshaledKey, hostKey) { |
| 85 | return nil |
| 86 | } |
| 87 | return fmt.Errorf("invalid host") |
| 88 | } |
| 89 | |
| 90 | sshConnection, err := ssh.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", port), sshConfig) |
| 91 | if err != nil { |
| 92 | if !strings.Contains(err.Error(), "unable to authenticate") { |
| 93 | assert.Fail(t, "handshake failed for non-auth reasons", err) |
| 94 | } |
| 95 | } else { |
| 96 | _ = sshConnection.Close() |
| 97 | assert.Fail(t, "authentication succeeded", err) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | func TestAuthKeyboardInteractive(t *testing.T) { |
| 102 | //t.Parallel()() |
nothing calls this directly
no test coverage detected