MCPcopy Index your code
hub / github.com/tailscale/tailscale / TestSNIProxyWithNetmapConfig

Function TestSNIProxyWithNetmapConfig

cmd/sniproxy/sniproxy_test.go:115–192  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

113}
114
115func TestSNIProxyWithNetmapConfig(t *testing.T) {
116 nettest.SkipIfNoNetwork(t)
117 c, controlURL := startControl(t)
118 ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
119 defer cancel()
120
121 // Create a listener to proxy connections to.
122 ln, err := net.Listen("tcp", "127.0.0.1:0")
123 if err != nil {
124 t.Fatal(err)
125 }
126 defer ln.Close()
127
128 // Start sniproxy
129 sni, nodeKey, ip := startNode(t, ctx, controlURL, "snitest")
130 go run(ctx, sni, 0, sni.Hostname, false, 0, "", "")
131
132 // Configure the mock coordination server to send down app connector config.
133 config := &appctype.AppConnectorConfig{
134 DNAT: map[appctype.ConfigID]appctype.DNATConfig{
135 "nic_test": {
136 Addrs: []netip.Addr{ip},
137 To: []string{"127.0.0.1"},
138 IP: []tailcfg.ProtoPortRange{
139 {
140 Proto: int(ipproto.TCP),
141 Ports: tailcfg.PortRange{First: uint16(ln.Addr().(*net.TCPAddr).Port), Last: uint16(ln.Addr().(*net.TCPAddr).Port)},
142 },
143 },
144 },
145 },
146 }
147 b, err := json.Marshal(config)
148 if err != nil {
149 t.Fatal(err)
150 }
151 c.SetNodeCapMap(nodeKey, tailcfg.NodeCapMap{
152 configCapKey: []tailcfg.RawMessage{tailcfg.RawMessage(b)},
153 })
154
155 // Let's spin up a second node (to represent the client).
156 client, _, _ := startNode(t, ctx, controlURL, "client")
157
158 // Make sure that the sni node has received its config.
159 lc, err := sni.LocalClient()
160 if err != nil {
161 t.Fatal(err)
162 }
163 gotConfigured := false
164 for range 100 {
165 s, err := lc.StatusWithoutPeers(ctx)
166 if err != nil {
167 t.Fatal(err)
168 }
169 if len(s.Self.CapMap) > 0 {
170 gotConfigured = true
171 break // we got it
172 }

Callers

nothing calls this directly

Calls 15

SkipIfNoNetworkFunction · 0.92
RawMessageTypeAlias · 0.92
SetNodeCapMapMethod · 0.80
startControlFunction · 0.70
startNodeFunction · 0.70
runFunction · 0.70
ListenMethod · 0.65
FatalMethod · 0.65
CloseMethod · 0.65
MarshalMethod · 0.65
StatusWithoutPeersMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…