createKnownHostsEntry creates a known_hosts entry for a given host and key
(t *testing.T, knownHostsPath string, host string, key ssh.PublicKey)
| 192 | |
| 193 | // createKnownHostsEntry creates a known_hosts entry for a given host and key |
| 194 | func createKnownHostsEntry(t *testing.T, knownHostsPath string, host string, key ssh.PublicKey) { |
| 195 | line := knownhosts.Line([]string{host}, key) |
| 196 | |
| 197 | var existingData []byte |
| 198 | if data, err := os.ReadFile(knownHostsPath); err == nil { |
| 199 | existingData = data |
| 200 | } |
| 201 | |
| 202 | newData := append(existingData, []byte(line+"\n")...) |
| 203 | err := os.WriteFile(knownHostsPath, newData, 0644) |
| 204 | require.NoError(t, err) |
| 205 | } |
| 206 | |
| 207 | func TestSSHKnownHosts(t *testing.T) { |
| 208 | // Test that connections succeed to unknown hosts without modifying known_hosts. |
no test coverage detected