Validate kubernetes.io/dockerconfigjson secrets

Added unit test.
This commit is contained in:
Eric Tune
2015-12-16 14:13:18 -08:00
parent 810544633e
commit 4a3d4defdf
2 changed files with 37 additions and 7 deletions

View File

@@ -1916,6 +1916,17 @@ func ValidateSecret(secret *api.Secret) field.ErrorList {
if err := json.Unmarshal(dockercfgBytes, &map[string]interface{}{}); err != nil {
allErrs = append(allErrs, field.Invalid(dataPath.Key(api.DockerConfigKey), "<secret contents redacted>", err.Error()))
}
case api.SecretTypeDockerConfigJson:
dockerConfigJsonBytes, exists := secret.Data[api.DockerConfigJsonKey]
if !exists {
allErrs = append(allErrs, field.Required(dataPath.Key(api.DockerConfigJsonKey), ""))
break
}
// make sure that the content is well-formed json.
if err := json.Unmarshal(dockerConfigJsonBytes, &map[string]interface{}{}); err != nil {
allErrs = append(allErrs, field.Invalid(dataPath.Key(api.DockerConfigJsonKey), "<secret contents redacted>", err.Error()))
}
default:
// no-op