Skip to content

Commit

Permalink
Drop validation.IsValidSocketAddr
Browse files Browse the repository at this point in the history
It's not used anywhere, and if someone was going to validate an
IP:port somewhere, they should think about exactly what they want
rather than just using this function. (E.g., validation should be
slightly different for an IP:port to bind to vs an IP:port to connect
to.)

Kubernetes-commit: 8fc691be940e73dac324e92c3207ed03df74b1ca
  • Loading branch information
danwinship authored and k8s-publishing-bot committed Jan 23, 2024
1 parent f14778d commit 8d387a6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 45 deletions.
17 changes: 0 additions & 17 deletions pkg/util/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ package validation
import (
"fmt"
"math"
"net"
"regexp"
"strconv"
"strings"

"k8s.io/apimachinery/pkg/util/validation/field"
Expand Down Expand Up @@ -493,18 +491,3 @@ func hasChDirPrefix(value string) []string {
}
return errs
}

// IsValidSocketAddr checks that string represents a valid socket address
// as defined in RFC 789. (e.g 0.0.0.0:10254 or [::]:10254))
func IsValidSocketAddr(value string) []string {
var errs []string
ip, port, err := net.SplitHostPort(value)
if err != nil {
errs = append(errs, "must be a valid socket address format, (e.g. 0.0.0.0:10254 or [::]:10254)")
return errs
}
portInt, _ := strconv.Atoi(port)
errs = append(errs, IsValidPortNum(portInt)...)
errs = append(errs, IsValidIP(ip)...)
return errs
}
28 changes: 0 additions & 28 deletions pkg/util/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,31 +710,3 @@ func TestIsDomainPrefixedPath(t *testing.T) {
}
}
}

func TestIsValidSocketAddr(t *testing.T) {
goodValues := []string{
"0.0.0.0:10254",
"127.0.0.1:8888",
"[2001:db8:1f70::999:de8:7648:6e8]:10254",
"[::]:10254",
}
for _, val := range goodValues {
if errs := IsValidSocketAddr(val); len(errs) != 0 {
t.Errorf("expected no errors for %q: %v", val, errs)
}
}

badValues := []string{
"0.0.0.0.0:2020",
"0.0.0.0",
"6.6.6.6:909090",
"2001:db8:1f70::999:de8:7648:6e8:87567:102545",
"",
"*",
}
for _, val := range badValues {
if errs := IsValidSocketAddr(val); len(errs) == 0 {
t.Errorf("expected errors for %q", val)
}
}
}

0 comments on commit 8d387a6

Please sign in to comment.