package catalogue import ( "strings" "testing" ) // The ssh-client module, composed as a machine receives it (novox/hq to-be 29): every other node's // Host block written into a marked region of the operator's ~/.ssh/config, owned by the account, // with ~/.ssh created 0700 — the operator's own config kept. func TestSSHClientOwnsTheOperatorsSSHConfig(t *testing.T) { shelf := shelf(catalogueManifest(t, "ssh-client")) got, err := Resolve(shelf, []string{"ssh-client"}, Node{Name: "homer", At: "homer.internal", Account: "jo"}, World{}) if err != nil { t.Fatal(err) } names := map[string]string{"homer.internal": "10.10.0.1", "marge.internal": "10.10.0.2"} out, err := got.Declaration(Rendering{ Names: names, Machines: names, Accounts: map[string]string{"homer": "jo", "marge": "jo"}, Suffix: "internal", }) if err != nil { t.Fatal(err) } by := map[string]map[string]any{} for _, r := range out { by[r["id"].(string)] = r } dir := by["ssh-client.ssh-dir"] if dir == nil || dir["path"] != "/home/jo/.ssh" || dir["owner"] != "jo" || dir["mode"] != "0700" { t.Fatalf("~/.ssh is not created 0700 owned by the account: %v", dir) } cfg := by["ssh-client.fact-ssh-config"] if cfg == nil || cfg["path"] != "/home/jo/.ssh/config" || cfg["owner"] != "jo" || cfg["into"] != "block" { t.Fatalf("the ssh config is not written into the operator's ~/.ssh/config as a region: %v", cfg) } body := cfg["content"].(string) if !strings.Contains(body, "Host marge marge.internal") || !strings.Contains(body, "User jo") { t.Fatalf("the config does not name the peer node and its account:\n%s", body) } if strings.Contains(body, "Host homer ") { t.Fatalf("the config names the machine itself, not only its peers:\n%s", body) } }