testcontrol

package
v0.0.0-...-1b709f2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2026 License: BSD-3-Clause Imports: 39 Imported by: 0

Documentation

Overview

Package testcontrol contains a minimal control plane server for testing purposes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthPath

type AuthPath struct {
	// contains filtered or unexported fields
}

func (*AuthPath) CompleteSuccessfully

func (ap *AuthPath) CompleteSuccessfully()

CompleteSuccessfully completes the login path successfully, as if the user did the whole auth dance.

type MasqueradePair

type MasqueradePair struct {
	Node              key.NodePublic
	Peer              key.NodePublic
	NodeMasqueradesAs netip.Addr
}

MasqueradePair is a pair of nodes and the IP address that the Node masquerades as for the Peer.

Setting this will have future MapResponses for Node to have Peer.SelfNodeV{4,6}MasqAddrForThisPeer set to NodeMasqueradesAs. MapResponses for the Peer will now see Node.Addresses as NodeMasqueradesAs.

type Server

type Server struct {
	Logf               logger.Logf      // nil means to use the log package
	DERPMap            *tailcfg.DERPMap // nil means to use prod DERP map
	RequireAuth        bool
	RequireAuthKey     string // required authkey for all nodes
	RequireMachineAuth bool
	Verbose            bool
	DNSConfig          *tailcfg.DNSConfig // nil means no DNS config
	MagicDNSDomain     string
	C2NResponses       syncs.Map[string, func(*http.Response)] // token => onResponse func

	// PeerRelayGrants, if true, inserts relay capabilities into the wildcard
	// grants rules.
	PeerRelayGrants bool

	// AllNodesSameUser, if true, makes all created nodes
	// belong to the same user.
	AllNodesSameUser bool

	// DefaultNodeCapabilities overrides the capability map sent to each client.
	DefaultNodeCapabilities *tailcfg.NodeCapMap

	// CollectServices, if non-empty, sets whether the control server asks
	// for service updates. If empty, the default is "true".
	CollectServices opt.Bool

	// ExplicitBaseURL or HTTPTestServer must be set.
	ExplicitBaseURL string           // e.g. "http://127.0.0.1:1234" with no trailing URL
	HTTPTestServer  *httptest.Server // if non-nil, used to get BaseURL

	// ModifyFirstMapResponse, if non-nil, is called exactly once per
	// MapResponse stream to modify the first MapResponse sent in response to it.
	ModifyFirstMapResponse func(*tailcfg.MapResponse, *tailcfg.MapRequest)
	// contains filtered or unexported fields
}

Server is a control plane server. Its zero value is ready for use. Everything is stored in-memory in one tailnet.

func (*Server) AddDNSRecords

func (s *Server) AddDNSRecords(records ...tailcfg.DNSRecord)

AddDNSRecords adds records to the server's DNS config.

func (*Server) AddFakeNode

func (s *Server) AddFakeNode()

AddFakeNode injects a fake node into the server.

func (*Server) AddPingRequest

func (s *Server) AddPingRequest(nodeKeyDst key.NodePublic, pr *tailcfg.PingRequest) bool

AddPingRequest sends the ping pr to nodeKeyDst.

It reports whether the message was enqueued. That is, it reports whether nodeKeyDst was connected.

func (*Server) AddRawMapResponse

func (s *Server) AddRawMapResponse(nodeKeyDst key.NodePublic, mr *tailcfg.MapResponse) bool

AddRawMapResponse delivers the raw MapResponse mr to nodeKeyDst. It's meant for testing incremental map updates.

Once AddRawMapResponse has been sent to a node, all future automatic MapResponses to that node will be suppressed and only explicit MapResponses injected via AddRawMapResponse will be sent.

It reports whether the message was enqueued. That is, it reports whether nodeKeyDst was connected.

func (*Server) AllNodes

func (s *Server) AllNodes() (nodes []*tailcfg.Node)

func (*Server) AwaitNodeInMapRequest

func (s *Server) AwaitNodeInMapRequest(ctx context.Context, k key.NodePublic) error

