From 4414dfcbdc84d2168a43f7376b7a8b092e3d3d81 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sat, 10 May 2025 08:27:47 +0200 Subject: [PATCH] integration: ensure last_seen is set Signed-off-by: Kristoffer Dalby --- integration/auth_key_test.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/integration/auth_key_test.go b/integration/auth_key_test.go index ca5c8d0d..d54ff593 100644 --- a/integration/auth_key_test.go +++ b/integration/auth_key_test.go @@ -9,6 +9,7 @@ import ( "slices" + v1 "github.com/juanfont/headscale/gen/go/headscale/v1" "github.com/juanfont/headscale/integration/hsic" "github.com/juanfont/headscale/integration/tsic" "github.com/samber/lo" @@ -44,6 +45,9 @@ func TestAuthKeyLogoutAndReloginSameUser(t *testing.T) { allClients, err := scenario.ListTailscaleClients() assertNoErrListClients(t, err) + allIps, err := scenario.ListTailscaleClientsIPs() + assertNoErrListClientIPs(t, err) + err = scenario.WaitForTailscaleSync() assertNoErrSync(t, err) @@ -66,6 +70,10 @@ func TestAuthKeyLogoutAndReloginSameUser(t *testing.T) { nodeCountBeforeLogout := len(listNodes) t.Logf("node count before logout: %d", nodeCountBeforeLogout) + for _, node := range listNodes { + assertLastSeenSet(t, node) + } + for _, client := range allClients { err := client.Logout() if err != nil { @@ -78,6 +86,13 @@ func TestAuthKeyLogoutAndReloginSameUser(t *testing.T) { t.Logf("all clients logged out") + listNodes, err = headscale.ListNodes() + require.Equal(t, nodeCountBeforeLogout, len(listNodes)) + + for _, node := range listNodes { + assertLastSeenSet(t, node) + } + // if the server is not running with HTTPS, we have to wait a bit before // reconnection as the newest Tailscale client has a measure that will only // reconnect over HTTPS if they saw a noise connection previously. @@ -105,8 +120,9 @@ func TestAuthKeyLogoutAndReloginSameUser(t *testing.T) { listNodes, err = headscale.ListNodes() require.Equal(t, nodeCountBeforeLogout, len(listNodes)) - allIps, err := scenario.ListTailscaleClientsIPs() - assertNoErrListClientIPs(t, err) + for _, node := range listNodes { + assertLastSeenSet(t, node) + } allAddrs := lo.Map(allIps, func(x netip.Addr, index int) string { return x.String() @@ -137,8 +153,20 @@ func TestAuthKeyLogoutAndReloginSameUser(t *testing.T) { } } } + + listNodes, err = headscale.ListNodes() + require.Equal(t, nodeCountBeforeLogout, len(listNodes)) + for _, node := range listNodes { + assertLastSeenSet(t, node) + } }) } + +} + +func assertLastSeenSet(t *testing.T, node *v1.Node) { + assert.NotNil(t, node) + assert.NotNil(t, node.LastSeen) } // This test will first log in two sets of nodes to two sets of users, then