Merge pull request #9919 from liggitt/port_protocol_validation

Validate port protocol case strictly
This commit is contained in:
Satnam Singh 2015-06-19 15:18:03 -07:00
commit 3591a543d1
3 changed files with 9 additions and 8 deletions

View File

@ -610,7 +610,7 @@ func validatePorts(ports []api.ContainerPort) errs.ValidationErrorList {
}
if len(port.Protocol) == 0 {
pErrs = append(pErrs, errs.NewFieldRequired("protocol"))
} else if !supportedPortProtocols.Has(strings.ToUpper(string(port.Protocol))) {
} else if !supportedPortProtocols.Has(string(port.Protocol)) {
pErrs = append(pErrs, errs.NewFieldNotSupported("protocol", port.Protocol))
}
allErrs = append(allErrs, pErrs.PrefixIndex(i)...)
@ -1144,7 +1144,7 @@ func validateServicePort(sp *api.ServicePort, requireName bool, allNames *util.S
if len(sp.Protocol) == 0 {
allErrs = append(allErrs, errs.NewFieldRequired("protocol"))
} else if !supportedPortProtocols.Has(strings.ToUpper(string(sp.Protocol))) {
} else if !supportedPortProtocols.Has(string(sp.Protocol)) {
allErrs = append(allErrs, errs.NewFieldNotSupported("protocol", sp.Protocol))
}
@ -1680,7 +1680,7 @@ func validateEndpointPort(port *api.EndpointPort, requireName bool) errs.Validat
}
if len(port.Protocol) == 0 {
allErrs = append(allErrs, errs.NewFieldRequired("protocol"))
} else if !supportedPortProtocols.Has(strings.ToUpper(string(port.Protocol))) {
} else if !supportedPortProtocols.Has(string(port.Protocol)) {
allErrs = append(allErrs, errs.NewFieldNotSupported("protocol", port.Protocol))
}
return allErrs

View File

@ -493,7 +493,6 @@ func TestValidatePorts(t *testing.T) {
{Name: "easy", ContainerPort: 82, Protocol: "TCP"},
{Name: "as", ContainerPort: 83, Protocol: "UDP"},
{Name: "do-re-me", ContainerPort: 84, Protocol: "UDP"},
{Name: "baby-you-and-me", ContainerPort: 82, Protocol: "tcp"},
{ContainerPort: 85, Protocol: "TCP"},
}
if errs := validatePorts(successCase); len(errs) != 0 {
@ -522,6 +521,7 @@ func TestValidatePorts(t *testing.T) {
"zero container port": {[]api.ContainerPort{{ContainerPort: 0, Protocol: "TCP"}}, errors.ValidationErrorTypeInvalid, "[0].containerPort", portRangeErrorMsg},
"invalid container port": {[]api.ContainerPort{{ContainerPort: 65536, Protocol: "TCP"}}, errors.ValidationErrorTypeInvalid, "[0].containerPort", portRangeErrorMsg},
"invalid host port": {[]api.ContainerPort{{ContainerPort: 80, HostPort: 65536, Protocol: "TCP"}}, errors.ValidationErrorTypeInvalid, "[0].hostPort", portRangeErrorMsg},
"invalid protocol case": {[]api.ContainerPort{{ContainerPort: 80, Protocol: "tcp"}}, errors.ValidationErrorTypeNotSupported, "[0].protocol", ""},
"invalid protocol": {[]api.ContainerPort{{ContainerPort: 80, Protocol: "ICMP"}}, errors.ValidationErrorTypeNotSupported, "[0].protocol", ""},
"protocol required": {[]api.ContainerPort{{Name: "abc", ContainerPort: 80}}, errors.ValidationErrorTypeRequired, "[0].protocol", ""},
}

View File

@ -18,6 +18,9 @@ package e2e
import (
"fmt"
"strings"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
@ -25,8 +28,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
"strings"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -237,7 +238,7 @@ var _ = Describe("DNS", func() {
Spec: api.ServiceSpec{
ClusterIP: "None",
Ports: []api.ServicePort{
{Port: 80, Name: "http", Protocol: "tcp"},
{Port: 80, Name: "http", Protocol: "TCP"},
},
Selector: testServiceSelector,
},
@ -257,7 +258,7 @@ var _ = Describe("DNS", func() {
},
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{Port: 80, Name: "http", Protocol: "tcp"},
{Port: 80, Name: "http", Protocol: "TCP"},
},
Selector: testServiceSelector,
},