提交 97f1c784 编写于 作者: K Kenta Iso

add check proxy cidr is valid

上级 cd7d4b81
......@@ -44,6 +44,9 @@ func isInBlock(ip string, block string) (bool, error) {
if i == nil {
return false, fmt.Errorf("parsed IP is nil")
}
if !strings.Contains(block, "/") {
return false, nil
}
_, b, err := net.ParseCIDR(block)
if err != nil {
return false, errors.Wrapf(err, "Error Parsing block %s", b)
......@@ -101,7 +104,11 @@ func checkEnv(ip string, env string) bool {
// Checks if included in IP ranges, i.e., 192.168.39.13/24
noProxyBlocks := strings.Split(v, ",")
for _, b := range noProxyBlocks {
if yes, _ := isInBlock(ip, b); yes {
yes, err := isInBlock(ip, b)
if err != nil {
glog.Errorf("fail to check proxy env: %v", err)
}
if yes {
return true
}
}
......
......@@ -57,7 +57,7 @@ func TestIsInBlock(t *testing.T) {
{"192.168.0.2", "192.168.0.1/32", false, false},
{"192.168.0.1", "192.168.0.1/18", true, false},
{"abcd", "192.168.0.1/18", false, true},
{"192.168.0.1", "foo", false, true},
{"192.168.0.1", "foo", false, false},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%s in %s Want: %t WantAErr: %t", tc.ip, tc.block, tc.want, tc.wanntAErr), func(t *testing.T) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册