@@ -473,6 +473,93 @@ func TestConfigMaps_updatePeers_lost_and_found(t *testing.T) {
473
473
_ = testutil .RequireRecvCtx (ctx , t , done )
474
474
}
475
475
476
+ func TestConfigMaps_setBlockEndpoints_different (t * testing.T ) {
477
+ t .Parallel ()
478
+ ctx := testutil .Context (t , testutil .WaitShort )
479
+ logger := slogtest .Make (t , nil ).Leveled (slog .LevelDebug )
480
+ fEng := newFakeEngineConfigurable ()
481
+ nodePrivateKey := key .NewNode ()
482
+ nodeID := tailcfg .NodeID (5 )
483
+ discoKey := key .NewDisco ()
484
+ uut := newConfigMaps (logger , fEng , nodeID , nodePrivateKey , discoKey .Public (), nil )
485
+ defer uut .close ()
486
+
487
+ p1ID := uuid .MustParse ("10000000-0000-0000-0000-000000000000" )
488
+ p1Node := newTestNode (1 )
489
+ p1n , err := NodeToProto (p1Node )
490
+ require .NoError (t , err )
491
+ p1tcn , err := uut .protoNodeToTailcfg (p1n )
492
+ p1tcn .KeepAlive = true
493
+ require .NoError (t , err )
494
+
495
+ // Given: peer already exists
496
+ uut .L .Lock ()
497
+ uut .peers [p1ID ] = & peerLifecycle {
498
+ peerID : p1ID ,
499
+ node : p1tcn ,
500
+ lastHandshake : time .Date (2024 , 1 , 7 , 12 , 0 , 10 , 0 , time .UTC ),
501
+ }
502
+ uut .L .Unlock ()
503
+
504
+ uut .setBlockEndpoints (true )
505
+
506
+ nm := testutil .RequireRecvCtx (ctx , t , fEng .setNetworkMap )
507
+ r := testutil .RequireRecvCtx (ctx , t , fEng .reconfig )
508
+ require .Len (t , nm .Peers , 1 )
509
+ require .Len (t , nm .Peers [0 ].Endpoints , 0 )
510
+ require .Len (t , r .wg .Peers , 1 )
511
+
512
+ done := make (chan struct {})
513
+ go func () {
514
+ defer close (done )
515
+ uut .close ()
516
+ }()
517
+ _ = testutil .RequireRecvCtx (ctx , t , done )
518
+ }
519
+
520
+ func TestConfigMaps_setBlockEndpoints_same (t * testing.T ) {
521
+ t .Parallel ()
522
+ ctx := testutil .Context (t , testutil .WaitShort )
523
+ logger := slogtest .Make (t , nil ).Leveled (slog .LevelDebug )
524
+ fEng := newFakeEngineConfigurable ()
525
+ nodePrivateKey := key .NewNode ()
526
+ nodeID := tailcfg .NodeID (5 )
527
+ discoKey := key .NewDisco ()
528
+ uut := newConfigMaps (logger , fEng , nodeID , nodePrivateKey , discoKey .Public (), nil )
529
+ defer uut .close ()
530
+
531
+ p1ID := uuid .MustParse ("10000000-0000-0000-0000-000000000000" )
532
+ p1Node := newTestNode (1 )
533
+ p1n , err := NodeToProto (p1Node )
534
+ require .NoError (t , err )
535
+ p1tcn , err := uut .protoNodeToTailcfg (p1n )
536
+ p1tcn .KeepAlive = true
537
+ require .NoError (t , err )
538
+
539
+ // Given: peer already exists && blockEndpoints set to true
540
+ uut .L .Lock ()
541
+ uut .peers [p1ID ] = & peerLifecycle {
542
+ peerID : p1ID ,
543
+ node : p1tcn ,
544
+ lastHandshake : time .Date (2024 , 1 , 7 , 12 , 0 , 10 , 0 , time .UTC ),
545
+ }
546
+ uut .blockEndpoints = true
547
+ uut .L .Unlock ()
548
+
549
+ // Then: we don't configure
550
+ requireNeverConfigures (ctx , t , uut )
551
+
552
+ // When we set blockEndpoints to true
553
+ uut .setBlockEndpoints (true )
554
+
555
+ done := make (chan struct {})
556
+ go func () {
557
+ defer close (done )
558
+ uut .close ()
559
+ }()
560
+ _ = testutil .RequireRecvCtx (ctx , t , done )
561
+ }
562
+
476
563
func expectStatusWithHandshake (
477
564
ctx context.Context , t testing.TB , fEng * fakeEngineConfigurable , k key.NodePublic , lastHandshake time.Time ,
478
565
) <- chan struct {} {
0 commit comments