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 28, 2018
1 parent b8ab124 commit bf26320
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 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
40 changes: 20 additions & 20 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,7 +62,7 @@ func TestValidateClusterServiceClass(t *testing.T) {
valid: true,
},
{
name: "valid serviceClass - period in GUID",
name: "valid serviceClass - period in externalID",
serviceClass: func() *servicecatalog.ClusterServiceClass {
s := validClusterServiceClass()
s.Spec.ExternalID = "4315f5e1-0139-4ecf-9706-9df0aff33e5a.plan-name"
Expand All @@ -71,37 +71,37 @@ func TestValidateClusterServiceClass(t *testing.T) {
valid: true,
},
{
name: "valid serviceClass - period in externalName",
name: "valid serviceClass - underscore in ExternalID",
serviceClass: func() *servicecatalog.ClusterServiceClass {
s := validClusterServiceClass()
s.Spec.ExternalName = "abc.com"
s.Spec.ExternalID = "4315f5e1-0139-4ecf-9706-9df0aff33e5a_plan-name"
return s
}(),
valid: true,
},
{
name: "invalid serviceClass - has namespace",
name: "valid serviceClass - period in externalName",
serviceClass: func() *servicecatalog.ClusterServiceClass {
s := validClusterServiceClass()
s.Namespace = "test-ns"
s.Spec.ExternalName = "abc.com"
return s
}(),
valid: false,
valid: true,
},
{
name: "invalid serviceClass - missing guid",
name: "invalid serviceClass - has namespace",
serviceClass: func() *servicecatalog.ClusterServiceClass {
s := validClusterServiceClass()
s.Spec.ExternalID = ""
s.Namespace = "test-ns"
return s
}(),
valid: false,
},
{
name: "invalid serviceClass - invalid guid",
name: "invalid serviceClass - empty 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 +203,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 +212,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 All @@ -230,28 +230,28 @@ func TestValidateServiceClass(t *testing.T) {
valid: true,
},
{
name: "invalid serviceClass - has no namespace",
name: "valid serviceClass - underscore in ExternalID",
serviceClass: func() *servicecatalog.ServiceClass {
s := validServiceClass()
s.Namespace = ""
s.Spec.ExternalID = "4315f5e1-0139-4ecf-9706-9df0aff33e5a_plan-name"
return s
}(),
valid: false,
valid: true,
},
{
name: "invalid serviceClass - missing guid",
name: "invalid serviceClass - has no namespace",
serviceClass: func() *servicecatalog.ServiceClass {
s := validServiceClass()
s.Spec.ExternalID = ""
s.Namespace = ""
return s
}(),
valid: false,
},
{
name: "invalid serviceClass - invalid guid",
name: "invalid serviceClass - empty 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 bf26320

Please sign in to comment.