aboutsummaryrefslogtreecommitdiff
path: root/internal/netutil/netutil_test.go
diff options
context:
space:
mode:
authorJoe Chen <jc@unknwon.io>2022-03-14 22:06:08 +0800
committerGitHub <noreply@github.com>2022-03-14 22:06:08 +0800
commit714383a063f64fcc7c6a458182c4f9cf5a46df66 (patch)
treeebed76f917e9817cd78c4dda07813f93f3bb16bd /internal/netutil/netutil_test.go
parenta2c632526111b3333de482c69709a7ca70a173f8 (diff)
conf: add allowlist for accessing local network (#6842)
Diffstat (limited to 'internal/netutil/netutil_test.go')
-rw-r--r--internal/netutil/netutil_test.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/internal/netutil/netutil_test.go b/internal/netutil/netutil_test.go
index 47be4e74..c65af2c0 100644
--- a/internal/netutil/netutil_test.go
+++ b/internal/netutil/netutil_test.go
@@ -12,8 +12,9 @@ import (
func TestIsLocalHostname(t *testing.T) {
tests := []struct {
- hostname string
- want bool
+ hostname string
+ allowlist []string
+ want bool
}{
{hostname: "localhost", want: true},
{hostname: "127.0.0.1", want: true},
@@ -27,10 +28,13 @@ func TestIsLocalHostname(t *testing.T) {
{hostname: "gogs.io", want: false},
{hostname: "google.com", want: false},
{hostname: "165.232.140.255", want: false},
+
+ {hostname: "192.168.123.45", allowlist: []string{"10.0.0.17"}, want: true},
+ {hostname: "gogs.local", allowlist: []string{"gogs.local"}, want: false},
}
for _, test := range tests {
t.Run("", func(t *testing.T) {
- assert.Equal(t, test.want, IsLocalHostname(test.hostname))
+ assert.Equal(t, test.want, IsLocalHostname(test.hostname, test.allowlist))
})
}
}