test: isolate VPN DNS settling tests from host adapters

This commit is contained in:
Cuong Manh Le
2026-06-01 16:30:34 +07:00
committed by Cuong Manh Le
parent 4395efcb22
commit 75e8447c75
2 changed files with 12 additions and 1 deletions
+9 -1
View File
@@ -46,6 +46,9 @@ type vpnDNSManager struct {
// state for one guarded refresh cycle because Windows can briefly report an
// intermediate empty adapter/DNS state after sleep/wake or reconnect.
retainedAfterEmptyDiscovery bool
// discoverVPNDNS is injected for tests so Refresh does not depend on the
// runner host's real VPN/virtual adapter state.
discoverVPNDNS func(context.Context) []ctrld.VPNDNSConfig
// Called when VPN DNS server list changes, to update intercept exemptions.
onServersChanged vpnDNSExemptFunc
}
@@ -56,6 +59,7 @@ type vpnDNSManager struct {
func newVPNDNSManager(exemptFunc vpnDNSExemptFunc) *vpnDNSManager {
return &vpnDNSManager{
routes: make(map[string][]string),
discoverVPNDNS: ctrld.DiscoverVPNDNS,
onServersChanged: exemptFunc,
}
}
@@ -66,7 +70,11 @@ func (m *vpnDNSManager) Refresh(guardAgainstNoNameservers bool) {
logger := mainLog.Load()
logger.Debug().Msg("Refreshing VPN DNS configurations")
configs := ctrld.DiscoverVPNDNS(context.Background())
discoverVPNDNS := m.discoverVPNDNS
if discoverVPNDNS == nil {
discoverVPNDNS = ctrld.DiscoverVPNDNS
}
configs := discoverVPNDNS(context.Background())
// Detect exit mode: if the default route goes through a VPN DNS interface,
// the VPN is routing ALL traffic (exit node / full tunnel). This is more