(t *testing.T)
| 203 | } |
| 204 | |
| 205 | func TestGetSourceIPsFullExtract(t *testing.T) { |
| 206 | tests := []struct { |
| 207 | name string |
| 208 | req *http.Request |
| 209 | want string |
| 210 | }{ |
| 211 | { |
| 212 | name: "no header", |
| 213 | req: &http.Request{RemoteAddr: "192.168.1.100:3454"}, |
| 214 | want: "192.168.1.100", |
| 215 | }, |
| 216 | { |
| 217 | name: "no header and remote has no port", |
| 218 | req: &http.Request{RemoteAddr: "192.168.1.100"}, |
| 219 | want: "192.168.1.100", |
| 220 | }, |
| 221 | { |
| 222 | name: "no header, remote address is invalid", |
| 223 | req: &http.Request{RemoteAddr: "192.168.100"}, |
| 224 | want: "192.168.100", |
| 225 | }, |
| 226 | { |
| 227 | name: "X-Forwarded-For and single forward address", |
| 228 | req: &http.Request{ |
| 229 | RemoteAddr: "192.168.1.100:3454", |
| 230 | Header: map[string][]string{ |
| 231 | http.CanonicalHeaderKey(xForwardedFor): {"172.16.1.1"}, |
| 232 | }, |
| 233 | }, |
| 234 | want: "172.16.1.1, 192.168.1.100", |
| 235 | }, |
| 236 | { |
| 237 | name: "X-Forwarded-For and single forward address which is same as remote", |
| 238 | req: &http.Request{ |
| 239 | RemoteAddr: "192.168.1.100:3454", |
| 240 | Header: map[string][]string{ |
| 241 | http.CanonicalHeaderKey(xForwardedFor): {"192.168.1.100"}, |
| 242 | }, |
| 243 | }, |
| 244 | want: "192.168.1.100", |
| 245 | }, |
| 246 | { |
| 247 | name: "single IPv6 X-Forwarded-For address", |
| 248 | req: &http.Request{ |
| 249 | RemoteAddr: "[2001:db9::1]:3454", |
| 250 | Header: map[string][]string{ |
| 251 | http.CanonicalHeaderKey(xForwardedFor): {"2001:db8::1"}, |
| 252 | }, |
| 253 | }, |
| 254 | want: "2001:db8::1, 2001:db9::1", |
| 255 | }, |
| 256 | { |
| 257 | name: "single X-Forwarded-For address no RemoteAddr", |
| 258 | req: &http.Request{ |
| 259 | Header: map[string][]string{ |
| 260 | http.CanonicalHeaderKey(xForwardedFor): {"172.16.1.1"}, |
| 261 | }, |
| 262 | }, |
nothing calls this directly
no test coverage detected