Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Remove regex validation of service class external IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
jberkhahn committed Aug 27, 2018
1 parent b8ab124 commit ec31964
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
9 changes: 2 additions & 7 deletions pkg/apis/servicecatalog/validation/serviceclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@ const commonServiceClassNameMaxLength int = 63

var commonServiceClassNameRegexp = regexp.MustCompile("^" + commonServiceClassNameFmt + "$")

const guidFmt string = "[a-zA-Z0-9]([-a-zA-Z0-9.]*[a-zA-Z0-9])?"
const guidMaxLength int = 63

// guidRegexp is a loosened validation for
// DNS1123 labels that allows uppercase characters.
var guidRegexp = regexp.MustCompile("^" + guidFmt + "$")

// validateCommonServiceClassName is the common validation function for
// service class types.
func validateCommonServiceClassName(value string, prefix bool) []string {
Expand All @@ -64,8 +59,8 @@ func validateExternalID(value string) []string {
if len(value) > guidMaxLength {
errs = append(errs, utilvalidation.MaxLenError(guidMaxLength))
}
if !guidRegexp.MatchString(value) {
errs = append(errs, utilvalidation.RegexError(guidFmt, "my-name", "123-abc", "456-DEF"))
if len(value) == 0 {
errs = append(errs, utilvalidation.EmptyError())
}
return errs
}
Expand Down
25 changes: 17 additions & 8 deletions pkg/apis/servicecatalog/validation/serviceclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestValidateClusterServiceClass(t *testing.T) {
valid: true,
},
{
name: "valid serviceClass - uppercase in GUID",
name: "valid serviceClass - uppercase in externalID",
serviceClass: func() *servicecatalog.ClusterServiceClass {
s := validClusterServiceClass()
s.Spec.ExternalID = "40D-0983-1b89"
Expand All @@ -62,14 +62,23 @@ func TestValidateClusterServiceClass(t *testing.T) {
valid: true,
},
{
name: "valid serviceClass - period in GUID",
name: "valid serviceClass - period in externalID:2",
serviceClass: func() *servicecatalog.ClusterServiceClass {
s := validClusterServiceClass()
s.Spec.ExternalID = "4315f5e1-0139-4ecf-9706-9df0aff33e5a.plan-name"
return s
}(),
valid: true,
},
{
name: "valid serviceClass - underscore in ExternalID",
serviceClass: func() *servicecatalog.ClusterServiceClass {
s := validClusterServiceClass()
s.Spec.ExternalID = "4315f5e1-0139-4ecf-9706-9df0aff33e5a_plan-name"
return s
}(),
valid: true,
},
{
name: "valid serviceClass - period in externalName",
serviceClass: func() *servicecatalog.ClusterServiceClass {
Expand Down Expand Up @@ -98,10 +107,10 @@ func TestValidateClusterServiceClass(t *testing.T) {
valid: false,
},
{
name: "invalid serviceClass - invalid guid",
name: "invalid serviceClass - invalid externalID",
serviceClass: func() *servicecatalog.ClusterServiceClass {
s := validClusterServiceClass()
s.Spec.ExternalID = "1234-4354a\\%-49b"
s.Spec.ExternalID = ""
return s
}(),
valid: false,
Expand Down Expand Up @@ -203,7 +212,7 @@ func TestValidateServiceClass(t *testing.T) {
valid: true,
},
{
name: "valid serviceClass - uppercase in GUID",
name: "valid serviceClass - uppercase in externalID",
serviceClass: func() *servicecatalog.ServiceClass {
s := validServiceClass()
s.Spec.ExternalID = "40D-0983-1b89"
Expand All @@ -212,7 +221,7 @@ func TestValidateServiceClass(t *testing.T) {
valid: true,
},
{
name: "valid serviceClass - period in GUID",
name: "valid serviceClass - period in externalID",
serviceClass: func() *servicecatalog.ServiceClass {
s := validServiceClass()
s.Spec.ExternalID = "4315f5e1-0139-4ecf-9706-9df0aff33e5a.plan-name"
Expand Down Expand Up @@ -248,10 +257,10 @@ func TestValidateServiceClass(t *testing.T) {
valid: false,
},
{
name: "invalid serviceClass - invalid guid",
name: "invalid serviceClass - invalid externalID",
serviceClass: func() *servicecatalog.ServiceClass {
s := validServiceClass()
s.Spec.ExternalID = "1234-4354a\\%-49b"
s.Spec.ExternalID = ""
return s
}(),
valid: false,
Expand Down

0 comments on commit ec31964

Please sign in to comment.