mirror of
https://github.com/juanfont/headscale.git
synced 2026-11-19 11:57:07 +09:00
servertest: replay restarts that send an auth key
tsnet sends TS_AUTHKEY on every start; up --advertise-tags may send none.
This commit is contained in:
1 parent
2765031898
commit
a1f1e30e65
3 files changed
+41
-4
No files matched your search
@@ -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
|
||||
|
||||
@@ -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/") {
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in new issue
Block a user