2026-04-04 22:24:56 -03:00
|
|
|
package sshutil
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
2026-04-09 01:38:06 -03:00
|
|
|
// TestIsHostKeyErrorDetectsMismatch runs one orchestration or CLI step.
|
|
|
|
|
// Signature: TestIsHostKeyErrorDetectsMismatch(t *testing.T).
|
|
|
|
|
// Why: keeps behavior explicit so startup/shutdown workflows remain maintainable as services evolve.
|
2026-04-04 22:24:56 -03:00
|
|
|
func TestIsHostKeyErrorDetectsMismatch(t *testing.T) {
|
|
|
|
|
out := "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!"
|
|
|
|
|
if !IsHostKeyError(out, errors.New("ssh failed")) {
|
|
|
|
|
t.Fatalf("expected host-key mismatch to be detected")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-09 01:38:06 -03:00
|
|
|
// TestIsHostKeyErrorIgnoresGenericFailures runs one orchestration or CLI step.
|
|
|
|
|
// Signature: TestIsHostKeyErrorIgnoresGenericFailures(t *testing.T).
|
|
|
|
|
// Why: keeps behavior explicit so startup/shutdown workflows remain maintainable as services evolve.
|
2026-04-04 22:24:56 -03:00
|
|
|
func TestIsHostKeyErrorIgnoresGenericFailures(t *testing.T) {
|
|
|
|
|
out := "connection timed out"
|
|
|
|
|
if IsHostKeyError(out, errors.New("ssh failed")) {
|
|
|
|
|
t.Fatalf("did not expect host-key mismatch for generic timeout")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-09 01:38:06 -03:00
|
|
|
// TestShouldAttemptKnownHostsRepairOnSilent255 runs one orchestration or CLI step.
|
|
|
|
|
// Signature: TestShouldAttemptKnownHostsRepairOnSilent255(t *testing.T).
|
|
|
|
|
// Why: keeps behavior explicit so startup/shutdown workflows remain maintainable as services evolve.
|
2026-04-04 22:40:39 -03:00
|
|
|
func TestShouldAttemptKnownHostsRepairOnSilent255(t *testing.T) {
|
|
|
|
|
if !ShouldAttemptKnownHostsRepair("", errors.New("ssh ...: exit status 255")) {
|
|
|
|
|
t.Fatalf("expected silent exit status 255 to trigger known_hosts repair")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-09 01:38:06 -03:00
|
|
|
// TestKnownHostsFilesIncludesDerivedPaths runs one orchestration or CLI step.
|
|
|
|
|
// Signature: TestKnownHostsFilesIncludesDerivedPaths(t *testing.T).
|
|
|
|
|
// Why: keeps behavior explicit so startup/shutdown workflows remain maintainable as services evolve.
|
2026-04-04 22:24:56 -03:00
|
|
|
func TestKnownHostsFilesIncludesDerivedPaths(t *testing.T) {
|
|
|
|
|
configFile := "/home/atlas/.ssh/config"
|
|
|
|
|
identityFile := "/home/tethys/.ssh/id_ed25519"
|
|
|
|
|
files := KnownHostsFiles(configFile, identityFile)
|
|
|
|
|
set := map[string]struct{}{}
|
|
|
|
|
for _, f := range files {
|
|
|
|
|
set[f] = struct{}{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
want := []string{
|
|
|
|
|
"/home/atlas/.ssh/known_hosts",
|
|
|
|
|
"/home/tethys/.ssh/known_hosts",
|
|
|
|
|
filepath.Join(filepath.Dir(configFile), "known_hosts"),
|
|
|
|
|
filepath.Join(filepath.Dir(identityFile), "known_hosts"),
|
|
|
|
|
}
|
|
|
|
|
for _, path := range want {
|
|
|
|
|
if _, ok := set[path]; !ok {
|
|
|
|
|
t.Fatalf("expected known_hosts candidate %s", path)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|