1 parent
0b6dcbd547
commit
d48c1863bf
9 files changed
+222
-7
No files matched your search
@@ -656,3 +656,42 @@ func TestHealthCheckProbesEveryUpstream(t *testing.T) {
|
||||
t.Error("the dead upstream was not taken out of rotation")
|
||||
}
|
||||
}
|
||||
|
||||
func TestForwardZones(t *testing.T) {
|
||||
public := newFakeUpstream(t, fakeOpt{ip: "203.0.113.1"})
|
||||
firewall := newFakeUpstream(t, fakeOpt{ip: "10.10.11.117", truncateUDP: true})
|
||||
specific := newFakeUpstream(t, fakeOpt{ip: "10.10.11.118"})
|
||||
cfg := poolCfg(udpServer(public.addr))
|
||||
cfg.ForwardZones = []config.ForwardZone{
|
||||
{Zone: "local", Servers: []config.UpstreamServer{udpServer(firewall.addr)}},
|
||||
{Zone: "lab.local", Servers: []config.UpstreamServer{udpServer(specific.addr)}},
|
||||
}
|
||||
p := NewPool(cfg)
|
||||
for _, tc := range []struct{ name, addr string }{
|
||||
{"fastpi.LoCaL.", firewall.addr}, {"local.", firewall.addr},
|
||||
{"host.lab.local.", specific.addr}, {"notlocal.", public.addr},
|
||||
{"local.example.", public.addr},
|
||||
} {
|
||||
_, addr, err := p.Exchange(testCtx(t), query(tc.name), []string{public.addr}, time.Second)
|
||||
if err != nil || addr != tc.addr {
|
||||
t.Fatalf("%s: addr=%s err=%v, want %s", tc.name, addr, err, tc.addr)
|
||||
}
|
||||
}
|
||||
if firewall.tcpHits.Load() == 0 {
|
||||
t.Fatal("forwarded truncated UDP answer did not retry TCP")
|
||||
}
|
||||
before := public.udpHits.Load()
|
||||
cfg.ForwardZones[0].Servers = []config.UpstreamServer{udpServer("127.0.0.1:1")}
|
||||
p.Rebind(cfg)
|
||||
if _, _, err := p.Exchange(testCtx(t), query("fastpi.local."), nil, 50*time.Millisecond); err == nil {
|
||||
t.Fatal("dead route succeeded")
|
||||
}
|
||||
if public.udpHits.Load() != before {
|
||||
t.Fatal("private query leaked to public upstream")
|
||||
}
|
||||
cfg.ForwardZones = nil
|
||||
p.Rebind(cfg)
|
||||
if _, addr, err := p.Exchange(testCtx(t), query("fastpi.local."), nil, time.Second); err != nil || addr != public.addr {
|
||||
t.Fatalf("removed route: %s %v", addr, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user