|
@@ -17,6 +17,7 @@ package driver
|
17
|
17
|
import (
|
18
|
18
|
"fmt"
|
19
|
19
|
"io/ioutil"
|
|
20
|
+ "net"
|
20
|
21
|
"net/http"
|
21
|
22
|
"net/http/httptest"
|
22
|
23
|
"net/url"
|
|
@@ -235,3 +236,16 @@ func TestNewListenerAndURL(t *testing.T) {
|
235
|
236
|
})
|
236
|
237
|
}
|
237
|
238
|
}
|
|
239
|
+
|
|
240
|
+func TestIsLocalHost(t *testing.T) {
|
|
241
|
+ for _, s := range []string{"localhost:10000", "[::1]:10000", "127.0.0.1:10000"} {
|
|
242
|
+ host, _, err := net.SplitHostPort(s)
|
|
243
|
+ if err != nil {
|
|
244
|
+ t.Error("unexpected error when splitting", s)
|
|
245
|
+ continue
|
|
246
|
+ }
|
|
247
|
+ if !isLocalhost(host) {
|
|
248
|
+ t.Errorf("host %s from %s not considered local", host, s)
|
|
249
|
+ }
|
|
250
|
+ }
|
|
251
|
+}
|