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

Function TestTrustLoopback

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

Source from the content-addressed store, hash-verified

329}
330
331func 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
369func TestExtractIPDirect(t *testing.T) {
370 var testCases = []struct {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…