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

Function TestAddrsFromRequest

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

Source from the content-addressed store, hash-verified

129}
130
131func TestAddrsFromRequest(t *testing.T) {
132 var (
133 theIP = netip.AddrFrom4([4]byte{1, 2, 3, 4})
134 anotherIP = netip.AddrFrom4([4]byte{1, 2, 3, 5})
135
136 theIPStr = theIP.String()
137 anotherIPStr = anotherIP.String()
138 )
139
140 testCases := []struct {
141 name string
142 hdrs map[string]string
143 wantIP netip.Addr
144 wantErr string
145 }{{
146 name: "cf-connecting-ip",
147 hdrs: map[string]string{
148 "CF-Connecting-IP": theIPStr,
149 },
150 wantIP: theIP,
151 wantErr: "",
152 }, {
153 name: "true-client-ip",
154 hdrs: map[string]string{
155 "True-Client-IP": theIPStr,
156 },
157 wantIP: theIP,
158 wantErr: "",
159 }, {
160 name: "x-real-ip",
161 hdrs: map[string]string{
162 "X-Real-IP": theIPStr,
163 },
164 wantIP: theIP,
165 wantErr: "",
166 }, {
167 name: "no_any",
168 hdrs: map[string]string{
169 "CF-Connecting-IP": "invalid",
170 "True-Client-IP": "invalid",
171 "X-Real-IP": "invalid",
172 },
173 wantIP: netip.Addr{},
174 wantErr: `ParseAddr(""): unable to parse IP`,
175 }, {
176 name: "priority",
177 hdrs: map[string]string{
178 "X-Forwarded-For": strings.Join([]string{anotherIPStr, theIPStr}, ","),
179 "True-Client-IP": anotherIPStr,
180 "X-Real-IP": anotherIPStr,
181 "CF-Connecting-IP": theIPStr,
182 },
183 wantIP: theIP,
184 wantErr: "",
185 }, {
186 name: "x-forwarded-for_simple",
187 hdrs: map[string]string{
188 "X-Forwarded-For": strings.Join([]string{anotherIPStr, theIPStr}, ","),

Callers

nothing calls this directly

Calls 3

realIPFromHdrsFunction · 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…