(t *testing.T)
| 276 | } |
| 277 | |
| 278 | func TestTrustLinkLocal(t *testing.T) { |
| 279 | var testCases = []struct { |
| 280 | name string |
| 281 | whenIP string |
| 282 | expect bool |
| 283 | }{ |
| 284 | { |
| 285 | name: "trust link local IPv4 address (lower bounds)", |
| 286 | whenIP: "169.254.0.0", |
| 287 | expect: true, |
| 288 | }, |
| 289 | { |
| 290 | name: "trust link local IPv4 address (upper bounds)", |
| 291 | whenIP: "169.254.255.255", |
| 292 | expect: true, |
| 293 | }, |
| 294 | { |
| 295 | name: "do not trust link local IPv4 address (outside of lower bounds)", |
| 296 | whenIP: "169.253.255.255", |
| 297 | expect: false, |
| 298 | }, |
| 299 | { |
| 300 | name: "do not trust link local IPv4 address (outside of upper bounds)", |
| 301 | whenIP: "169.255.0.0", |
| 302 | expect: false, |
| 303 | }, |
| 304 | { |
| 305 | name: "trust link local IPv6 address ", |
| 306 | whenIP: "fe80::1", |
| 307 | expect: true, |
| 308 | }, |
| 309 | { |
| 310 | name: "do not trust link local IPv6 address ", |
| 311 | whenIP: "fec0::1", |
| 312 | expect: false, |
| 313 | }, |
| 314 | } |
| 315 | |
| 316 | for _, tc := range testCases { |
| 317 | t.Run(tc.name, func(t *testing.T) { |
| 318 | checker := newIPChecker([]TrustOption{ |
| 319 | TrustLoopback(false), // disable to avoid interference |
| 320 | TrustPrivateNet(false), // disable to avoid interference |
| 321 | |
| 322 | TrustLinkLocal(true), |
| 323 | }) |
| 324 | |
| 325 | result := checker.trust(net.ParseIP(tc.whenIP)) |
| 326 | assert.Equal(t, tc.expect, result) |
| 327 | }) |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | func TestTrustLoopback(t *testing.T) { |
| 332 | var testCases = []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…