MCPcopy Index your code
hub / github.com/labstack/echo / TestIPChecker_TrustOption

Function TestIPChecker_TrustOption

ip_test.go:22–63  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20}
21
22func 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
65func TestTrustIPRange(t *testing.T) {
66 var testCases = []struct {

Callers

nothing calls this directly

Calls 7

TrustLoopbackFunction · 0.85
TrustLinkLocalFunction · 0.85
TrustPrivateNetFunction · 0.85
TrustIPRangeFunction · 0.85
mustParseCIDRFunction · 0.85
newIPCheckerFunction · 0.85
trustMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…