MCPcopy Index your code
hub / github.com/coder/coder / TestConn_BlockEndpoints

Function TestConn_BlockEndpoints

tailnet/conn_test.go:415–470  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

413}
414
415func TestConn_BlockEndpoints(t *testing.T) {
416 t.Parallel()
417 logger := testutil.Logger(t)
418
419 derpMap, _ := tailnettest.RunDERPAndSTUN(t)
420
421 // Setup conn 1.
422 ip1 := tailnet.TailscaleServicePrefix.RandomAddr()
423 conn1, err := tailnet.NewConn(&tailnet.Options{
424 Addresses: []netip.Prefix{netip.PrefixFrom(ip1, 128)},
425 Logger: logger.Named("w1"),
426 DERPMap: derpMap,
427 BlockEndpoints: true,
428 })
429 require.NoError(t, err)
430 t.Cleanup(func() {
431 err := conn1.Close()
432 assert.NoError(t, err)
433 })
434
435 // Setup conn 2.
436 ip2 := tailnet.TailscaleServicePrefix.RandomAddr()
437 conn2, err := tailnet.NewConn(&tailnet.Options{
438 Addresses: []netip.Prefix{netip.PrefixFrom(ip2, 128)},
439 Logger: logger.Named("w2"),
440 DERPMap: derpMap,
441 BlockEndpoints: true,
442 })
443 require.NoError(t, err)
444 t.Cleanup(func() {
445 err := conn2.Close()
446 assert.NoError(t, err)
447 })
448
449 // Connect them together and wait for them to be reachable.
450 stitch(t, conn2, conn1)
451 stitch(t, conn1, conn2)
452 awaitReachableCtx, awaitReachableCancel := context.WithTimeout(context.Background(), testutil.WaitShort)
453 t.Cleanup(awaitReachableCancel)
454 require.True(t, conn1.AwaitReachable(awaitReachableCtx, ip2))
455
456 // Wait 10s for endpoints to potentially be sent over Disco. There's no way
457 // to force Disco to send endpoints immediately.
458 time.Sleep(10 * time.Second)
459
460 // Double check that both peers don't have endpoints for the other peer
461 // according to magicsock.
462 conn1Status, ok := conn1.Status().Peer[conn2.Node().Key]
463 require.True(t, ok)
464 require.Empty(t, conn1Status.Addrs)
465 require.Empty(t, conn1Status.CurAddr)
466 conn2Status, ok := conn2.Status().Peer[conn1.Node().Key]
467 require.True(t, ok)
468 require.Empty(t, conn2Status.Addrs)
469 require.Empty(t, conn2Status.CurAddr)
470}
471
472// stitch sends node updates from src Conn as peer updates to dst Conn. Sort of

Callers

nothing calls this directly

Calls 12

CloseMethod · 0.95
AwaitReachableMethod · 0.95
StatusMethod · 0.95
NodeMethod · 0.95
LoggerFunction · 0.92
RunDERPAndSTUNFunction · 0.92
NewConnFunction · 0.92
stitchFunction · 0.85
RandomAddrMethod · 0.80
NamedMethod · 0.80
CleanupMethod · 0.65
EmptyMethod · 0.45

Tested by

no test coverage detected