MCPcopy Index your code
hub / github.com/AdguardTeam/dnsproxy / TestRemoteAddr

Function TestRemoteAddr

proxy/serverhttps_internal_test.go:247–358  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

245}
246
247func TestRemoteAddr(t *testing.T) {
248 const thePort = 4321
249
250 var (
251 theIP = netip.AddrFrom4([4]byte{1, 2, 3, 4})
252 anotherIP = netip.AddrFrom4([4]byte{1, 2, 3, 5})
253 thirdIP = netip.AddrFrom4([4]byte{1, 2, 3, 6})
254
255 theIPStr = theIP.String()
256 anotherIPStr = anotherIP.String()
257 thirdIPStr = thirdIP.String()
258 )
259
260 rAddr := netip.AddrPortFrom(theIP, thePort)
261
262 testCases := []struct {
263 name string
264 remoteAddr string
265 hdrs map[string]string
266 wantErr string
267 wantIP netip.AddrPort
268 wantProxy netip.AddrPort
269 }{{
270 name: "no_proxy",
271 remoteAddr: rAddr.String(),
272 hdrs: nil,
273 wantErr: "",
274 wantIP: netip.AddrPortFrom(theIP, thePort),
275 wantProxy: netip.AddrPort{},
276 }, {
277 name: "proxied_with_cloudflare",
278 remoteAddr: rAddr.String(),
279 hdrs: map[string]string{
280 "CF-Connecting-IP": anotherIPStr,
281 },
282 wantErr: "",
283 wantIP: netip.AddrPortFrom(anotherIP, 0),
284 wantProxy: netip.AddrPortFrom(theIP, thePort),
285 }, {
286 name: "proxied_once",
287 remoteAddr: rAddr.String(),
288 hdrs: map[string]string{
289 "X-Forwarded-For": anotherIPStr,
290 },
291 wantErr: "",
292 wantIP: netip.AddrPortFrom(anotherIP, 0),
293 wantProxy: netip.AddrPortFrom(theIP, thePort),
294 }, {
295 name: "proxied_multiple",
296 remoteAddr: rAddr.String(),
297 hdrs: map[string]string{
298 "X-Forwarded-For": strings.Join([]string{anotherIPStr, thirdIPStr}, ","),
299 },
300 wantErr: "",
301 wantIP: netip.AddrPortFrom(anotherIP, 0),
302 wantProxy: netip.AddrPortFrom(theIP, thePort),
303 }, {
304 name: "no_port",

Callers

nothing calls this directly

Calls 3

remoteAddrFunction · 0.85
StringMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…