mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	remove not needed (#19128)
This commit is contained in:
		@@ -8,8 +8,6 @@ import (
 | 
				
			|||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	"code.gitea.io/gitea/modules/util"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// HostMatchList is used to check if a host or IP is in a list.
 | 
					// HostMatchList is used to check if a host or IP is in a list.
 | 
				
			||||||
@@ -104,11 +102,11 @@ func (hl *HostMatchList) checkIP(ip net.IP) bool {
 | 
				
			|||||||
	for _, builtin := range hl.builtins {
 | 
						for _, builtin := range hl.builtins {
 | 
				
			||||||
		switch builtin {
 | 
							switch builtin {
 | 
				
			||||||
		case MatchBuiltinExternal:
 | 
							case MatchBuiltinExternal:
 | 
				
			||||||
			if ip.IsGlobalUnicast() && !util.IsIPPrivate(ip) {
 | 
								if ip.IsGlobalUnicast() && !ip.IsPrivate() {
 | 
				
			||||||
				return true
 | 
									return true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		case MatchBuiltinPrivate:
 | 
							case MatchBuiltinPrivate:
 | 
				
			||||||
			if util.IsIPPrivate(ip) {
 | 
								if ip.IsPrivate() {
 | 
				
			||||||
				return true
 | 
									return true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		case MatchBuiltinLoopback:
 | 
							case MatchBuiltinLoopback:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,13 +0,0 @@
 | 
				
			|||||||
// Copyright 2021 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"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func IsIPPrivate(ip net.IP) bool {
 | 
					 | 
				
			||||||
	return ip.IsPrivate()
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,56 +0,0 @@
 | 
				
			|||||||
// 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)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user