mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-23 13:59:09 +02:00
Fix build
This commit is contained in:
@@ -434,12 +434,6 @@ func (m *Manager) UpdatePeerHostKeys(peerKeys []PeerHostKey) error {
|
|||||||
return fmt.Errorf("setup known_hosts file: %w", err)
|
return fmt.Errorf("setup known_hosts file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read existing entries
|
|
||||||
existingEntries, err := m.readKnownHosts(knownHostsPath)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("read existing known_hosts: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build new entries map for efficient lookup
|
// Build new entries map for efficient lookup
|
||||||
newEntries := make(map[string]string)
|
newEntries := make(map[string]string)
|
||||||
for _, peerKey := range peerKeys {
|
for _, peerKey := range peerKeys {
|
||||||
@@ -471,29 +465,6 @@ func (m *Manager) UpdatePeerHostKeys(peerKeys []PeerHostKey) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// readKnownHosts reads and returns all entries from the known_hosts file
|
|
||||||
func (m *Manager) readKnownHosts(knownHostsPath string) ([]string, error) {
|
|
||||||
file, err := os.Open(knownHostsPath)
|
|
||||||
if err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return []string{}, nil
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("open known_hosts file: %w", err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
var entries []string
|
|
||||||
scanner := bufio.NewScanner(file)
|
|
||||||
for scanner.Scan() {
|
|
||||||
line := strings.TrimSpace(scanner.Text())
|
|
||||||
if line != "" && !strings.HasPrefix(line, "#") {
|
|
||||||
entries = append(entries, line)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return entries, scanner.Err()
|
|
||||||
}
|
|
||||||
|
|
||||||
// formatKnownHostsEntry formats a peer host key as a known_hosts entry
|
// formatKnownHostsEntry formats a peer host key as a known_hosts entry
|
||||||
func (m *Manager) formatKnownHostsEntry(peerKey PeerHostKey) string {
|
func (m *Manager) formatKnownHostsEntry(peerKey PeerHostKey) string {
|
||||||
hostnames := m.getHostnameVariants(peerKey)
|
hostnames := m.getHostnameVariants(peerKey)
|
||||||
|
|||||||
@@ -144,27 +144,6 @@ func TestManager_GetHostnameVariants(t *testing.T) {
|
|||||||
assert.ElementsMatch(t, expectedVariants, variants)
|
assert.ElementsMatch(t, expectedVariants, variants)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestManager_IsNetBirdEntry(t *testing.T) {
|
|
||||||
manager := NewManager()
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
entry string
|
|
||||||
expected bool
|
|
||||||
}{
|
|
||||||
{"100.125.1.1 ssh-ed25519 AAAAC3...", true},
|
|
||||||
{"peer.nb.internal ssh-rsa AAAAB3...", true},
|
|
||||||
{"test.netbird.com ssh-ed25519 AAAAC3...", true},
|
|
||||||
{"github.com ssh-rsa AAAAB3...", false},
|
|
||||||
{"192.168.1.1 ssh-ed25519 AAAAC3...", false},
|
|
||||||
{"example.com ssh-rsa AAAAB3...", false},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
result := manager.isNetBirdEntry(test.entry)
|
|
||||||
assert.Equal(t, test.expected, result, "Entry: %s", test.entry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestManager_FormatKnownHostsEntry(t *testing.T) {
|
func TestManager_FormatKnownHostsEntry(t *testing.T) {
|
||||||
manager := NewManager()
|
manager := NewManager()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user