forked from elazarl/goproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdispatcher_test.go
More file actions
50 lines (45 loc) · 841 Bytes
/
dispatcher_test.go
File metadata and controls
50 lines (45 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package goproxy_test
import (
"context"
"net"
"net/http"
"strings"
"testing"
"github.com/elazarl/goproxy"
)
func TestIsLocalHost(t *testing.T) {
hosts := []string{
"localhost",
"127.0.0.1",
"127.0.0.7",
"::ffff:127.0.0.1",
"::ffff:127.0.0.7",
"::1",
"0:0:0:0:0:0:0:1",
}
ports := []string{
"",
"80",
"443",
}
for _, host := range hosts {
for _, port := range ports {
if port == "" && strings.HasPrefix(host, "::ffff:") {
continue
}
addr := host
if port != "" {
addr = net.JoinHostPort(host, port)
}
t.Run(addr, func(t *testing.T) {
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "http://"+addr, http.NoBody)
if err != nil {
t.Fatal(err)
}
if !goproxy.IsLocalHost(req, nil) {
t.Fatal("expected true")
}
})
}
}
}