Name no node in postgres's, ssh-client's and mesh-mail-web's fixtures (issue 1838)

This commit is contained in:
jochen
2026-10-22 21:44:44 +02:00
parent 098a0f6542
commit c55e705357
12 changed files with 97 additions and 97 deletions
@@ -48,7 +48,7 @@ func keygenStandIn(ctx context.Context, env []string, name string, args ...strin
// 1480/AC1
func TestTheBundlesKeeperIsForgekeysOfKindMachineWithItsEntryAtNodeAccount(t *testing.T) {
home, st := t.TempDir(), &recordState{}
k := keeperFor(home, "g14", "nox", keygenStandIn, st)
k := keeperFor(home, "node-b", "nox", keygenStandIn, st)
k.Now = func() time.Time { return time.Date(2026, 10, 20, 12, 0, 0, 0, time.UTC) }
if err := k.Once(context.Background()); err != nil {
t.Fatal(err)
@@ -56,15 +56,15 @@ func TestTheBundlesKeeperIsForgekeysOfKindMachineWithItsEntryAtNodeAccount(t *te
if _, err := os.Stat(filepath.Join(home, ".ssh", "mesh_ed25519")); err != nil {
t.Errorf("the key file mesh_ed25519 was not made in an empty home: %v", err)
}
raw, ok := st.puts["g14.nox"]
raw, ok := st.puts["node-b.nox"]
if !ok || len(st.puts) != 1 {
t.Fatalf("entries = %v, want one at g14.nox", st.puts)
t.Fatalf("entries = %v, want one at node-b.nox", st.puts)
}
var e forgekey.KeyEntry
if err := json.Unmarshal(raw, &e); err != nil {
t.Fatal(err)
}
if e.Kind != "machine" || e.Node != "g14" || e.Account != "nox" || !strings.HasSuffix(e.Public, " nox@g14 (mesh)") {
if e.Kind != "machine" || e.Node != "node-b" || e.Account != "nox" || !strings.HasSuffix(e.Public, " nox@node-b (mesh)") {
t.Errorf("entry = %s", raw)
}
}
@@ -83,9 +83,9 @@ func client(h string, f *fake) *Client {
// a found predecessor file and a module's drop-in beside it; the operator's lines below.
var layout = map[string]string{
"config": "# BEGIN mesh ssh-client.config\n# the mesh's region\nInclude ~/.ssh/config.d/*\n# END mesh ssh-client.config\n\n" +
"ServerAliveInterval 30\nHost *\n AddKeysToAgent yes\nHost ace\n User wrong\nHost box\n HostName 192.0.2.7\n IdentityFile ~/.ssh/id_box\n",
"config.d/00-mesh": "# Generated by the mesh. Do not edit\n\nHost ace ace.internal\n HostName ace.internal\n User ace\n\nHost shanks shanks.internal\n HostName shanks.internal\n User op\n",
"config.d/mesh": "Host ace\n\tHostName ace.internal\n\tUser ace\n",
"ServerAliveInterval 30\nHost *\n AddKeysToAgent yes\nHost node-a\n User wrong\nHost box\n HostName 192.0.2.7\n IdentityFile ~/.ssh/id_box\n",
"config.d/00-mesh": "# Generated by the mesh. Do not edit\n\nHost node-a node-a.internal\n HostName node-a.internal\n User node-a\n\nHost node-d node-d.internal\n HostName node-d.internal\n User op\n",
"config.d/mesh": "Host node-a\n\tHostName node-a.internal\n\tUser node-a\n",
"config.d/work": "# Generated by the mesh. Do not edit\nHost forge.example\n Port 2222\n",
}
@@ -99,8 +99,8 @@ func TestHostsSayWhereEachCameFromInTheOrderSshReadsThem(t *testing.T) {
for _, s := range got["sections"].([]Section) {
who = append(who, s.Patterns[0]+"@"+s.Source+"/"+s.From)
}
want := []string{"ace@config.d/00-mesh/mesh", "shanks@config.d/00-mesh/mesh", "ace@config.d/mesh/drop-in",
"forge.example@config.d/work/drop-in", "*@config/operator", "ace@config/operator", "box@config/operator"}
want := []string{"node-a@config.d/00-mesh/mesh", "node-d@config.d/00-mesh/mesh", "node-a@config.d/mesh/drop-in",
"forge.example@config.d/work/drop-in", "*@config/operator", "node-a@config/operator", "box@config/operator"}
if !reflect.DeepEqual(who, want) {
t.Fatalf("order/source:\n%v\nwant\n%v", who, want)
}
@@ -108,7 +108,7 @@ func TestHostsSayWhereEachCameFromInTheOrderSshReadsThem(t *testing.T) {
t.Errorf("an operator line after the include read as part of the last included section: %v", got["global"])
}
dups := got["duplicates"].([]map[string]any)
if len(dups) != 1 || dups[0]["host"] != "ace" || dups[0]["wins"] != "config.d/00-mesh:3 (mesh)" {
if len(dups) != 1 || dups[0]["host"] != "node-a" || dups[0]["wins"] != "config.d/00-mesh:3 (mesh)" {
t.Errorf("duplicates: %v", dups)
}
sections := got["sections"].([]Section)
@@ -245,30 +245,30 @@ func TestRevokeKeepsTheFileFirstAndRefusesALockout(t *testing.T) {
func scanOf(host, pub string) string { return host + " " + pub + "\n" }
func TestKnownHostComparesWhatIsKnownWithWhatIsOffered(t *testing.T) {
h := home(t, map[string]string{"config": layout["config"], "known_hosts": "ace.internal " + edPub + "\n"})
h := home(t, map[string]string{"config": layout["config"], "known_hosts": "node-a.internal " + edPub + "\n"})
offered := edPub
f := &fake{answer: func(c call) forgekey.Ran {
switch {
case c.name == "ssh-keygen" && c.args[0] == "-F":
return forgekey.Ran{Stdout: "# Host ace.internal found: line 1\nace.internal " + edPub + "\n"}
return forgekey.Ran{Stdout: "# Host node-a.internal found: line 1\nace.internal " + edPub + "\n"}
case c.name == "ssh-keyscan":
return forgekey.Ran{Stdout: scanOf("ace.internal", offered)}
return forgekey.Ran{Stdout: scanOf("node-a.internal", offered)}
case c.name == "ssh-keygen" && c.args[0] == "-R":
return forgekey.Ran{}
}
return forgekey.Ran{Status: 1}
}}
c := client(h, f)
got, err := c.KnownHost(context.Background(), "ace.internal", 22, false)
got, err := c.KnownHost(context.Background(), "node-a.internal", 22, false)
if err != nil || got["state"] != "matches" {
t.Fatalf("%v %v", got, err)
}
offered = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGZha2VrZXlmYWtla2V5ZmFrZWtleWZha2VrZXlmYWs="
got, _ = c.KnownHost(context.Background(), "ace.internal", 22, false)
got, _ = c.KnownHost(context.Background(), "node-a.internal", 22, false)
if !strings.HasPrefix(got["state"].(string), "changed") {
t.Fatalf("%v", got["state"])
}
got, err = c.KnownHost(context.Background(), "ace.internal", 22, true)
got, err = c.KnownHost(context.Background(), "node-a.internal", 22, true)
if err != nil || got["refreshed"] != true {
t.Fatalf("%v %v", got, err)
}
@@ -278,7 +278,7 @@ func TestKnownHostComparesWhatIsKnownWithWhatIsOffered(t *testing.T) {
}
sawRemove := false
for _, c := range f.recorded() {
if c.name == "ssh-keygen" && reflect.DeepEqual(c.args[:2], []string{"-R", "ace.internal"}) {
if c.name == "ssh-keygen" && reflect.DeepEqual(c.args[:2], []string{"-R", "node-a.internal"}) {
sawRemove = true
}
if c.name == "ssh-keyscan" && !reflect.DeepEqual(c.args[:4], []string{"-T", "5", "-p", "22"}) {
@@ -311,19 +311,19 @@ func TestAnUnreachableHostIsNotRefreshed(t *testing.T) {
}
func TestTestSaysHowItAuthenticatedOrWhyNot(t *testing.T) {
ok := "debug1: Connecting to ace.internal [10.0.0.2] port 22.\ndebug1: Server accepts key: /h/.ssh/id_ed25519 ED25519 " + edFP + "\nAuthenticated to ace.internal ([10.0.0.2]:22) using \"publickey\".\n"
ok := "debug1: Connecting to node-a.internal [10.0.0.2] port 22.\ndebug1: Server accepts key: /h/.ssh/id_ed25519 ED25519 " + edFP + "\nAuthenticated to node-a.internal ([10.0.0.2]:22) using \"publickey\".\n"
f := &fake{answer: func(c call) forgekey.Ran { return forgekey.Ran{Stderr: ok} }}
got, err := client(t.TempDir(), f).Test(context.Background(), "ace")
got, err := client(t.TempDir(), f).Test(context.Background(), "node-a")
if err != nil || got["ok"] != true || got["method"] != "publickey" || got["connected_to"] != "10.0.0.2:22" {
t.Fatalf("%v %v", got, err)
}
args := strings.Join(f.recorded()[0].args, " ")
if !strings.Contains(args, "BatchMode=yes") || !strings.Contains(args, "StrictHostKeyChecking=yes") || !strings.HasSuffix(args, "ace true") {
if !strings.Contains(args, "BatchMode=yes") || !strings.Contains(args, "StrictHostKeyChecking=yes") || !strings.HasSuffix(args, "node-a true") {
t.Fatalf("not a batch test: %s", args)
}
denied := "debug1: Offering public key: /h/.ssh/id_box RSA " + rsaFP + "\nop@ace.internal: Permission denied (publickey).\n"
denied := "debug1: Offering public key: /h/.ssh/id_box RSA " + rsaFP + "\nop@node-a.internal: Permission denied (publickey).\n"
f = &fake{answer: func(c call) forgekey.Ran { return forgekey.Ran{Status: 255, Stderr: denied} }}
got, _ = client(t.TempDir(), f).Test(context.Background(), "ace")
got, _ = client(t.TempDir(), f).Test(context.Background(), "node-a")
if got["ok"] != false || got["why"] != "no key it offered was accepted" || !reflect.DeepEqual(got["offered"], []string{"/h/.ssh/id_box"}) {
t.Fatalf("%v", got)
}
@@ -358,7 +358,7 @@ func TestCheckFindsWhatIsWrongAndSaysWhatItDidNotCheck(t *testing.T) {
}
all := strings.Join(whats, "\n")
for _, want := range []string{"writable by others (0666)", "private key readable by others (0644)", "no passphrase",
"not the first thing in the file", "Host ace is defined 3 times", "RSA of 2048 bits", "not known: the first connection would ask", "config.bak-1"} {
"not the first thing in the file", "Host node-a is defined 3 times", "RSA of 2048 bits", "not known: the first connection would ask", "config.bak-1"} {
if !strings.Contains(all, want) {
t.Errorf("missing %q in:\n%s", want, all)
}
@@ -453,13 +453,13 @@ func TestTheManifestsRegionIsWhatSshReads(t *testing.T) {
if !strings.Contains(region, "Include ~/.ssh/config.d/*") {
t.Fatalf("no include: %q", region)
}
h := home(t, map[string]string{"config": "# BEGIN mesh ssh-client.config\n" + region + "# END mesh ssh-client.config\n\nCompression yes\nHost ace\n User wrong\n",
h := home(t, map[string]string{"config": "# BEGIN mesh ssh-client.config\n" + region + "# END mesh ssh-client.config\n\nCompression yes\nHost node-a\n User wrong\n",
"config.d/00-mesh": layout["config.d/00-mesh"]})
p, err := Parse(h)
if err != nil {
t.Fatal(err)
}
if p.Sections[0].Source != MeshFile || p.Sections[0].Options["user"] != "ace" || len(p.Global) != 1 || !strings.HasSuffix(p.Global[0], " Compression yes") {
if p.Sections[0].Source != MeshFile || p.Sections[0].Options["user"] != "node-a" || len(p.Global) != 1 || !strings.HasSuffix(p.Global[0], " Compression yes") {
t.Fatalf("%+v %v", p.Sections, p.Global)
}
}
@@ -44,7 +44,7 @@ func sweepHome(t *testing.T) (*Client, string) {
put("work_key-cert.pub", "ssh-ed25519-cert-v01@openssh.com AAAAIHNzaC1lZDI1NTE5LWNlcnQtdjAxQG9wZW5zc2guY29t work\n", 0o644)
put("config.bak-20260807-015327", "old\n", 0o600)
put("known_hosts.old", "old\n", 0o644)
put("config.d/mesh", "Host ace\n", 0o600)
put("config.d/mesh", "Host node-a\n", 0o600)
put("removed-hal-20261002/config", "old\n", 0o600)
put("removed-drone-20261004/id_drone", key, 0o600) // a key inside a leftover folder
put("removed-drone-20261004/config", "old\n", 0o600)
@@ -136,7 +136,7 @@ func TestSweepOnceSaysEachMove(t *testing.T) {
func TestSweepLeavesSocketsAndUnreadable(t *testing.T) {
c, dir := sweepHome(t)
sock := filepath.Join(dir, "cm-ace")
sock := filepath.Join(dir, "cm-node-a")
if l, err := net.Listen("unix", sock); err == nil {
defer l.Close()
} else {
@@ -92,12 +92,12 @@ func TestManifestKeepsKeysAndRequiresForgeAccount(t *testing.T) {
// Issue 955, area S3: the three files the forge account fills in — known_hosts, the forge's Host, git's rewrite.
var sampleBound = map[string]string{
"known_host": "[novox.internal]:222 ssh-ed25519 AAAAC3Nza",
"known_host": "[node-c.internal]:222 ssh-ed25519 AAAAC3Nza",
"host_key": "ssh-ed25519 AAAAC3Nza",
"ssh_host": "novox.internal",
"ssh_host": "node-c.internal",
"ssh_alias": "mesh-forge",
"ssh_port": "222",
"ssh_base": "ssh://git@novox.internal:222/",
"ssh_base": "ssh://git@node-c.internal:222/",
"https_base": "https://git.novox.be/",
}
@@ -151,7 +151,7 @@ func TestForgeFilesRenderFromTheBoundValues(t *testing.T) {
if forge["into"] != nil {
t.Errorf("10-forge is a block, want the whole file")
}
want := "Host mesh-forge\n HostName novox.internal\n Port 222\n HostKeyAlias mesh-forge\n User git\n IdentityFile ~/.ssh/mesh_ed25519\n IdentitiesOnly yes\n"
want := "Host mesh-forge\n HostName node-c.internal\n Port 222\n HostKeyAlias mesh-forge\n User git\n IdentityFile ~/.ssh/mesh_ed25519\n IdentitiesOnly yes\n"
if got := renderBound(t, templateText(t, forge)); got != want {
t.Errorf("10-forge = %q, want %q", got, want)
}