MCPcopy
hub / github.com/juanfont/headscale / assertValidNetmap

Function assertValidNetmap

integration/helpers.go:763–819  ·  view source on GitHub ↗

assertValidNetmap validates that a client's netmap has all required fields for proper operation. Checks self node and all peers for essential networking data including hostinfo, addresses, endpoints, and DERP configuration. Skips validation for Tailscale versions below 1.56. This test is not suitabl

(t *testing.T, client TailscaleClient)

Source from the content-addressed store, hash-verified

761//
762//nolint:unused
763func assertValidNetmap(t *testing.T, client TailscaleClient) {
764 t.Helper()
765
766 if !util.TailscaleVersionNewerOrEqual("1.56", client.Version()) {
767 t.Logf("%q has version %q, skipping netmap check...", client.Hostname(), client.Version())
768
769 return
770 }
771
772 t.Logf("Checking netmap of %q", client.Hostname())
773
774 assert.EventuallyWithT(t, func(c *assert.CollectT) {
775 netmap, err := client.Netmap()
776 assert.NoError(c, err, "getting netmap for %q", client.Hostname())
777
778 assert.Truef(c, netmap.SelfNode.Hostinfo().Valid(), "%q does not have Hostinfo", client.Hostname())
779
780 if hi := netmap.SelfNode.Hostinfo(); hi.Valid() {
781 assert.LessOrEqual(c, 1, netmap.SelfNode.Hostinfo().Services().Len(), "%q does not have enough services, got: %v", client.Hostname(), netmap.SelfNode.Hostinfo().Services())
782 }
783
784 assert.NotEmptyf(c, netmap.SelfNode.AllowedIPs(), "%q does not have any allowed IPs", client.Hostname())
785 assert.NotEmptyf(c, netmap.SelfNode.Addresses(), "%q does not have any addresses", client.Hostname())
786
787 assert.Truef(c, netmap.SelfNode.Online().Get(), "%q is not online", client.Hostname())
788
789 assert.Falsef(c, netmap.SelfNode.Key().IsZero(), "%q does not have a valid NodeKey", client.Hostname())
790 assert.Falsef(c, netmap.SelfNode.Machine().IsZero(), "%q does not have a valid MachineKey", client.Hostname())
791 assert.Falsef(c, netmap.SelfNode.DiscoKey().IsZero(), "%q does not have a valid DiscoKey", client.Hostname())
792
793 for _, peer := range netmap.Peers {
794 assert.NotEqualf(c, 0, peer.HomeDERP(), "peer (%s) has no home DERP in %q's netmap, got: %d", peer.ComputedName(), client.Hostname(), peer.HomeDERP())
795
796 assert.Truef(c, peer.Hostinfo().Valid(), "peer (%s) of %q does not have Hostinfo", peer.ComputedName(), client.Hostname())
797
798 if hi := peer.Hostinfo(); hi.Valid() {
799 assert.LessOrEqualf(c, 3, peer.Hostinfo().Services().Len(), "peer (%s) of %q does not have enough services, got: %v", peer.ComputedName(), client.Hostname(), peer.Hostinfo().Services())
800
801 // Netinfo is not always set
802 // assert.Truef(c, hi.NetInfo().Valid(), "peer (%s) of %q does not have NetInfo", peer.ComputedName(), client.Hostname())
803 if ni := hi.NetInfo(); ni.Valid() {
804 assert.NotEqualf(c, 0, ni.PreferredDERP(), "peer (%s) has no home DERP in %q's netmap, got: %s", peer.ComputedName(), client.Hostname(), peer.Hostinfo().NetInfo().PreferredDERP())
805 }
806 }
807
808 assert.NotEmptyf(c, peer.Endpoints(), "peer (%s) of %q does not have any endpoints", peer.ComputedName(), client.Hostname())
809 assert.NotEmptyf(c, peer.AllowedIPs(), "peer (%s) of %q does not have any allowed IPs", peer.ComputedName(), client.Hostname())
810 assert.NotEmptyf(c, peer.Addresses(), "peer (%s) of %q does not have any addresses", peer.ComputedName(), client.Hostname())
811
812 assert.Truef(c, peer.Online().Get(), "peer (%s) of %q is not online", peer.ComputedName(), client.Hostname())
813
814 assert.Falsef(c, peer.Key().IsZero(), "peer (%s) of %q does not have a valid NodeKey", peer.ComputedName(), client.Hostname())
815 assert.Falsef(c, peer.Machine().IsZero(), "peer (%s) of %q does not have a valid MachineKey", peer.ComputedName(), client.Hostname())
816 assert.Falsef(c, peer.DiscoKey().IsZero(), "peer (%s) of %q does not have a valid DiscoKey", peer.ComputedName(), client.Hostname())
817 }
818 }, 10*time.Second, 200*time.Millisecond, "Waiting for valid netmap for %q", client.Hostname())
819}
820

Callers 1

assertClientsStateFunction · 0.85

Calls 12

HostinfoMethod · 0.80
LenMethod · 0.80
ServicesMethod · 0.80
KeyMethod · 0.80
DiscoKeyMethod · 0.80
EndpointsMethod · 0.80
VersionMethod · 0.65
HostnameMethod · 0.65
NetmapMethod · 0.65
ValidMethod · 0.45
IsZeroMethod · 0.45

Tested by

no test coverage detected