@@ -185,6 +185,52 @@ func TestConfigMaps_updatePeers_new(t *testing.T) {
185
185
_ = testutil .RequireRecvCtx (ctx , t , done )
186
186
}
187
187
188
+ func TestConfigMaps_updatePeers_new_waitForHandshake_neverConfigures (t * testing.T ) {
189
+ t .Parallel ()
190
+ ctx := testutil .Context (t , testutil .WaitShort )
191
+ logger := slogtest .Make (t , nil ).Leveled (slog .LevelDebug )
192
+ fEng := newFakeEngineConfigurable ()
193
+ nodePrivateKey := key .NewNode ()
194
+ nodeID := tailcfg .NodeID (5 )
195
+ discoKey := key .NewDisco ()
196
+ uut := newConfigMaps (logger , fEng , nodeID , nodePrivateKey , discoKey .Public ())
197
+ defer uut .close ()
198
+ uut .setWaitForHandshake (true )
199
+ start := time .Date (2024 , time .January , 1 , 8 , 0 , 0 , 0 , time .UTC )
200
+ mClock := clock .NewMock ()
201
+ mClock .Set (start )
202
+ uut .clock = mClock
203
+
204
+ p1ID := uuid.UUID {1 }
205
+ p1Node := newTestNode (1 )
206
+ p1n , err := NodeToProto (p1Node )
207
+ require .NoError (t , err )
208
+
209
+ // it should not send the peer to the netmap
210
+ requireNeverConfigures (ctx , t , & uut .phased )
211
+
212
+ go func () {
213
+ <- fEng .status
214
+ fEng .statusDone <- struct {}{}
215
+ }()
216
+
217
+ u1 := []* proto.CoordinateResponse_PeerUpdate {
218
+ {
219
+ Id : p1ID [:],
220
+ Kind : proto .CoordinateResponse_PeerUpdate_NODE ,
221
+ Node : p1n ,
222
+ },
223
+ }
224
+ uut .updatePeers (u1 )
225
+
226
+ done := make (chan struct {})
227
+ go func () {
228
+ defer close (done )
229
+ uut .close ()
230
+ }()
231
+ _ = testutil .RequireRecvCtx (ctx , t , done )
232
+ }
233
+
188
234
func TestConfigMaps_updatePeers_new_waitForHandshake (t * testing.T ) {
189
235
t .Parallel ()
190
236
ctx := testutil .Context (t , testutil .WaitShort )
@@ -196,6 +242,10 @@ func TestConfigMaps_updatePeers_new_waitForHandshake(t *testing.T) {
196
242
uut := newConfigMaps (logger , fEng , nodeID , nodePrivateKey , discoKey .Public ())
197
243
defer uut .close ()
198
244
uut .setWaitForHandshake (true )
245
+ start := time .Date (2024 , time .January , 1 , 8 , 0 , 0 , 0 , time .UTC )
246
+ mClock := clock .NewMock ()
247
+ mClock .Set (start )
248
+ uut .clock = mClock
199
249
200
250
p1ID := uuid.UUID {1 }
201
251
p1Node := newTestNode (1 )
@@ -254,6 +304,66 @@ func TestConfigMaps_updatePeers_new_waitForHandshake(t *testing.T) {
254
304
_ = testutil .RequireRecvCtx (ctx , t , done )
255
305
}
256
306
307
+ func TestConfigMaps_updatePeers_new_waitForHandshake_timeout (t * testing.T ) {
308
+ t .Parallel ()
309
+ ctx := testutil .Context (t , testutil .WaitShort )
310
+ logger := slogtest .Make (t , nil ).Leveled (slog .LevelDebug )
311
+ fEng := newFakeEngineConfigurable ()
312
+ nodePrivateKey := key .NewNode ()
313
+ nodeID := tailcfg .NodeID (5 )
314
+ discoKey := key .NewDisco ()
315
+ uut := newConfigMaps (logger , fEng , nodeID , nodePrivateKey , discoKey .Public ())
316
+ defer uut .close ()
317
+ uut .setWaitForHandshake (true )
318
+ start := time .Date (2024 , time .March , 29 , 8 , 0 , 0 , 0 , time .UTC )
319
+ mClock := clock .NewMock ()
320
+ mClock .Set (start )
321
+ uut .clock = mClock
322
+
323
+ p1ID := uuid.UUID {1 }
324
+ p1Node := newTestNode (1 )
325
+ p1n , err := NodeToProto (p1Node )
326
+ require .NoError (t , err )
327
+
328
+ go func () {
329
+ <- fEng .status
330
+ fEng .statusDone <- struct {}{}
331
+ }()
332
+
333
+ u1 := []* proto.CoordinateResponse_PeerUpdate {
334
+ {
335
+ Id : p1ID [:],
336
+ Kind : proto .CoordinateResponse_PeerUpdate_NODE ,
337
+ Node : p1n ,
338
+ },
339
+ }
340
+ uut .updatePeers (u1 )
341
+
342
+ mClock .Add (5 * time .Second )
343
+
344
+ // it should now send the peer to the netmap
345
+
346
+ nm := testutil .RequireRecvCtx (ctx , t , fEng .setNetworkMap )
347
+ r := testutil .RequireRecvCtx (ctx , t , fEng .reconfig )
348
+
349
+ require .Len (t , nm .Peers , 1 )
350
+ n1 := getNodeWithID (t , nm .Peers , 1 )
351
+ require .Equal (t , "127.3.3.40:1" , n1 .DERP )
352
+ require .Equal (t , p1Node .Endpoints , n1 .Endpoints )
353
+ require .False (t , n1 .KeepAlive )
354
+
355
+ // we rely on nmcfg.WGCfg() to convert the netmap to wireguard config, so just
356
+ // require the right number of peers.
357
+ require .Len (t , r .wg .Peers , 1 )
358
+
359
+ done := make (chan struct {})
360
+ go func () {
361
+ defer close (done )
362
+ uut .close ()
363
+ }()
364
+ _ = testutil .RequireRecvCtx (ctx , t , done )
365
+ }
366
+
257
367
func TestConfigMaps_updatePeers_same (t * testing.T ) {
258
368
t .Parallel ()
259
369
ctx := testutil .Context (t , testutil .WaitShort )
0 commit comments