1 package acp_test
2
3 import (
4 "testing"
5
6 "github.com/emissary-ingress/emissary/v3/pkg/acp"
7 )
8
9 func check(t *testing.T, hostport string, wanted bool) {
10 if acp.HostPortIsLocal(hostport) != wanted {
11 t.Errorf("HostPort %s: wanted %v, got %v", hostport, wanted, acp.HostPortIsLocal(hostport))
12 }
13 }
14
15 func TestHostIsLocal(t *testing.T) {
16
17 check(t, "localhost", false)
18 check(t, "127.0.0.1", false)
19 check(t, "LOCALHOST", false)
20 check(t, "127.0.0.2", false)
21 check(t, "LoCalHosT", false)
22 check(t, "localhostt", false)
23 check(t, "localhop", false)
24 check(t, "::1", false)
25 check(t, "::2", false)
26
27 check(t, "localhost:9999", true)
28 check(t, "127.0.0.1:9999", true)
29 check(t, "LOCALHOST:9999", false)
30 check(t, "127.0.0.2:9999", false)
31 check(t, "LoCalHosT:9999", false)
32 check(t, "localhostt:9999", false)
33 check(t, "localhop:9999", false)
34 check(t, "[::1]:9999", true)
35 check(t, "[::2]:9999", false)
36
37
38
39 check(t, "[::1]", false)
40 check(t, "[::2]", false)
41 }
42
View as plain text