MCPcopy
hub / github.com/AdguardTeam/dnsproxy / TestECSProxyCacheMinMaxTTL

Function TestECSProxyCacheMinMaxTTL

proxy/proxy_internal_test.go:1199–1272  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1197}
1198
1199func TestECSProxyCacheMinMaxTTL(t *testing.T) {
1200 clientIP := net.IP{1, 2, 3, 0}
1201 u := &testUpstream{
1202 ans: []dns.RR{&dns.A{
1203 Hdr: dns.RR_Header{
1204 Rrtype: dns.TypeA,
1205 Name: "host.",
1206 Ttl: 10,
1207 },
1208 A: net.IP{4, 3, 2, 1},
1209 }},
1210 ecsIP: clientIP,
1211 }
1212
1213 prx := mustNew(t, &Config{
1214 Logger: testLogger,
1215 UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
1216 TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
1217 UpstreamConfig: &UpstreamConfig{Upstreams: []upstream.Upstream{u}},
1218 TrustedProxies: defaultTrustedProxies,
1219 DNSSECEnabled: true,
1220 EnableEDNSClientSubnet: true,
1221 CacheEnabled: true,
1222 CacheMinTTL: 20,
1223 CacheMaxTTL: 40,
1224 })
1225
1226 servicetest.RequireRun(t, prx, testTimeout)
1227
1228 // first request
1229 d := &DNSContext{
1230 Req: newHostTestMessage("host"),
1231 Addr: netip.MustParseAddrPort("1.2.3.0:1234"),
1232 }
1233 ctx := testutil.ContextWithTimeout(t, defaultTimeout)
1234 err := prx.Resolve(ctx, d)
1235 require.NoError(t, err)
1236
1237 // get from cache - check min TTL
1238 ci, expired, key := prx.cache.getWithSubnet(d.Req, &net.IPNet{
1239 IP: clientIP,
1240 Mask: net.CIDRMask(24, netutil.IPv4BitLen),
1241 })
1242 assert.False(t, expired)
1243
1244 assert.Equal(t, key, msgToKeyWithSubnet(d.Req, clientIP, 24))
1245 assert.True(t, ci.m.Answer[0].Header().Ttl == prx.CacheMinTTL)
1246
1247 // 2nd request
1248 clientIP = net.IP{1, 2, 4, 0}
1249 d.Req = newHostTestMessage("host")
1250 d.Addr = netip.MustParseAddrPort("1.2.4.0:1234")
1251 u.ans = []dns.RR{&dns.A{
1252 Hdr: dns.RR_Header{
1253 Rrtype: dns.TypeA,
1254 Name: "host.",
1255 Ttl: 60,
1256 },

Callers

nothing calls this directly

Calls 5

mustNewFunction · 0.85
newHostTestMessageFunction · 0.85
msgToKeyWithSubnetFunction · 0.85
ResolveMethod · 0.80
getWithSubnetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…