Kubectl user exec should accept zero-length environment values #652 (#78875)

* Kubectl user exec should accept zero-length environment values #652

* Changing TestValidateAuthInfoExecInvalidEnv to allow for empty strings as Exec values

Kubernetes-commit: f30af9dd6da46f0f01e38b477d455907da9f1b6c
This commit is contained in:
Peter Swica 2019-07-25 19:01:41 -04:00 committed by Kubernetes Publisher
parent a9c895e7f2
commit 579ad46bdc
2 changed files with 2 additions and 7 deletions

View File

@ -250,8 +250,6 @@ func validateAuthInfo(authInfoName string, authInfo clientcmdapi.AuthInfo) []err
for _, v := range authInfo.Exec.Env { for _, v := range authInfo.Exec.Env {
if len(v.Name) == 0 { if len(v.Name) == 0 {
validationErrors = append(validationErrors, fmt.Errorf("env variable name must be specified for %v to use exec authentication plugin", authInfoName)) validationErrors = append(validationErrors, fmt.Errorf("env variable name must be specified for %v to use exec authentication plugin", authInfoName))
} else if len(v.Value) == 0 {
validationErrors = append(validationErrors, fmt.Errorf("env variable %s value must be specified for %v to use exec authentication plugin", v.Name, authInfoName))
} }
} }
} }

View File

@ -443,22 +443,19 @@ func TestValidateAuthInfoExecWithAuthProvider(t *testing.T) {
test.testConfig(t) test.testConfig(t)
} }
func TestValidateAuthInfoExecInvalidEnv(t *testing.T) { func TestValidateAuthInfoExecNoEnv(t *testing.T) {
config := clientcmdapi.NewConfig() config := clientcmdapi.NewConfig()
config.AuthInfos["user"] = &clientcmdapi.AuthInfo{ config.AuthInfos["user"] = &clientcmdapi.AuthInfo{
Exec: &clientcmdapi.ExecConfig{ Exec: &clientcmdapi.ExecConfig{
Command: "/bin/example", Command: "/bin/example",
APIVersion: "clientauthentication.k8s.io/v1alpha1", APIVersion: "clientauthentication.k8s.io/v1alpha1",
Env: []clientcmdapi.ExecEnvVar{ Env: []clientcmdapi.ExecEnvVar{
{Name: "foo"}, // No value {Name: "foo", Value: ""},
}, },
}, },
} }
test := configValidationTest{ test := configValidationTest{
config: config, config: config,
expectedErrorSubstring: []string{
"env variable foo value must be specified for user to use exec authentication plugin",
},
} }
test.testAuthInfo("user", t) test.testAuthInfo("user", t)