|
@@ -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))
|
|
|
})
|
|
|
}
|
|
|
}
|