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

Function TestTrustIPRange

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

Source from the content-addressed store, hash-verified

63}
64
65func TestTrustIPRange(t *testing.T) {
66 var testCases = []struct {
67 name string
68 givenRange string
69 whenIP string
70 expect bool
71 }{
72 {
73 name: "ip is within trust range, IPV6 network range",
74 // CIDR Notation: 2001:0db8:0000:0000:0000:0000:0000:0000/48
75 // Address: 2001:0db8:0000:0000:0000:0000:0000:0103
76 // Range start: 2001:0db8:0000:0000:0000:0000:0000:0000
77 // Range end: 2001:0db8:0000:ffff:ffff:ffff:ffff:ffff
78 givenRange: "2001:db8::103/48",
79 whenIP: "2001:0db8:0000:0000:0000:0000:0000:0103",
80 expect: true,
81 },
82 {
83 name: "ip is outside (upper bounds) of trust range, IPV6 network range",
84 givenRange: "2001:db8::103/48",
85 whenIP: "2001:0db8:0001:0000:0000:0000:0000:0000",
86 expect: false,
87 },
88 {
89 name: "ip is outside (lower bounds) of trust range, IPV6 network range",
90 givenRange: "2001:db8::103/48",
91 whenIP: "2001:0db7:ffff:ffff:ffff:ffff:ffff:ffff",
92 expect: false,
93 },
94 {
95 name: "ip is within trust range, IPV4 network range",
96 // CIDR Notation: 8.8.8.8/24
97 // Address: 8.8.8.8
98 // Range start: 8.8.8.0
99 // Range end: 8.8.8.255
100 givenRange: "8.8.8.0/24",
101 whenIP: "8.8.8.8",
102 expect: true,
103 },
104 {
105 name: "ip is within trust range, IPV4 network range",
106 // CIDR Notation: 8.8.8.8/24
107 // Address: 8.8.8.8
108 // Range start: 8.8.8.0
109 // Range end: 8.8.8.255
110 givenRange: "8.8.8.0/24",
111 whenIP: "8.8.8.8",
112 expect: true,
113 },
114 {
115 name: "ip is outside (upper bounds) of trust range, IPV4 network range",
116 givenRange: "8.8.8.0/24",
117 whenIP: "8.8.9.0",
118 expect: false,
119 },
120 {
121 name: "ip is outside (lower bounds) of trust range, IPV4 network range",
122 givenRange: "8.8.8.0/24",

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…