Skip to content

Commit

Permalink
Validate ConfigMapRef and SecretRef name
Browse files Browse the repository at this point in the history
  • Loading branch information
fraenkel committed Feb 24, 2017
1 parent ee88325 commit 62bd5d3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,10 @@ func validateConfigMapEnvSource(configMapSource *api.ConfigMapEnvSource, fldPath
allErrs := field.ErrorList{}
if len(configMapSource.Name) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("name"), ""))
} else {
for _, msg := range ValidateConfigMapName(configMapSource.Name, true) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("name"), configMapSource.Name, msg))
}
}
return allErrs
}
Expand All @@ -1407,6 +1411,10 @@ func validateSecretEnvSource(secretSource *api.SecretEnvSource, fldPath *field.P
allErrs := field.ErrorList{}
if len(secretSource.Name) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("name"), ""))
} else {
for _, msg := range ValidateSecretName(secretSource.Name, true) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("name"), secretSource.Name, msg))
}
}
return allErrs
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/api/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2316,6 +2316,16 @@ func TestValidateEnvFrom(t *testing.T) {
},
expectedError: "field[0].configMapRef.name: Required value",
},
{
name: "invalid name",
envs: []api.EnvFromSource{
{
ConfigMapRef: &api.ConfigMapEnvSource{
LocalObjectReference: api.LocalObjectReference{Name: "$"}},
},
},
expectedError: "field[0].configMapRef.name: Invalid value",
},
{
name: "invalid prefix",
envs: []api.EnvFromSource{
Expand All @@ -2337,6 +2347,16 @@ func TestValidateEnvFrom(t *testing.T) {
},
expectedError: "field[0].secretRef.name: Required value",
},
{
name: "invalid name",
envs: []api.EnvFromSource{
{
SecretRef: &api.SecretEnvSource{
LocalObjectReference: api.LocalObjectReference{Name: "&"}},
},
},
expectedError: "field[0].secretRef.name: Invalid value",
},
{
name: "invalid prefix",
envs: []api.EnvFromSource{
Expand Down

0 comments on commit 62bd5d3

Please sign in to comment.