(t *testing.T)
| 329 | } |
| 330 | |
| 331 | func TestTrustLoopback(t *testing.T) { |
| 332 | var testCases = []struct { |
| 333 | name string |
| 334 | whenIP string |
| 335 | expect bool |
| 336 | }{ |
| 337 | { |
| 338 | name: "trust IPv4 as localhost", |
| 339 | whenIP: "127.0.0.1", |
| 340 | expect: true, |
| 341 | }, |
| 342 | { |
| 343 | name: "trust IPv6 as localhost", |
| 344 | whenIP: "::1", |
| 345 | expect: true, |
| 346 | }, |
| 347 | { |
| 348 | name: "do not trust public ip as localhost", |
| 349 | whenIP: "8.8.8.8", |
| 350 | expect: false, |
| 351 | }, |
| 352 | } |
| 353 | |
| 354 | for _, tc := range testCases { |
| 355 | t.Run(tc.name, func(t *testing.T) { |
| 356 | checker := newIPChecker([]TrustOption{ |
| 357 | TrustLinkLocal(false), // disable to avoid interference |
| 358 | TrustPrivateNet(false), // disable to avoid interference |
| 359 | |
| 360 | TrustLoopback(true), |
| 361 | }) |
| 362 | |
| 363 | result := checker.trust(net.ParseIP(tc.whenIP)) |
| 364 | assert.Equal(t, tc.expect, result) |
| 365 | }) |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | func TestExtractIPDirect(t *testing.T) { |
| 370 | var testCases = []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…