diff --git a/hscontrol/servertest/client.go b/hscontrol/servertest/client.go index 3cbb21a03..3f70e1913 100644 --- a/hscontrol/servertest/client.go +++ b/hscontrol/servertest/client.go @@ -757,9 +757,18 @@ func (c *TestClient) Login( // // Safe to call from non-test goroutines. func (c *TestClient) Restart(ctx context.Context, hi *tailcfg.Hostinfo) error { + return c.RestartWithKey(ctx, "", hi) +} + +// RestartWithKey is [TestClient.Restart] for a client that hands authKey to +// its backend on every start, as a tsnet program does with TS_AUTHKEY: the +// key goes out under the node key the client already has. +// +// Safe to call from non-test goroutines. +func (c *TestClient) RestartWithKey(ctx context.Context, authKey string, hi *tailcfg.Hostinfo) error { c.discoKey = key.NewDisco().Public() - return c.Login(ctx, c.Persist(), "", controlclient.LoginDefault, hi, nil) + return c.Login(ctx, c.Persist(), authKey, controlclient.LoginDefault, hi, nil) } // RotateDisco gives the client a new disco key and reports it, then logs in diff --git a/hscontrol/servertest/reauth_compat_test.go b/hscontrol/servertest/reauth_compat_test.go index 25607b812..7a1271d1c 100644 --- a/hscontrol/servertest/reauth_compat_test.go +++ b/hscontrol/servertest/reauth_compat_test.go @@ -432,7 +432,14 @@ func stepCells(step testcapture.Step) ([]string, map[string]testcapture.Action) case "join", "relogin", "login", "switch_profile": add(a.Node) logins[a.Node] = a - case "restart", "cli", "logout": + case "restart": + add(a.Node) + + // A tsnet program logs in with its key on every start. + if a.Key != "" { + logins[a.Node] = a + } + case "cli", "logout": add(a.Node) case "api": if strings.HasPrefix(a.Path, "/device/") { diff --git a/hscontrol/servertest/via_ha_compat_test.go b/hscontrol/servertest/via_ha_compat_test.go index 184b9473f..53afe49be 100644 --- a/hscontrol/servertest/via_ha_compat_test.go +++ b/hscontrol/servertest/via_ha_compat_test.go @@ -814,7 +814,11 @@ func (r *stepReplay) apply(t *testing.T, step testcapture.Step) map[string]error if r.interactive != nil && r.interactive(step, a) { err = cl.Login(ctx, cl.Persist(), "", controlclient.LoginInteractive, hi.Clone(), r.approver(ctx, t, a.Key)) } else { - require.Contains(t, r.keys, a.Key, "%s: relogin with unknown key", step.Name) + // No key: `tailscale up --advertise-tags` on a running node. + if a.Key != "" { + require.Contains(t, r.keys, a.Key, "%s: relogin with unknown key", step.Name) + } + err = cl.Relogin(ctx, r.keys[a.Key], a.Force, hi.Clone()) } @@ -859,7 +863,24 @@ func (r *stepReplay) apply(t *testing.T, step testcapture.Step) map[string]error refused[a.Node] = err } - case "restart", "start", "kill", "shutdown", "logout", "advertise", "set_hostname", + case "restart": + if a.Key == "" { + r.daemon(ctx, t, step.Name, a) + + continue + } + + // A tsnet program hands its auth key to the backend on every start. + require.Contains(t, r.keys, a.Key, "%s: restart with unknown key", step.Name) + + err := r.clients[a.Node].RestartWithKey(ctx, r.keys[a.Key], r.hostinfo[a.Node].Clone()) + if err != nil { + refused[a.Node] = err + } + + r.remember(a.Node) + + case "start", "kill", "shutdown", "logout", "advertise", "set_hostname", "break_tcp_conns", "rotate_disco_key", "cli", "disconnect_control", "down", "up": r.daemon(ctx, t, step.Name, a)