From 41b64eed71b6f3ed6baa796bf613844862d5fb78 Mon Sep 17 00:00:00 2001 From: Johan Siebens Date: Sat, 10 Feb 2024 15:36:28 +0100 Subject: [PATCH] fix: expired peer missing in peer list --- internal/mapping/poll_net_mapper.go | 3 --- tests/expired_peers_test.go | 25 +++++++++++++++++++++++++ tests/sc/scenario.go | 8 ++++++++ tests/tsn/conditions.go | 11 +++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 tests/expired_peers_test.go diff --git a/internal/mapping/poll_net_mapper.go b/internal/mapping/poll_net_mapper.go index fb0237e..e76584d 100644 --- a/internal/mapping/poll_net_mapper.go +++ b/internal/mapping/poll_net_mapper.go @@ -89,9 +89,6 @@ func (h *PollNetMapper) CreateMapResponse(ctx context.Context, delta bool) (*Map syncedUserIDs := map[tailcfg.UserID]bool{user.ID: true} for _, peer := range candidatePeers { - if peer.IsExpired() { - continue - } if policies.IsValidPeer(m, &peer) || policies.IsValidPeer(&peer, m) { isConnected := h.sessionManager.HasSession(peer.TailnetID, peer.ID) diff --git a/tests/expired_peers_test.go b/tests/expired_peers_test.go new file mode 100644 index 0000000..14d892f --- /dev/null +++ b/tests/expired_peers_test.go @@ -0,0 +1,25 @@ +package tests + +import ( + "github.com/jsiebens/ionscale/tests/sc" + "github.com/jsiebens/ionscale/tests/tsn" + "github.com/stretchr/testify/require" + "testing" +) + +func TestExpiredPeersShouldBeListed(t *testing.T) { + sc.Run(t, func(s *sc.Scenario) { + tailnet := s.CreateTailnet() + key := s.CreateAuthKey(tailnet.Id, true) + + nodeA := s.NewTailscaleNode() + + require.NoError(t, nodeA.Up(key)) + + s.ExpireMachines(tailnet.Id) + + nodeB := s.NewTailscaleNode() + require.NoError(t, nodeB.Up(key)) + require.NoError(t, nodeB.Check(tsn.HasExpiredPeer(nodeA.Hostname()))) + }) +} diff --git a/tests/sc/scenario.go b/tests/sc/scenario.go index 29022b2..9296e8d 100644 --- a/tests/sc/scenario.go +++ b/tests/sc/scenario.go @@ -77,6 +77,14 @@ func (s *Scenario) AuthorizeMachines(tailnetID uint64) { } } +func (s *Scenario) ExpireMachines(tailnetID uint64) { + machines := s.ListMachines(tailnetID) + for _, m := range machines { + _, err := s.ionscaleClient.ExpireMachine(context.Background(), connect.NewRequest(&api.ExpireMachineRequest{MachineId: m.Id})) + require.NoError(s.t, err) + } +} + func (s *Scenario) SetACLPolicy(tailnetID uint64, policy *api.ACLPolicy) { _, err := s.ionscaleClient.SetACLPolicy(context.Background(), connect.NewRequest(&api.SetACLPolicyRequest{TailnetId: tailnetID, Policy: policy})) require.NoError(s.t, err) diff --git a/tests/tsn/conditions.go b/tests/tsn/conditions.go index b23d01d..4187de1 100644 --- a/tests/tsn/conditions.go +++ b/tests/tsn/conditions.go @@ -66,6 +66,17 @@ func PeerCount(expected int) Condition { } } +func HasExpiredPeer(name string) Condition { + return func(status *ipnstate.Status) bool { + for _, peer := range status.Peer { + if strings.HasPrefix(peer.DNSName, name) { + return peer.Expired + } + } + return false + } +} + func HasCapability(capability tailcfg.NodeCapability) Condition { return func(status *ipnstate.Status) bool { self := status.Self