Validate Service.Spec.publicIPs to be a valid IP that is not a localhost
This commit is contained in:
@@ -222,3 +222,33 @@ func TestIsValidLabelValue(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsValidIP(t *testing.T) {
|
||||
goodValues := []string{
|
||||
"1.1.1.1",
|
||||
"1.1.1.01",
|
||||
"255.0.0.1",
|
||||
"1.0.0.0",
|
||||
"0.0.0.0",
|
||||
}
|
||||
for _, val := range goodValues {
|
||||
if !IsValidIP(val) {
|
||||
t.Errorf("expected true for %q", val)
|
||||
}
|
||||
}
|
||||
|
||||
badValues := []string{
|
||||
"2a00:79e0:2:0:f1c3:e797:93c1:df80", // This is valid IPv6
|
||||
"a",
|
||||
"myhost.mydomain",
|
||||
"-1.0.0.0",
|
||||
"1.0.0.256",
|
||||
"1.0.0.1.1",
|
||||
"1.0.0.1.",
|
||||
}
|
||||
for _, val := range badValues {
|
||||
if IsValidIP(val) {
|
||||
t.Errorf("expected false for %q", val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user