(t *testing.T)
| 113 | } |
| 114 | |
| 115 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…