AwaitNodeInMapRequest waits for node k to be stuck in a map poll. It returns an error if and only if the context is done first.

func (*Server) BaseURL

func (s *Server) BaseURL() string

BaseURL returns the server's base URL, without trailing slash.

func (*Server) CompleteAuth

func (s *Server) CompleteAuth(authPathOrURL string) bool

CompleteAuth marks the provided path or URL (containing "/auth/...") as successfully authenticated, unblocking any requests blocked on that in serveRegister.

func (*Server) CompleteDeviceApproval

func (s *Server) CompleteDeviceApproval(controlUrl string, urlStr string, nodeKey *key.NodePublic) bool

Complete the device approval for this node.

This function returns false if the node does not exist, or you try to approve a device against a different control server.

func (*Server) ForceNetmapUpdate

func (s *Server) ForceNetmapUpdate(ctx context.Context, nodeKey key.NodePublic) error

ForceNetmapUpdate waits for the node to get stuck in a map poll and then sends the current netmap (which may result in a redundant netmap). The intended use case is ensuring state changes propagate before running tests.

This should only be called for nodes connected as streaming clients. Calling this with a non-streaming node will result in non-deterministic behavior.

This function cannot guarantee that the node has processed the issued update, so tests should confirm processing by querying the node. By example:

if err := s.ForceNetmapUpdate(node.Key()); err != nil {
// handle error
}
for !updatesPresent(node.NetMap()) {
time.Sleep(10 * time.Millisecond)
}

func (*Server) InServeMap

func (s *Server) InServeMap() int

InServeMap returns the number of clients currently in a MapRequest HTTP handler.

func (*Server) MapResponse

func (s *Server) MapResponse(req *tailcfg.MapRequest) (res *tailcfg.MapResponse, err error)

MapResponse generates a MapResponse for a MapRequest.

No updates to s are done here.

func (*Server) Node

func (s *Server) Node(nodeKey key.NodePublic) *tailcfg.Node

Node returns the node for nodeKey. It's always nil or cloned memory.

func (*Server) NodeRoundTripper

func (s *Server) NodeRoundTripper(n key.NodePublic) http.RoundTripper

func (*Server) NumNodes

func (s *Server) NumNodes() int

NumNodes returns the number of nodes in the testcontrol server.

This is useful when connecting a bunch of virtual machines to a testcontrol server to see how many of them connected successfully.

func (*Server) SendC2N

func (s *Server) SendC2N(node key.NodePublic, req *http.Request, onRes func(*http.Response)) error

SendC2N sends req to node. When the response is received, onRes is called.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) SetExpireAllNodes

func (s *Server) SetExpireAllNodes(expired bool)

Mark the Node key of every node as expired

func (*Server) SetGlobalAppCaps

func (s *Server) SetGlobalAppCaps(appCaps tailcfg.PeerCapMap)

SetGlobalAppCaps configures global app capabilities. This is equivalent to

"grants": [
   {
     "src": ["*"],
     "dst": ["*"],
     "app": <contents of the input map>
   }
]

func (*Server) SetJailed

func (s *Server) SetJailed(a, b key.NodePublic, jailed bool)

SetJailed sets b to be jailed when it is a peer of a.

func (*Server) SetMasqueradeAddresses

func (s *Server) SetMasqueradeAddresses(pairs []MasqueradePair)

SetMasqueradeAddresses sets the masquerade addresses for the server. See MasqueradePair for more details.

func (*Server) SetNodeCapMap

func (s *Server) SetNodeCapMap(nodeKey key.NodePublic, capMap tailcfg.NodeCapMap)

SetNodeCapMap overrides the capability map the specified client receives.

func (*Server) SetSubnetRoutes

func (s *Server) SetSubnetRoutes(nodeKey key.NodePublic, routes []netip.Prefix)

SetSubnetRoutes sets the list of subnet routes which a node is routing.

func (*Server) UpdateNode

func (s *Server) UpdateNode(n *tailcfg.Node) (peersToUpdate []tailcfg.NodeID)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL