@@ -293,6 +293,7 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
293
293
}
294
294
295
295
stunAddr , stunCleanup := stuntest .ServeWithPacketListener (t , nettype.Std {})
296
+ stunAddr .IP = net .ParseIP ("127.0.0.1" )
296
297
t .Cleanup (stunCleanup )
297
298
298
299
derpServer := derp .NewServer (key .NewNode (), tailnet .Logger (slogtest .Make (t , nil ).Named ("derp" ).Leveled (slog .LevelDebug )))
@@ -310,6 +311,29 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
310
311
require .NoError (t , err )
311
312
}
312
313
314
+ region := & tailcfg.DERPRegion {
315
+ EmbeddedRelay : true ,
316
+ RegionID : int (options .DeploymentValues .DERP .Server .RegionID .Value ()),
317
+ RegionCode : options .DeploymentValues .DERP .Server .RegionCode .String (),
318
+ RegionName : options .DeploymentValues .DERP .Server .RegionName .String (),
319
+ Nodes : []* tailcfg.DERPNode {{
320
+ Name : fmt .Sprintf ("%db" , options .DeploymentValues .DERP .Server .RegionID ),
321
+ RegionID : int (options .DeploymentValues .DERP .Server .RegionID .Value ()),
322
+ IPv4 : "127.0.0.1" ,
323
+ DERPPort : derpPort ,
324
+ // STUN port is added as a separate node by tailnet.NewDERPMap() if
325
+ // direct connections are enabled.
326
+ STUNPort : - 1 ,
327
+ InsecureForTests : true ,
328
+ ForceHTTP : options .TLSCertificates == nil ,
329
+ }},
330
+ }
331
+ if ! options .DeploymentValues .DERP .Server .Enable .Value () {
332
+ region = nil
333
+ }
334
+ derpMap , err := tailnet .NewDERPMap (ctx , region , []string {stunAddr .String ()}, "" , "" , options .DeploymentValues .DERP .Config .BlockDirect .Value ())
335
+ require .NoError (t , err )
336
+
313
337
return func (h http.Handler ) {
314
338
mutex .Lock ()
315
339
defer mutex .Unlock ()
@@ -328,42 +352,24 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
328
352
Pubsub : options .Pubsub ,
329
353
GitAuthConfigs : options .GitAuthConfigs ,
330
354
331
- Auditor : options .Auditor ,
332
- AWSCertificates : options .AWSCertificates ,
333
- AzureCertificates : options .AzureCertificates ,
334
- GithubOAuth2Config : options .GithubOAuth2Config ,
335
- RealIPConfig : options .RealIPConfig ,
336
- OIDCConfig : options .OIDCConfig ,
337
- GoogleTokenValidator : options .GoogleTokenValidator ,
338
- SSHKeygenAlgorithm : options .SSHKeygenAlgorithm ,
339
- DERPServer : derpServer ,
340
- APIRateLimit : options .APIRateLimit ,
341
- LoginRateLimit : options .LoginRateLimit ,
342
- FilesRateLimit : options .FilesRateLimit ,
343
- Authorizer : options .Authorizer ,
344
- Telemetry : telemetry .NewNoop (),
345
- TemplateScheduleStore : & templateScheduleStore ,
346
- TLSCertificates : options .TLSCertificates ,
347
- TrialGenerator : options .TrialGenerator ,
348
- DERPMap : & tailcfg.DERPMap {
349
- Regions : map [int ]* tailcfg.DERPRegion {
350
- 1 : {
351
- EmbeddedRelay : true ,
352
- RegionID : 1 ,
353
- RegionCode : "coder" ,
354
- RegionName : "Coder" ,
355
- Nodes : []* tailcfg.DERPNode {{
356
- Name : "1a" ,
357
- RegionID : 1 ,
358
- IPv4 : "127.0.0.1" ,
359
- DERPPort : derpPort ,
360
- STUNPort : stunAddr .Port ,
361
- InsecureForTests : true ,
362
- ForceHTTP : options .TLSCertificates == nil ,
363
- }},
364
- },
365
- },
366
- },
355
+ Auditor : options .Auditor ,
356
+ AWSCertificates : options .AWSCertificates ,
357
+ AzureCertificates : options .AzureCertificates ,
358
+ GithubOAuth2Config : options .GithubOAuth2Config ,
359
+ RealIPConfig : options .RealIPConfig ,
360
+ OIDCConfig : options .OIDCConfig ,
361
+ GoogleTokenValidator : options .GoogleTokenValidator ,
362
+ SSHKeygenAlgorithm : options .SSHKeygenAlgorithm ,
363
+ DERPServer : derpServer ,
364
+ APIRateLimit : options .APIRateLimit ,
365
+ LoginRateLimit : options .LoginRateLimit ,
366
+ FilesRateLimit : options .FilesRateLimit ,
367
+ Authorizer : options .Authorizer ,
368
+ Telemetry : telemetry .NewNoop (),
369
+ TemplateScheduleStore : & templateScheduleStore ,
370
+ TLSCertificates : options .TLSCertificates ,
371
+ TrialGenerator : options .TrialGenerator ,
372
+ DERPMap : derpMap ,
367
373
MetricsCacheRefreshInterval : options .MetricsCacheRefreshInterval ,
368
374
AgentStatsRefreshInterval : options .AgentStatsRefreshInterval ,
369
375
DeploymentValues : options .DeploymentValues ,
0 commit comments