mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-16 13:17:19 +02:00
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/Control-D-Inc/ctrld"
|
|
)
|
|
|
|
func TestRefreshDNSAfterVPNSettleRefreshesOSResolverAndVPNRoutes(t *testing.T) {
|
|
oldInitialize := initializeOsResolver
|
|
defer func() { initializeOsResolver = oldInitialize }()
|
|
|
|
var initialized []bool
|
|
initializeOsResolver = func(ctx context.Context, force bool) []string {
|
|
initialized = append(initialized, force)
|
|
return []string{"10.102.26.10:53"}
|
|
}
|
|
|
|
var exemptionUpdates [][]vpnDNSExemption
|
|
p := &prog{}
|
|
p.vpnDNS = newVPNDNSManager(&mainLog, func(exemptions []vpnDNSExemption) error {
|
|
exemptionUpdates = append(exemptionUpdates, append([]vpnDNSExemption{}, exemptions...))
|
|
return nil
|
|
})
|
|
p.vpnDNS.discoverVPNDNS = func(context.Context) []ctrld.VPNDNSConfig {
|
|
return []ctrld.VPNDNSConfig{{
|
|
InterfaceName: "utun4",
|
|
Servers: []string{"10.102.26.10"},
|
|
Domains: []string{"bmwgroup.net"},
|
|
}}
|
|
}
|
|
|
|
routes, domainlessServers, exemptions := p.refreshDNSAfterVPNSettle("test")
|
|
|
|
if routes != 1 || domainlessServers != 0 || exemptions != 1 {
|
|
t.Fatalf("expected 1 route, 0 domainless servers, 1 exemption, got routes=%d domainless=%d exemptions=%d",
|
|
routes, domainlessServers, exemptions)
|
|
}
|
|
if len(initialized) != 1 || !initialized[0] {
|
|
t.Fatalf("expected forced OS resolver refresh once, got %v", initialized)
|
|
}
|
|
if got := p.vpnDNS.UpstreamForDomain("jira.cc.bmwgroup.net."); len(got) != 1 || got[0] != "10.102.26.10" {
|
|
t.Fatalf("expected refreshed VPN DNS route, got %v", got)
|
|
}
|
|
if len(exemptionUpdates) != 0 {
|
|
t.Fatalf("expected route-only refresh to avoid pf exemption updates, got %+v", exemptionUpdates)
|
|
}
|
|
}
|