From 1d277dff31d22355efad12f65c176d79171fa6cf Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 22 Jun 2022 19:05:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/iplibrary/list_utils.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/internal/iplibrary/list_utils.go b/internal/iplibrary/list_utils.go index bd2d604..1f96692 100644 --- a/internal/iplibrary/list_utils.go +++ b/internal/iplibrary/list_utils.go @@ -5,14 +5,23 @@ package iplibrary import ( "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/TeaOSLab/EdgeNode/internal/utils" + "github.com/iwind/TeaGo/Tea" ) // AllowIP 检查IP是否被允许访问 // 如果一个IP不在任何名单中,则允许访问 func AllowIP(ip string, serverId int64) (canGoNext bool, inAllowList bool) { - // 放行lo - if ip == "127.0.0.1" { - return true, true + if !Tea.IsTesting() { // 如果在测试环境,我们不加入一些白名单,以便于可以在本地和局域网正常测试 + // 放行lo + if ip == "127.0.0.1" { + return true, true + } + + // check node + nodeConfig, err := nodeconfigs.SharedNodeConfig() + if err == nil && nodeConfig.IPIsAutoAllowed(ip) { + return true, true + } } var ipLong = utils.IP2Long(ip) @@ -20,12 +29,6 @@ func AllowIP(ip string, serverId int64) (canGoNext bool, inAllowList bool) { return false, false } - // check node - nodeConfig, err := nodeconfigs.SharedNodeConfig() - if err == nil && nodeConfig.IPIsAutoAllowed(ip) { - return true, true - } - // check white lists if GlobalWhiteIPList.Contains(ipLong) { return true, true