summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authortechknowlogick <techknowlogick@gitea.io>2022-03-16 00:08:31 -0400
committerGitHub <noreply@github.com>2022-03-16 00:08:31 -0400
commited1d95c55dfa91d1c9a486bfb8e00375d4038e29 (patch)
tree5c4e1cc6deff4ddbbb7fc9431ab8c0d94efe69fa /modules
parentfe9626af296f7c7893af8cff88bc4195724bea07 (diff)
downloadgitea-ed1d95c55dfa91d1c9a486bfb8e00375d4038e29.tar.gz
gitea-ed1d95c55dfa91d1c9a486bfb8e00375d4038e29.zip
use go1.18 to build gitea (#19099)
* use go1.18 to build gitea& update min go version to 1.17 * bump in a few more places * add a few simple tests for isipprivate * update go.mod * update URL to https://go.dev/dl/ * golangci-lint * attempt golangci-lint workaround * change version * bump fumpt version * skip strings.title test * go mod tidy * update tests as some aren't private?? * update tests
Diffstat (limited to 'modules')
-rw-r--r--modules/util/net.go8
-rw-r--r--modules/util/net_test.go56
2 files changed, 57 insertions, 7 deletions
diff --git a/modules/util/net.go b/modules/util/net.go
index 54c0a2ca39..0339325dc3 100644
--- a/modules/util/net.go
+++ b/modules/util/net.go
@@ -8,12 +8,6 @@ import (
"net"
)
-// IsIPPrivate for net.IP.IsPrivate. TODO: replace with `ip.IsPrivate()` if min go version is bumped to 1.17
func IsIPPrivate(ip net.IP) bool {
- if ip4 := ip.To4(); ip4 != nil {
- return ip4[0] == 10 ||
- (ip4[0] == 172 && ip4[1]&0xf0 == 16) ||
- (ip4[0] == 192 && ip4[1] == 168)
- }
- return len(ip) == net.IPv6len && ip[0]&0xfe == 0xfc
+ return ip.IsPrivate()
}
diff --git a/modules/util/net_test.go b/modules/util/net_test.go
new file mode 100644
index 0000000000..93a95ab123
--- /dev/null
+++ b/modules/util/net_test.go
@@ -0,0 +1,56 @@
+// Copyright 2022 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package util
+
+import (
+ "net"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestIsIPPPrivate(t *testing.T) {
+ cases := []struct {
+ ip string
+ isPrivate bool
+ }{
+ // case 0
+ {
+ ip: "127.0.0.1",
+ isPrivate: false, // TODO: according to go, this isn't private?
+ },
+ // case 1
+ {
+ ip: "127.1.2.3",
+ isPrivate: false, // TODO: according to go, this isn't private?
+ },
+ // case 2
+ {
+ ip: "10.255.255.0",
+ isPrivate: true,
+ },
+ // case 3
+ {
+ ip: "8.8.8.8",
+ isPrivate: false,
+ },
+ // case 4
+ {
+ ip: "::1",
+ isPrivate: false, // TODO: according to go, this isn't private?
+ },
+ // case 4
+ {
+ ip: "2a12:7c40::f00d",
+ isPrivate: false,
+ },
+ }
+
+ for n, c := range cases {
+ i := net.ParseIP(c.ip)
+ p := IsIPPrivate(i)
+ assert.Equal(t, c.isPrivate, p, "case %d: should be equal", n)
+ }
+}