MCPcopy Create free account
hub / github.com/Thunder-Compute/thunder-cli / createKnownHostsEntry

Function createKnownHostsEntry

utils/ssh_test.go:194–205  ·  view source on GitHub ↗

createKnownHostsEntry creates a known_hosts entry for a given host and key

(t *testing.T, knownHostsPath string, host string, key ssh.PublicKey)

Source from the content-addressed store, hash-verified

192
193// createKnownHostsEntry creates a known_hosts entry for a given host and key
194func 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
207func TestSSHKnownHosts(t *testing.T) {
208 // Test that connections succeed to unknown hosts without modifying known_hosts.

Callers 1

TestSSHKnownHostsFunction · 0.85

Calls 2

ReadFileMethod · 0.65
WriteFileMethod · 0.65

Tested by

no test coverage detected