(t *testing.T)
| 20 | } |
| 21 | |
| 22 | func TestIPChecker_TrustOption(t *testing.T) { |
| 23 | var testCases = []struct { |
| 24 | name string |
| 25 | whenIP string |
| 26 | givenOptions []TrustOption |
| 27 | expect bool |
| 28 | }{ |
| 29 | { |
| 30 | name: "ip is within trust range, trusts additional private IPV6 network", |
| 31 | givenOptions: []TrustOption{ |
| 32 | TrustLoopback(false), |
| 33 | TrustLinkLocal(false), |
| 34 | TrustPrivateNet(false), |
| 35 | // this is private IPv6 ip |
| 36 | // CIDR Notation: 2001:0db8:0000:0000:0000:0000:0000:0000/48 |
| 37 | // Address: 2001:0db8:0000:0000:0000:0000:0000:0103 |
| 38 | // Range start: 2001:0db8:0000:0000:0000:0000:0000:0000 |
| 39 | // Range end: 2001:0db8:0000:ffff:ffff:ffff:ffff:ffff |
| 40 | TrustIPRange(mustParseCIDR("2001:db8::103/48")), |
| 41 | }, |
| 42 | whenIP: "2001:0db8:0000:0000:0000:0000:0000:0103", |
| 43 | expect: true, |
| 44 | }, |
| 45 | { |
| 46 | name: "ip is within trust range, trusts additional private IPV6 network", |
| 47 | givenOptions: []TrustOption{ |
| 48 | TrustIPRange(mustParseCIDR("2001:db8::103/48")), |
| 49 | }, |
| 50 | whenIP: "2001:0db8:0000:0000:0000:0000:0000:0103", |
| 51 | expect: true, |
| 52 | }, |
| 53 | } |
| 54 | |
| 55 | for _, tc := range testCases { |
| 56 | t.Run(tc.name, func(t *testing.T) { |
| 57 | checker := newIPChecker(tc.givenOptions) |
| 58 | |
| 59 | result := checker.trust(net.ParseIP(tc.whenIP)) |
| 60 | assert.Equal(t, tc.expect, result) |
| 61 | }) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | func TestTrustIPRange(t *testing.T) { |
| 66 | var testCases = []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…