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

Function TestTSMPKeyAdvertisement

wgengine/userspace_test.go:417–473  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

415}
416
417func TestTSMPKeyAdvertisement(t *testing.T) {
418 var knobs controlknobs.Knobs
419
420 bus := eventbustest.NewBus(t)
421 ht := health.NewTracker(bus)
422 reg := new(usermetric.Registry)
423 e, err := NewFakeUserspaceEngine(t.Logf, 0, &knobs, ht, reg, bus)
424 if err != nil {
425 t.Fatal(err)
426 }
427 t.Cleanup(e.Close)
428 ue := e.(*userspaceEngine)
429 routerCfg := &router.Config{}
430 nodeKey := nkFromHex("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
431 nm := &netmap.NetworkMap{
432 Peers: nodeViews([]*tailcfg.Node{
433 {
434 ID: 1,
435 Key: nodeKey,
436 },
437 }),
438 SelfNode: (&tailcfg.Node{
439 StableID: "TESTCTRL00000001",
440 Name: "test-node.test.ts.net",
441 Addresses: []netip.Prefix{netip.MustParsePrefix("100.64.0.1/32"), netip.MustParsePrefix("fd7a:115c:a1e0:ab12:4843:cd96:0:1/128")},
442 }).View(),
443 }
444 cfg := &wgcfg.Config{
445 Peers: []wgcfg.Peer{
446 {
447 PublicKey: nodeKey,
448 AllowedIPs: []netip.Prefix{
449 netip.PrefixFrom(netaddr.IPv4(100, 100, 99, 1), 32),
450 },
451 },
452 },
453 }
454
455 ue.SetNetworkMap(nm)
456 err = ue.Reconfig(cfg, routerCfg, &dns.Config{})
457 if err != nil {
458 t.Fatal(err)
459 }
460
461 addr := netip.MustParseAddr("100.100.99.1")
462 previousValue := metricTSMPDiscoKeyAdvertisementSent.Value()
463 ue.sendTSMPDiscoAdvertisement(addr)
464 if val := metricTSMPDiscoKeyAdvertisementSent.Value(); val <= previousValue {
465 errs := metricTSMPDiscoKeyAdvertisementError.Value()
466 t.Errorf("Expected 1 disco key advert, got %d, errors %d", val, errs)
467 }
468 // Remove config to have the engine shut down more consistently
469 err = ue.Reconfig(&wgcfg.Config{}, &router.Config{}, &dns.Config{})
470 if err != nil {
471 t.Fatal(err)
472 }
473}
474

Callers

nothing calls this directly

Calls 14

NewBusFunction · 0.92
NewTrackerFunction · 0.92
IPv4Function · 0.92
NewFakeUserspaceEngineFunction · 0.85
nkFromHexFunction · 0.85
nodeViewsFunction · 0.70
FatalMethod · 0.65
CleanupMethod · 0.65
ViewMethod · 0.65
SetNetworkMapMethod · 0.65
ReconfigMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…