| 93 | } |
| 94 | |
| 95 | func (u *TestUser) GetAuthMethods() []ssh.AuthMethod { |
| 96 | var result []ssh.AuthMethod |
| 97 | if u.password != "" { |
| 98 | result = append(result, ssh.Password(u.password)) |
| 99 | } |
| 100 | var pubKeys []ssh.Signer |
| 101 | for _, privateKey := range u.privateKeys { |
| 102 | signer, err := ssh.NewSignerFromKey(privateKey) |
| 103 | if err != nil { |
| 104 | panic(err) |
| 105 | } |
| 106 | pubKeys = append(pubKeys, signer) |
| 107 | } |
| 108 | result = append(result, ssh.PublicKeys(pubKeys...)) |
| 109 | |
| 110 | if len(u.keyboardInteractive) > 0 { |
| 111 | result = append(result, ssh.KeyboardInteractive( |
| 112 | func(user, instruction string, questions []string, echos []bool) (answers []string, err error) { |
| 113 | for _, question := range questions { |
| 114 | if answer, ok := u.keyboardInteractive[question]; ok { |
| 115 | answers = append(answers, answer) |
| 116 | } else { |
| 117 | return nil, fmt.Errorf("unexpected keybord-interactive challenge: %s", question) |
| 118 | } |
| 119 | } |
| 120 | return answers, nil |
| 121 | })) |
| 122 | } |
| 123 | return result |
| 124 | } |